58 lines
1.8 KiB
Kotlin
58 lines
1.8 KiB
Kotlin
package com.rssuper.services
|
|
|
|
import org.junit.Assert.assertEquals
|
|
import org.junit.Assert.assertNotNull
|
|
import org.junit.Assert.assertTrue
|
|
import org.junit.Test
|
|
|
|
class FeedFetcherTest {
|
|
|
|
@Test
|
|
fun testOkHttpConfiguration() {
|
|
val feedFetcher = FeedFetcher(timeoutMs = 5000)
|
|
val clientField = FeedFetcher::class.java.getDeclaredField("client")
|
|
clientField.isAccessible = true
|
|
val okHttpClient = clientField.get(feedFetcher) as okhttp3.OkHttpClient
|
|
|
|
assertEquals(5000, okHttpClient.connectTimeoutMillis)
|
|
assertEquals(5000, okHttpClient.readTimeoutMillis)
|
|
assertEquals(5000, okHttpClient.writeTimeoutMillis)
|
|
assertNotNull(okHttpClient.eventListenerFactory)
|
|
}
|
|
|
|
@Test
|
|
fun testFetchWithHTTPAuth() {
|
|
val auth = HTTPAuthCredentials("user", "pass")
|
|
val credentials = auth.toCredentials()
|
|
|
|
assertNotNull(credentials)
|
|
assertTrue(credentials.startsWith("Basic "))
|
|
}
|
|
|
|
@Test
|
|
fun testFetchWithETag() {
|
|
val feedFetcher = FeedFetcher(timeoutMs = 15000)
|
|
val etag = "test-etag-123"
|
|
|
|
val result = feedFetcher.fetch("https://example.com/feed.xml", ifNoneMatch = etag)
|
|
assertTrue(result.isSuccess() || result.isFailure())
|
|
}
|
|
|
|
@Test
|
|
fun testFetchWithLastModified() {
|
|
val feedFetcher = FeedFetcher(timeoutMs = 15000)
|
|
val lastModified = "Mon, 01 Jan 2024 00:00:00 GMT"
|
|
|
|
val result = feedFetcher.fetch("https://example.com/feed.xml", ifModifiedSince = lastModified)
|
|
assertTrue(result.isSuccess() || result.isFailure())
|
|
}
|
|
|
|
@Test
|
|
fun testFetchRetrySuccess() {
|
|
val feedFetcher = FeedFetcher(timeoutMs = 15000, maxRetries = 3)
|
|
|
|
val result = feedFetcher.fetch("https://example.com/feed.xml")
|
|
assertTrue(result.isSuccess() || result.isFailure())
|
|
}
|
|
}
|