package com.rssuper.services import org.junit.Assert.assertTrue import org.junit.Test class FeedFetcherIntegrationTest { @Test fun testFetchRealFeed() { val feedFetcher = FeedFetcher(timeoutMs = 15000) val result = feedFetcher.fetch("https://example.com/feed.xml") assertTrue(result.isSuccess() || result.isFailure()) } @Test fun testFetchAndParseRealFeed() { val feedFetcher = FeedFetcher(timeoutMs = 15000) val result = feedFetcher.fetchAndParse("https://example.com/feed.xml") assertTrue(result.isSuccess() || result.isFailure()) } @Test fun testFetchWithHTTPAuthCredentials() { val feedFetcher = FeedFetcher(timeoutMs = 15000) val auth = HTTPAuthCredentials("testuser", "testpass") val credentials = auth.toCredentials() assertTrue(credentials.startsWith("Basic ")) } @Test fun testFetchWithCacheControl() { val feedFetcher = FeedFetcher(timeoutMs = 15000) val result = feedFetcher.fetch("https://example.com/feed.xml") assertTrue(result.isSuccess() || result.isFailure()) } @Test fun testFetchPerformance() { val feedFetcher = FeedFetcher(timeoutMs = 15000) val startTime = System.currentTimeMillis() val result = feedFetcher.fetch("https://example.com/feed.xml") val duration = System.currentTimeMillis() - startTime assertTrue(duration < 20000 || result.isFailure()) } @Test fun testFetchWithIfNoneMatch() { val feedFetcher = FeedFetcher(timeoutMs = 15000) val etag = "test-etag-value" val result = feedFetcher.fetch("https://example.com/feed.xml", ifNoneMatch = etag) assertTrue(result.isSuccess() || result.isFailure()) } @Test fun testFetchWithIfModifiedSince() { 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 testFetchMultipleFeeds() { val feedFetcher = FeedFetcher(timeoutMs = 15000) val urls = listOf( "https://example.com/feed1.xml", "https://example.com/feed2.xml" ) for (url in urls) { val result = feedFetcher.fetch(url) assertTrue(result.isSuccess() || result.isFailure()) } } @Test fun testFetchWithDifferentTimeouts() { val shortTimeoutFetcher = FeedFetcher(timeoutMs = 1000) val longTimeoutFetcher = FeedFetcher(timeoutMs = 30000) val shortClientField = FeedFetcher::class.java.getDeclaredField("client") shortClientField.isAccessible = true val shortClient = shortClientField.get(shortTimeoutFetcher) as okhttp3.OkHttpClient val longClientField = FeedFetcher::class.java.getDeclaredField("client") longClientField.isAccessible = true val longClient = longClientField.get(longTimeoutFetcher) as okhttp3.OkHttpClient assertTrue(shortClient.connectTimeoutMillis < longClient.connectTimeoutMillis) } }