forked from Archives/Athou_commafeed
add even more integration tests
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package com.commafeed.backend.favicon;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.commafeed.backend.HttpGetter;
|
||||
import com.commafeed.backend.HttpGetter.HttpResult;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class FacebookFaviconFetcherTest {
|
||||
|
||||
@Mock
|
||||
private HttpGetter httpGetter;
|
||||
|
||||
private FacebookFaviconFetcher faviconFetcher;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
faviconFetcher = new FacebookFaviconFetcher(httpGetter);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithValidFacebookUrl() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://www.facebook.com/something?id=validUserId");
|
||||
|
||||
byte[] iconBytes = new byte[1000];
|
||||
String contentType = "image/png";
|
||||
|
||||
HttpResult httpResult = new HttpResult(iconBytes, contentType, null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://graph.facebook.com/validUserId/picture?type=square&height=16")).thenReturn(httpResult);
|
||||
|
||||
Favicon result = faviconFetcher.fetch(feed);
|
||||
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(iconBytes, result.getIcon());
|
||||
Assertions.assertTrue(result.getMediaType().isCompatible(MediaType.valueOf(contentType)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithNonFacebookUrl() {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://example.com");
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
Mockito.verifyNoInteractions(httpGetter);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithFacebookUrlButNoUserId() {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://www.facebook.com/something");
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
Mockito.verifyNoInteractions(httpGetter);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithHttpGetterException() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://www.facebook.com/something?id=validUserId");
|
||||
|
||||
Mockito.when(httpGetter.get("https://graph.facebook.com/validUserId/picture?type=square&height=16"))
|
||||
.thenThrow(new RuntimeException("Network error"));
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithInvalidIconResponse() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://www.facebook.com/something?id=validUserId");
|
||||
|
||||
// Create a byte array that's too small
|
||||
byte[] iconBytes = new byte[50];
|
||||
String contentType = "image/png";
|
||||
|
||||
HttpResult httpResult = new HttpResult(iconBytes, contentType, null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://graph.facebook.com/validUserId/picture?type=square&height=16")).thenReturn(httpResult);
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithBlacklistedContentType() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://www.facebook.com/something?id=validUserId");
|
||||
|
||||
byte[] iconBytes = new byte[1000];
|
||||
String contentType = "application/xml"; // Blacklisted content type
|
||||
|
||||
HttpResult httpResult = new HttpResult(iconBytes, contentType, null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://graph.facebook.com/validUserId/picture?type=square&height=16")).thenReturn(httpResult);
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
package com.commafeed.backend.favicon;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.commafeed.CommaFeedConfiguration;
|
||||
import com.commafeed.backend.HttpGetter;
|
||||
import com.commafeed.backend.HttpGetter.HttpResult;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.fasterxml.jackson.core.JsonPointer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class YoutubeFaviconFetcherTest {
|
||||
|
||||
@Mock
|
||||
private HttpGetter httpGetter;
|
||||
|
||||
@Mock
|
||||
private CommaFeedConfiguration config;
|
||||
|
||||
@Mock
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private YoutubeFaviconFetcher faviconFetcher;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
faviconFetcher = new YoutubeFaviconFetcher(httpGetter, config, objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithNonYoutubeUrl() {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://example.com/feed");
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
Mockito.verifyNoInteractions(httpGetter, objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithNoGoogleAuthKey() {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://youtube.com/feeds/videos.xml?user=someUser");
|
||||
|
||||
Mockito.when(config.googleAuthKey()).thenReturn(Optional.empty());
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
Mockito.verify(config).googleAuthKey();
|
||||
Mockito.verifyNoInteractions(httpGetter, objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchForUser() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://youtube.com/feeds/videos.xml?user=testUser");
|
||||
|
||||
Mockito.when(config.googleAuthKey()).thenReturn(Optional.of("test-api-key"));
|
||||
|
||||
byte[] apiResponse = """
|
||||
{"items":[{"snippet":{"thumbnails":{"default":{"url":"https://example.com/icon.png"}}}}]}""".getBytes();
|
||||
HttpResult apiHttpResult = new HttpResult(apiResponse, "application/json", null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://www.googleapis.com/youtube/v3/channels?part=snippet&key=test-api-key&forUsername=testUser"))
|
||||
.thenReturn(apiHttpResult);
|
||||
|
||||
JsonNode jsonNode = new ObjectMapper().readTree(apiResponse);
|
||||
Mockito.when(objectMapper.readTree(apiResponse)).thenReturn(jsonNode);
|
||||
|
||||
byte[] iconBytes = new byte[1000];
|
||||
String contentType = "image/png";
|
||||
HttpResult iconHttpResult = new HttpResult(iconBytes, contentType, null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://example.com/icon.png")).thenReturn(iconHttpResult);
|
||||
|
||||
Favicon result = faviconFetcher.fetch(feed);
|
||||
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(iconBytes, result.getIcon());
|
||||
Assertions.assertTrue(result.getMediaType().isCompatible(MediaType.valueOf(contentType)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchForChannel() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://youtube.com/feeds/videos.xml?channel_id=testChannelId");
|
||||
|
||||
Mockito.when(config.googleAuthKey()).thenReturn(Optional.of("test-api-key"));
|
||||
|
||||
byte[] apiResponse = """
|
||||
{"items":[{"snippet":{"thumbnails":{"default":{"url":"https://example.com/icon.png"}}}}]}""".getBytes();
|
||||
HttpResult apiHttpResult = new HttpResult(apiResponse, "application/json", null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://www.googleapis.com/youtube/v3/channels?part=snippet&key=test-api-key&id=testChannelId"))
|
||||
.thenReturn(apiHttpResult);
|
||||
|
||||
JsonNode jsonNode = new ObjectMapper().readTree(apiResponse);
|
||||
Mockito.when(objectMapper.readTree(apiResponse)).thenReturn(jsonNode);
|
||||
|
||||
byte[] iconBytes = new byte[1000];
|
||||
String contentType = "image/png";
|
||||
HttpResult iconHttpResult = new HttpResult(iconBytes, contentType, null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://example.com/icon.png")).thenReturn(iconHttpResult);
|
||||
|
||||
Favicon result = faviconFetcher.fetch(feed);
|
||||
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(iconBytes, result.getIcon());
|
||||
Assertions.assertTrue(result.getMediaType().isCompatible(MediaType.valueOf(contentType)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchForPlaylist() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://youtube.com/feeds/videos.xml?playlist_id=testPlaylistId");
|
||||
|
||||
Mockito.when(config.googleAuthKey()).thenReturn(Optional.of("test-api-key"));
|
||||
|
||||
byte[] playlistResponse = """
|
||||
{"items":[{"snippet":{"channelId":"testChannelId"}}]}""".getBytes();
|
||||
HttpResult playlistHttpResult = new HttpResult(playlistResponse, "application/json", null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://www.googleapis.com/youtube/v3/playlists?part=snippet&key=test-api-key&id=testPlaylistId"))
|
||||
.thenReturn(playlistHttpResult);
|
||||
|
||||
JsonNode playlistJsonNode = new ObjectMapper().readTree(playlistResponse);
|
||||
Mockito.when(objectMapper.readTree(playlistResponse)).thenReturn(playlistJsonNode);
|
||||
|
||||
byte[] channelResponse = """
|
||||
{"items":[{"snippet":{"thumbnails":{"default":{"url":"https://example.com/icon.png"}}}}]}""".getBytes();
|
||||
HttpResult channelHttpResult = new HttpResult(channelResponse, "application/json", null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://www.googleapis.com/youtube/v3/channels?part=snippet&key=test-api-key&id=testChannelId"))
|
||||
.thenReturn(channelHttpResult);
|
||||
|
||||
JsonNode channelJsonNode = new ObjectMapper().readTree(channelResponse);
|
||||
Mockito.when(objectMapper.readTree(channelResponse)).thenReturn(channelJsonNode);
|
||||
|
||||
byte[] iconBytes = new byte[1000];
|
||||
String contentType = "image/png";
|
||||
HttpResult iconHttpResult = new HttpResult(iconBytes, contentType, null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://example.com/icon.png")).thenReturn(iconHttpResult);
|
||||
|
||||
Favicon result = faviconFetcher.fetch(feed);
|
||||
|
||||
Assertions.assertNotNull(result);
|
||||
Assertions.assertEquals(iconBytes, result.getIcon());
|
||||
Assertions.assertTrue(result.getMediaType().isCompatible(MediaType.valueOf(contentType)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithHttpGetterException() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://youtube.com/feeds/videos.xml?user=testUser");
|
||||
|
||||
Mockito.when(config.googleAuthKey()).thenReturn(Optional.of("test-api-key"));
|
||||
|
||||
Mockito.when(httpGetter.get("https://www.googleapis.com/youtube/v3/channels?part=snippet&key=test-api-key&forUsername=testUser"))
|
||||
.thenThrow(new IOException("Network error"));
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithInvalidIconResponse() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://youtube.com/feeds/videos.xml?user=testUser");
|
||||
|
||||
Mockito.when(config.googleAuthKey()).thenReturn(Optional.of("test-api-key"));
|
||||
|
||||
byte[] apiResponse = """
|
||||
{"items":[{"snippet":{"thumbnails":{"default":{"url":"https://example.com/icon.png"}}}}]}""".getBytes();
|
||||
HttpResult apiHttpResult = new HttpResult(apiResponse, "application/json", null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://www.googleapis.com/youtube/v3/channels?part=snippet&key=test-api-key&forUsername=testUser"))
|
||||
.thenReturn(apiHttpResult);
|
||||
|
||||
JsonNode jsonNode = new ObjectMapper().readTree(apiResponse);
|
||||
Mockito.when(objectMapper.readTree(apiResponse)).thenReturn(jsonNode);
|
||||
|
||||
// Create a byte array that's too small
|
||||
byte[] iconBytes = new byte[50];
|
||||
String contentType = "image/png";
|
||||
HttpResult iconHttpResult = new HttpResult(iconBytes, contentType, null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://example.com/icon.png")).thenReturn(iconHttpResult);
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWithEmptyApiResponse() throws Exception {
|
||||
Feed feed = new Feed();
|
||||
feed.setUrl("https://youtube.com/feeds/videos.xml?user=testUser");
|
||||
|
||||
Mockito.when(config.googleAuthKey()).thenReturn(Optional.of("test-api-key"));
|
||||
|
||||
byte[] apiResponse = "{}".getBytes();
|
||||
HttpResult apiHttpResult = new HttpResult(apiResponse, "application/json", null, null, null, Duration.ZERO);
|
||||
Mockito.when(httpGetter.get("https://www.googleapis.com/youtube/v3/channels?part=snippet&key=test-api-key&forUsername=testUser"))
|
||||
.thenReturn(apiHttpResult);
|
||||
|
||||
JsonNode jsonNode = Mockito.mock(JsonNode.class);
|
||||
Mockito.when(objectMapper.readTree(apiResponse)).thenReturn(jsonNode);
|
||||
Mockito.when(jsonNode.at(Mockito.any(JsonPointer.class))).thenReturn(jsonNode);
|
||||
Mockito.when(jsonNode.isMissingNode()).thenReturn(true);
|
||||
|
||||
Assertions.assertNull(faviconFetcher.fetch(feed));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.commafeed.backend.model;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class FeedEntryContentTest {
|
||||
|
||||
@Nested
|
||||
class EquivalentTo {
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenComparedWithNull() {
|
||||
Assertions.assertFalse(new FeedEntryContent().equivalentTo(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnTrueWhenComparedWithIdenticalContent() {
|
||||
FeedEntryContent content1 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
Assertions.assertTrue(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenTitleDiffers() {
|
||||
FeedEntryContent content1 = createContent("title1", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title2", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenContentDiffers() {
|
||||
FeedEntryContent content1 = createContent("title", "content1", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content2", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenAuthorDiffers() {
|
||||
FeedEntryContent content1 = createContent("title", "content", "author1", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content", "author2", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenCategoriesDiffer() {
|
||||
FeedEntryContent content1 = createContent("title", "content", "author", "categories1", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content", "author", "categories2", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenEnclosureUrlDiffers() {
|
||||
FeedEntryContent content1 = createContent("title", "content", "author", "categories", "enclosureUrl1", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content", "author", "categories", "enclosureUrl2", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenEnclosureTypeDiffers() {
|
||||
FeedEntryContent content1 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType1",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType2",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenMediaDescriptionDiffers() {
|
||||
FeedEntryContent content1 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription1", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription2", "mediaThumbnailUrl", 10, 20);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenMediaThumbnailUrlDiffers() {
|
||||
FeedEntryContent content1 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl1", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl2", 10, 20);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenMediaThumbnailWidthDiffers() {
|
||||
FeedEntryContent content1 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 15, 20);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseWhenMediaThumbnailHeightDiffers() {
|
||||
FeedEntryContent content1 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 20);
|
||||
FeedEntryContent content2 = createContent("title", "content", "author", "categories", "enclosureUrl", "enclosureType",
|
||||
"mediaDescription", "mediaThumbnailUrl", 10, 25);
|
||||
Assertions.assertFalse(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnTrueWhenNullFieldsAreEqual() {
|
||||
FeedEntryContent content1 = new FeedEntryContent();
|
||||
FeedEntryContent content2 = new FeedEntryContent();
|
||||
Assertions.assertTrue(content1.equivalentTo(content2));
|
||||
}
|
||||
|
||||
private FeedEntryContent createContent(String title, String content, String author, String categories, String enclosureUrl,
|
||||
String enclosureType, String mediaDescription, String mediaThumbnailUrl, Integer mediaThumbnailWidth,
|
||||
Integer mediaThumbnailHeight) {
|
||||
FeedEntryContent feedEntryContent = new FeedEntryContent();
|
||||
feedEntryContent.setTitle(title);
|
||||
feedEntryContent.setContent(content);
|
||||
feedEntryContent.setAuthor(author);
|
||||
feedEntryContent.setCategories(categories);
|
||||
feedEntryContent.setEnclosureUrl(enclosureUrl);
|
||||
feedEntryContent.setEnclosureType(enclosureType);
|
||||
feedEntryContent.setMediaDescription(mediaDescription);
|
||||
feedEntryContent.setMediaThumbnailUrl(mediaThumbnailUrl);
|
||||
feedEntryContent.setMediaThumbnailWidth(mediaThumbnailWidth);
|
||||
feedEntryContent.setMediaThumbnailHeight(mediaThumbnailHeight);
|
||||
return feedEntryContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.commafeed.backend.urlprovider;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class InPageReferenceFeedURLProviderTest {
|
||||
|
||||
private final InPageReferenceFeedURLProvider provider = new InPageReferenceFeedURLProvider();
|
||||
|
||||
@Test
|
||||
void extractsAtomFeedURL() {
|
||||
String url = "http://example.com";
|
||||
String html = """
|
||||
<html>
|
||||
<head>
|
||||
<link type="application/atom+xml" href="/feed.atom">
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>""";
|
||||
|
||||
String result = provider.get(url, html);
|
||||
|
||||
Assertions.assertEquals("http://example.com/feed.atom", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void extractsRSSFeedURL() {
|
||||
String url = "http://example.com";
|
||||
String html = """
|
||||
<html>
|
||||
<head>
|
||||
<link type="application/rss+xml" href="/feed.rss">
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>""";
|
||||
|
||||
String result = provider.get(url, html);
|
||||
|
||||
Assertions.assertEquals("http://example.com/feed.rss", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void prefersAtomOverRSS() {
|
||||
String url = "http://example.com";
|
||||
String html = """
|
||||
<html>
|
||||
<head>
|
||||
<link type="application/atom+xml" href="/feed.atom">
|
||||
<link type="application/rss+xml" href="/feed.rss">
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>""";
|
||||
|
||||
String result = provider.get(url, html);
|
||||
|
||||
Assertions.assertEquals("http://example.com/feed.atom", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnsNullForNonHtmlContent() {
|
||||
String url = "http://example.com";
|
||||
String content = """
|
||||
<?xml version="1.0"?>
|
||||
<feed></feed>
|
||||
</xml>""";
|
||||
|
||||
String result = provider.get(url, content);
|
||||
|
||||
Assertions.assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnsNullForHtmlWithoutFeedLinks() {
|
||||
String url = "http://example.com";
|
||||
String html = """
|
||||
<html>
|
||||
<head>
|
||||
<link type="text/css" href="/style.css">
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>""";
|
||||
|
||||
String result = provider.get(url, html);
|
||||
|
||||
Assertions.assertNull(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.commafeed.frontend.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.rometools.rome.feed.synd.SyndEntry;
|
||||
|
||||
class EntryTest {
|
||||
|
||||
@Test
|
||||
void asRss() {
|
||||
Entry entry = new Entry();
|
||||
entry.setId("1");
|
||||
entry.setGuid("guid-1");
|
||||
entry.setTitle("Test Entry");
|
||||
entry.setContent("This is a test entry content.");
|
||||
entry.setCategories("test,example");
|
||||
entry.setRtl(false);
|
||||
entry.setAuthor("Author Name");
|
||||
entry.setEnclosureUrl("http://example.com/enclosure.mp3");
|
||||
entry.setEnclosureType("audio/mpeg");
|
||||
entry.setDate(Instant.ofEpochSecond(1));
|
||||
entry.setUrl("http://example.com/test-entry");
|
||||
|
||||
SyndEntry syndEntry = entry.asRss();
|
||||
Assertions.assertEquals("guid-1", syndEntry.getUri());
|
||||
Assertions.assertEquals("Test Entry", syndEntry.getTitle());
|
||||
Assertions.assertEquals("Author Name", syndEntry.getAuthor());
|
||||
Assertions.assertEquals(1, syndEntry.getContents().size());
|
||||
Assertions.assertEquals("This is a test entry content.", syndEntry.getContents().get(0).getValue());
|
||||
Assertions.assertEquals(1, syndEntry.getEnclosures().size());
|
||||
Assertions.assertEquals("http://example.com/enclosure.mp3", syndEntry.getEnclosures().get(0).getUrl());
|
||||
Assertions.assertEquals("audio/mpeg", syndEntry.getEnclosures().get(0).getType());
|
||||
Assertions.assertEquals("http://example.com/test-entry", syndEntry.getLink());
|
||||
Assertions.assertEquals(Date.from(Instant.ofEpochSecond(1)), syndEntry.getPublishedDate());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import java.util.Objects;
|
||||
|
||||
import jakarta.ws.rs.client.Client;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
@@ -29,6 +28,7 @@ import com.commafeed.frontend.model.request.AddCategoryRequest;
|
||||
import com.commafeed.frontend.model.request.SubscribeRequest;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.http.Header;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -95,7 +95,7 @@ public abstract class BaseIT {
|
||||
addCategoryRequest.setName(name);
|
||||
return RestAssured.given()
|
||||
.body(addCategoryRequest)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(ContentType.JSON)
|
||||
.post("rest/category/add")
|
||||
.then()
|
||||
.extract()
|
||||
@@ -117,7 +117,7 @@ public abstract class BaseIT {
|
||||
subscribeRequest.setCategoryId(categoryId);
|
||||
return RestAssured.given()
|
||||
.body(subscribeRequest)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(ContentType.JSON)
|
||||
.post("rest/feed/subscribe")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
@@ -162,6 +162,24 @@ public abstract class BaseIT {
|
||||
.as(Entries.class);
|
||||
}
|
||||
|
||||
protected Entries getCategoryEntries(String categoryId, String keywords) {
|
||||
return RestAssured.given()
|
||||
.get("rest/category/entries?id={id}&readType=all&keywords={keywords}", categoryId, keywords)
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
.extract()
|
||||
.as(Entries.class);
|
||||
}
|
||||
|
||||
protected Entries getTaggedEntries(String tag) {
|
||||
return RestAssured.given()
|
||||
.get("rest/category/entries?id=all&readType=all&tag={tag}", tag)
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
.extract()
|
||||
.as(Entries.class);
|
||||
}
|
||||
|
||||
protected int forceRefreshAllFeeds() {
|
||||
return RestAssured.given().get("rest/feed/refreshAll").then().extract().statusCode();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -20,6 +19,7 @@ import com.commafeed.frontend.model.request.SubscribeRequest;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
|
||||
@QuarkusTest
|
||||
class SecurityIT extends BaseIT {
|
||||
@@ -79,7 +79,7 @@ class SecurityIT extends BaseIT {
|
||||
.preemptive()
|
||||
.basic("admin", "admin")
|
||||
.body(req)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(ContentType.JSON)
|
||||
.post("rest/user/profile")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK);
|
||||
@@ -105,7 +105,7 @@ class SecurityIT extends BaseIT {
|
||||
.preemptive()
|
||||
.basic("admin", "admin")
|
||||
.body(subscribeRequest)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(ContentType.JSON)
|
||||
.post("rest/feed/subscribe")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
@@ -130,7 +130,7 @@ class SecurityIT extends BaseIT {
|
||||
markRequest.setRead(true);
|
||||
RestAssured.given()
|
||||
.body(markRequest)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(ContentType.JSON)
|
||||
.queryParam("apiKey", apiKey)
|
||||
.post("rest/entry/mark")
|
||||
.then()
|
||||
|
||||
@@ -19,7 +19,6 @@ import jakarta.websocket.Endpoint;
|
||||
import jakarta.websocket.EndpointConfig;
|
||||
import jakarta.websocket.Session;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.awaitility.Awaitility;
|
||||
@@ -32,6 +31,7 @@ import com.commafeed.frontend.model.request.FeedModificationRequest;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@QuarkusTest
|
||||
@@ -102,7 +102,7 @@ class WebSocketIT extends BaseIT {
|
||||
req.setId(subscriptionId);
|
||||
req.setName("feed-name");
|
||||
req.setFilter("!title.contains('item 4')");
|
||||
RestAssured.given().body(req).contentType(MediaType.APPLICATION_JSON).post("rest/feed/modify").then().statusCode(HttpStatus.SC_OK);
|
||||
RestAssured.given().body(req).contentType(ContentType.JSON).post("rest/feed/modify").then().statusCode(HttpStatus.SC_OK);
|
||||
|
||||
AtomicBoolean connected = new AtomicBoolean();
|
||||
AtomicReference<String> messageRef = new AtomicReference<>();
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.commafeed.integration.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -18,6 +16,7 @@ import com.commafeed.integration.BaseIT;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
|
||||
@QuarkusTest
|
||||
class AdminIT extends BaseIT {
|
||||
@@ -38,42 +37,47 @@ class AdminIT extends BaseIT {
|
||||
void saveModifyAndDeleteNewUser() {
|
||||
List<UserModel> existingUsers = getAllUsers();
|
||||
|
||||
createUser();
|
||||
long userId = createUser();
|
||||
Assertions.assertEquals(existingUsers.size() + 1, getAllUsers().size());
|
||||
|
||||
modifyUser();
|
||||
UserModel user = getUser(userId);
|
||||
Assertions.assertEquals("test", user.getName());
|
||||
|
||||
modifyUser(user);
|
||||
Assertions.assertEquals(existingUsers.size() + 1, getAllUsers().size());
|
||||
|
||||
deleteUser();
|
||||
Assertions.assertEquals(existingUsers.size(), getAllUsers().size());
|
||||
}
|
||||
|
||||
private void createUser() {
|
||||
private long createUser() {
|
||||
User user = new User();
|
||||
user.setName("test");
|
||||
user.setPassword("test".getBytes());
|
||||
user.setEmail("test@test.com");
|
||||
RestAssured.given()
|
||||
String response = RestAssured.given()
|
||||
.body(user)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(ContentType.JSON)
|
||||
.post("rest/admin/user/save")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK);
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
.extract()
|
||||
.asString();
|
||||
return Long.parseLong(response);
|
||||
}
|
||||
|
||||
private void modifyUser() {
|
||||
List<UserModel> existingUsers = getAllUsers();
|
||||
UserModel user = existingUsers.stream()
|
||||
.filter(u -> u.getName().equals("test"))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NullPointerException("User not found"));
|
||||
user.setEmail("new-email@provider.com");
|
||||
RestAssured.given()
|
||||
.body(user)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.post("rest/admin/user/save")
|
||||
private UserModel getUser(long userId) {
|
||||
return RestAssured.given()
|
||||
.get("rest/admin/user/get/{id}", userId)
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK);
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
.extract()
|
||||
.as(UserModel.class);
|
||||
}
|
||||
|
||||
private void modifyUser(UserModel user) {
|
||||
user.setEmail("new-email@provider.com");
|
||||
RestAssured.given().body(user).contentType(ContentType.JSON).post("rest/admin/user/save").then().statusCode(HttpStatus.SC_OK);
|
||||
}
|
||||
|
||||
private void deleteUser() {
|
||||
@@ -85,12 +89,7 @@ class AdminIT extends BaseIT {
|
||||
|
||||
IDRequest req = new IDRequest();
|
||||
req.setId(user.getId());
|
||||
RestAssured.given()
|
||||
.body(req)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.post("rest/admin/user/delete")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK);
|
||||
RestAssured.given().body(req).contentType(ContentType.JSON).post("rest/admin/user/delete").then().statusCode(HttpStatus.SC_OK);
|
||||
}
|
||||
|
||||
private List<UserModel> getAllUsers() {
|
||||
|
||||
@@ -1,25 +1,36 @@
|
||||
package com.commafeed.integration.rest;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.commafeed.frontend.model.Category;
|
||||
import com.commafeed.frontend.model.Entries;
|
||||
import com.commafeed.frontend.model.Entry;
|
||||
import com.commafeed.frontend.model.UnreadCount;
|
||||
import com.commafeed.frontend.model.request.CategoryModificationRequest;
|
||||
import com.commafeed.frontend.model.request.CollapseRequest;
|
||||
import com.commafeed.frontend.model.request.IDRequest;
|
||||
import com.commafeed.frontend.model.request.MarkRequest;
|
||||
import com.commafeed.frontend.model.request.StarRequest;
|
||||
import com.commafeed.frontend.model.request.TagRequest;
|
||||
import com.commafeed.frontend.resource.CategoryREST;
|
||||
import com.commafeed.integration.BaseIT;
|
||||
import com.rometools.rome.feed.synd.SyndFeed;
|
||||
import com.rometools.rome.io.FeedException;
|
||||
import com.rometools.rome.io.SyndFeedInput;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.common.mapper.TypeRef;
|
||||
import io.restassured.http.ContentType;
|
||||
|
||||
@QuarkusTest
|
||||
class CategoryIT extends BaseIT {
|
||||
@@ -37,18 +48,30 @@ class CategoryIT extends BaseIT {
|
||||
void modifyCategory() {
|
||||
String category1Id = createCategory("test-category-1");
|
||||
String category2Id = createCategory("test-category-2");
|
||||
String category3Id = createCategory("test-category-3");
|
||||
|
||||
CategoryModificationRequest request = new CategoryModificationRequest();
|
||||
request.setId(Long.valueOf(category2Id));
|
||||
request.setName("modified-category");
|
||||
request.setName("modified-category-2");
|
||||
request.setParentId(category1Id);
|
||||
RestAssured.given().body(request).contentType(MediaType.APPLICATION_JSON).post("rest/category/modify").then().statusCode(200);
|
||||
request.setPosition(2);
|
||||
RestAssured.given().body(request).contentType(ContentType.JSON).post("rest/category/modify").then().statusCode(200);
|
||||
|
||||
Category root = getRootCategory();
|
||||
Assertions.assertEquals(1, root.getChildren().size());
|
||||
Assertions.assertEquals(2, root.getChildren().size());
|
||||
Assertions.assertEquals("test-category-1", root.getChildren().get(0).getName());
|
||||
Assertions.assertEquals(1, root.getChildren().get(0).getChildren().size());
|
||||
Assertions.assertEquals("modified-category", root.getChildren().get(0).getChildren().get(0).getName());
|
||||
Assertions.assertEquals("modified-category-2", root.getChildren().get(0).getChildren().get(0).getName());
|
||||
|
||||
request = new CategoryModificationRequest();
|
||||
request.setId(Long.valueOf(category3Id));
|
||||
request.setPosition(0);
|
||||
RestAssured.given().body(request).contentType(ContentType.JSON).post("rest/category/modify").then().statusCode(200);
|
||||
|
||||
root = getRootCategory();
|
||||
Assertions.assertEquals(2, root.getChildren().size());
|
||||
Assertions.assertEquals("test-category-3", root.getChildren().get(0).getName());
|
||||
Assertions.assertEquals("test-category-1", root.getChildren().get(1).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,7 +85,7 @@ class CategoryIT extends BaseIT {
|
||||
CollapseRequest request = new CollapseRequest();
|
||||
request.setId(Long.valueOf(categoryId));
|
||||
request.setCollapse(true);
|
||||
RestAssured.given().body(request).contentType(MediaType.APPLICATION_JSON).post("rest/category/collapse").then().statusCode(200);
|
||||
RestAssured.given().body(request).contentType(ContentType.JSON).post("rest/category/collapse").then().statusCode(200);
|
||||
|
||||
root = getRootCategory();
|
||||
Assertions.assertEquals(1, root.getChildren().size());
|
||||
@@ -76,10 +99,57 @@ class CategoryIT extends BaseIT {
|
||||
|
||||
IDRequest request = new IDRequest();
|
||||
request.setId(Long.valueOf(categoryId));
|
||||
RestAssured.given().body(request).contentType(MediaType.APPLICATION_JSON).post("rest/category/delete").then().statusCode(200);
|
||||
RestAssured.given().body(request).contentType(ContentType.JSON).post("rest/category/delete").then().statusCode(200);
|
||||
Assertions.assertEquals(0, getRootCategory().getChildren().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unreadCount() {
|
||||
String categoryId = createCategory("test-category");
|
||||
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl(), categoryId);
|
||||
Assertions.assertEquals(2, getCategoryEntries(categoryId).getEntries().size());
|
||||
|
||||
List<UnreadCount> counts = RestAssured.given()
|
||||
.get("rest/category/unreadCount")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.as(new TypeRef<List<UnreadCount>>() {
|
||||
});
|
||||
|
||||
Assertions.assertEquals(1, counts.size());
|
||||
Assertions.assertEquals(subscriptionId, counts.get(0).getFeedId());
|
||||
Assertions.assertEquals(2, counts.get(0).getUnreadCount());
|
||||
}
|
||||
|
||||
@Nested
|
||||
class MarkEntriesAsRead {
|
||||
@Test
|
||||
void all() {
|
||||
subscribeAndWaitForEntries(getFeedUrl());
|
||||
Assertions.assertTrue(getCategoryEntries(CategoryREST.ALL).getEntries().stream().noneMatch(Entry::isRead));
|
||||
|
||||
MarkRequest request = new MarkRequest();
|
||||
request.setId(CategoryREST.ALL);
|
||||
request.setRead(true);
|
||||
RestAssured.given().body(request).contentType(ContentType.JSON).post("rest/category/mark").then().statusCode(200);
|
||||
Assertions.assertTrue(getCategoryEntries(CategoryREST.ALL).getEntries().stream().allMatch(Entry::isRead));
|
||||
}
|
||||
|
||||
@Test
|
||||
void specificCategory() {
|
||||
String categoryId = createCategory("test-category");
|
||||
subscribeAndWaitForEntries(getFeedUrl(), categoryId);
|
||||
Assertions.assertTrue(getCategoryEntries(categoryId).getEntries().stream().noneMatch(Entry::isRead));
|
||||
|
||||
MarkRequest request = new MarkRequest();
|
||||
request.setId(categoryId);
|
||||
request.setRead(true);
|
||||
RestAssured.given().body(request).contentType(ContentType.JSON).post("rest/category/mark").then().statusCode(200);
|
||||
Assertions.assertTrue(getCategoryEntries(categoryId).getEntries().stream().allMatch(Entry::isRead));
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class GetEntries {
|
||||
@Test
|
||||
@@ -89,6 +159,22 @@ class CategoryIT extends BaseIT {
|
||||
Assertions.assertEquals(2, entries.getEntries().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void allAsFeed() throws FeedException {
|
||||
subscribeAndWaitForEntries(getFeedUrl());
|
||||
String xml = RestAssured.given()
|
||||
.get("rest/category/entriesAsFeed?id=all")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
.contentType(ContentType.XML)
|
||||
.extract()
|
||||
.asString();
|
||||
|
||||
InputSource source = new InputSource(new StringReader(xml));
|
||||
SyndFeed feed = new SyndFeedInput().build(source);
|
||||
Assertions.assertEquals(2, feed.getEntries().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void starred() {
|
||||
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||
@@ -100,13 +186,36 @@ class CategoryIT extends BaseIT {
|
||||
starRequest.setId(entry.getId());
|
||||
starRequest.setFeedId(subscriptionId);
|
||||
starRequest.setStarred(true);
|
||||
RestAssured.given().body(starRequest).contentType(MediaType.APPLICATION_JSON).post("rest/entry/star");
|
||||
RestAssured.given().body(starRequest).contentType(ContentType.JSON).post("rest/entry/star");
|
||||
|
||||
Entries starredEntries = getCategoryEntries(CategoryREST.STARRED);
|
||||
Assertions.assertEquals(1, starredEntries.getEntries().size());
|
||||
Assertions.assertEquals(entry.getId(), starredEntries.getEntries().get(0).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagged() {
|
||||
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||
Assertions.assertEquals(0, getTaggedEntries("my-tag").getEntries().size());
|
||||
|
||||
Entry entry = getFeedEntries(subscriptionId).getEntries().get(0);
|
||||
|
||||
TagRequest tagRequest = new TagRequest();
|
||||
tagRequest.setEntryId(Long.valueOf(entry.getId()));
|
||||
tagRequest.setTags(List.of("my-tag"));
|
||||
RestAssured.given().body(tagRequest).contentType(ContentType.JSON).post("rest/entry/tag");
|
||||
|
||||
Entries taggedEntries = getTaggedEntries("my-tag");
|
||||
Assertions.assertEquals(1, taggedEntries.getEntries().size());
|
||||
Assertions.assertEquals(entry.getId(), taggedEntries.getEntries().get(0).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void keywords() {
|
||||
subscribeAndWaitForEntries(getFeedUrl());
|
||||
Assertions.assertEquals(1, getCategoryEntries(CategoryREST.ALL, "Item 2 description").getEntries().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void specificCategory() {
|
||||
String categoryId = createCategory("test-category");
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.commafeed.integration.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
@@ -19,6 +20,7 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.commafeed.frontend.model.Entry;
|
||||
import com.commafeed.frontend.model.FeedInfo;
|
||||
@@ -28,9 +30,13 @@ import com.commafeed.frontend.model.request.FeedModificationRequest;
|
||||
import com.commafeed.frontend.model.request.IDRequest;
|
||||
import com.commafeed.frontend.model.request.MarkRequest;
|
||||
import com.commafeed.integration.BaseIT;
|
||||
import com.rometools.rome.feed.synd.SyndFeed;
|
||||
import com.rometools.rome.io.FeedException;
|
||||
import com.rometools.rome.io.SyndFeedInput;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
|
||||
@QuarkusTest
|
||||
class FeedIT extends BaseIT {
|
||||
@@ -54,7 +60,7 @@ class FeedIT extends BaseIT {
|
||||
|
||||
FeedInfo feedInfo = RestAssured.given()
|
||||
.body(req)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(ContentType.JSON)
|
||||
.post("rest/feed/fetch")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
@@ -101,7 +107,7 @@ class FeedIT extends BaseIT {
|
||||
|
||||
return RestAssured.given()
|
||||
.body(request)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.contentType(ContentType.JSON)
|
||||
.post("rest/feed/unsubscribe")
|
||||
.then()
|
||||
.extract()
|
||||
@@ -152,12 +158,7 @@ class FeedIT extends BaseIT {
|
||||
request.setOlderThan(olderThan == null ? null : olderThan.toEpochMilli());
|
||||
request.setInsertedBefore(insertedBefore == null ? null : insertedBefore.toEpochMilli());
|
||||
|
||||
RestAssured.given()
|
||||
.body(request)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.post("rest/feed/mark")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK);
|
||||
RestAssured.given().body(request).contentType(ContentType.JSON).post("rest/feed/mark").then().statusCode(HttpStatus.SC_OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +181,25 @@ class FeedIT extends BaseIT {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class RSS {
|
||||
@Test
|
||||
void allAsFeed() throws FeedException {
|
||||
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||
String xml = RestAssured.given()
|
||||
.get("rest/feed/entriesAsFeed?id={id}", subscriptionId)
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK)
|
||||
.contentType(ContentType.XML)
|
||||
.extract()
|
||||
.asString();
|
||||
|
||||
InputSource source = new InputSource(new StringReader(xml));
|
||||
SyndFeed feed = new SyndFeedInput().build(source);
|
||||
Assertions.assertEquals(2, feed.getEntries().size());
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
class Modify {
|
||||
@Test
|
||||
@@ -192,12 +212,8 @@ class FeedIT extends BaseIT {
|
||||
req.setId(subscriptionId);
|
||||
req.setName("new name");
|
||||
req.setCategoryId(subscription.getCategoryId());
|
||||
RestAssured.given()
|
||||
.body(req)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.post("rest/feed/modify")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK);
|
||||
req.setPosition(1);
|
||||
RestAssured.given().body(req).contentType(ContentType.JSON).post("rest/feed/modify").then().statusCode(HttpStatus.SC_OK);
|
||||
|
||||
subscription = getSubscription(subscriptionId);
|
||||
Assertions.assertEquals("new name", subscription.getName());
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.commafeed.integration.rest;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -16,6 +14,7 @@ import com.commafeed.integration.BaseIT;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
|
||||
@QuarkusTest
|
||||
class FeverIT extends BaseIT {
|
||||
@@ -31,7 +30,7 @@ class FeverIT extends BaseIT {
|
||||
ProfileModificationRequest req = new ProfileModificationRequest();
|
||||
req.setCurrentPassword("admin");
|
||||
req.setNewApiKey(true);
|
||||
RestAssured.given().body(req).contentType(MediaType.APPLICATION_JSON).post("rest/user/profile").then().statusCode(HttpStatus.SC_OK);
|
||||
RestAssured.given().body(req).contentType(ContentType.JSON).post("rest/user/profile").then().statusCode(HttpStatus.SC_OK);
|
||||
|
||||
// retrieve api key
|
||||
UserModel user = RestAssured.given().get("rest/user/profile").then().statusCode(HttpStatus.SC_OK).extract().as(UserModel.class);
|
||||
@@ -70,6 +69,27 @@ class FeverIT extends BaseIT {
|
||||
Assertions.assertEquals(2, feverResponse.getUnreadItemIds().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void entries() {
|
||||
subscribeAndWaitForEntries(getFeedUrl());
|
||||
FeverResponse feverResponse = fetch("items");
|
||||
Assertions.assertEquals(2, feverResponse.getItems().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void groups() {
|
||||
createCategory("category-1");
|
||||
FeverResponse feverResponse = fetch("groups");
|
||||
Assertions.assertEquals(1, feverResponse.getGroups().size());
|
||||
Assertions.assertEquals("category-1", feverResponse.getGroups().get(0).getTitle());
|
||||
}
|
||||
|
||||
@Test
|
||||
void links() {
|
||||
FeverResponse feverResponse = fetch("links");
|
||||
Assertions.assertTrue(feverResponse.getLinks().isEmpty());
|
||||
}
|
||||
|
||||
private FeverResponse fetch(String what) {
|
||||
return fetch(what, apiKey);
|
||||
}
|
||||
|
||||
@@ -3,19 +3,22 @@ package com.commafeed.integration.rest;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.commafeed.frontend.model.Settings;
|
||||
import com.commafeed.frontend.model.request.PasswordResetRequest;
|
||||
import com.commafeed.integration.BaseIT;
|
||||
|
||||
import io.quarkus.mailer.MockMailbox;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.vertx.ext.mail.MailMessage;
|
||||
|
||||
@QuarkusTest
|
||||
@@ -40,7 +43,7 @@ class UserIT extends BaseIT {
|
||||
void resetPassword() {
|
||||
PasswordResetRequest req = new PasswordResetRequest();
|
||||
req.setEmail("admin@commafeed.com");
|
||||
RestAssured.given().body(req).contentType(MediaType.APPLICATION_JSON).post("rest/user/passwordReset").then().statusCode(200);
|
||||
RestAssured.given().body(req).contentType(ContentType.JSON).post("rest/user/passwordReset").then().statusCode(200);
|
||||
|
||||
List<MailMessage> mails = mailbox.getMailMessagesSentTo("admin@commafeed.com");
|
||||
Assertions.assertEquals(1, mails.size());
|
||||
@@ -49,5 +52,20 @@ class UserIT extends BaseIT {
|
||||
Assertions.assertEquals("CommaFeed - Password recovery", message.getSubject());
|
||||
Assertions.assertTrue(message.getHtml().startsWith("You asked for password recovery for account 'admin'"));
|
||||
Assertions.assertEquals("admin@commafeed.com", message.getTo().get(0));
|
||||
|
||||
Element a = Jsoup.parse(message.getHtml()).select("a").get(0);
|
||||
String link = a.attr("href");
|
||||
String newPasswordResponse = RestAssured.given().urlEncodingEnabled(false).get(link).then().statusCode(200).extract().asString();
|
||||
Assertions.assertTrue(newPasswordResponse.contains("Your new password is:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveSettings() {
|
||||
Settings settings = RestAssured.given().get("rest/user/settings").then().extract().as(Settings.class);
|
||||
settings.setLanguage("test");
|
||||
RestAssured.given().body(settings).contentType(ContentType.JSON).post("rest/user/settings").then().statusCode(200);
|
||||
|
||||
Settings updatedSettings = RestAssured.given().get("rest/user/settings").then().extract().as(Settings.class);
|
||||
Assertions.assertEquals("test", updatedSettings.getLanguage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.commafeed.integration.servlet;
|
||||
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.hc.core5.http.HttpStatus;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -13,6 +11,7 @@ import com.commafeed.integration.BaseIT;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
|
||||
@QuarkusTest
|
||||
class CustomCodeIT extends BaseIT {
|
||||
@@ -35,12 +34,7 @@ class CustomCodeIT extends BaseIT {
|
||||
// update settings
|
||||
settings.setCustomJs("custom-js");
|
||||
settings.setCustomCss("custom-css");
|
||||
RestAssured.given()
|
||||
.body(settings)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.post("rest/user/settings")
|
||||
.then()
|
||||
.statusCode(HttpStatus.SC_OK);
|
||||
RestAssured.given().body(settings).contentType(ContentType.JSON).post("rest/user/settings").then().statusCode(HttpStatus.SC_OK);
|
||||
|
||||
// check custom code servlets
|
||||
RestAssured.given().get("custom_js.js").then().statusCode(HttpStatus.SC_OK).body(CoreMatchers.is("custom-js"));
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.commafeed.tools;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
class CommaFeedPropertiesGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testGenerate() throws Exception {
|
||||
InputStream model = getClass().getResourceAsStream("/properties/quarkus-config-model.yaml");
|
||||
InputStream javadoc = getClass().getResourceAsStream("/properties/quarkus-config-javadoc.yaml");
|
||||
URL output = getClass().getResource("/properties/output.properties");
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
new CommaFeedPropertiesGenerator().generate(model, javadoc, baos);
|
||||
|
||||
Assertions.assertLinesMatch(Resources.readLines(output, StandardCharsets.UTF_8).stream(),
|
||||
baos.toString(StandardCharsets.UTF_8).lines());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user