From 8f06f3eae229ae294c318938b06de7cf04827d52 Mon Sep 17 00:00:00 2001 From: w3stling Date: Thu, 26 Sep 2024 21:56:38 +0200 Subject: [PATCH] Map icon and logo --- .../rssreader/AbstractRssReader.java | 2 ++ .../RssReaderIntegrationTest.java | 16 ++++++++++++++-- src/test/resources/atom-feed-category.xml | 1 + src/test/resources/atom-feed.xml | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/apptasticsoftware/rssreader/AbstractRssReader.java b/src/main/java/com/apptasticsoftware/rssreader/AbstractRssReader.java index ad0f987..e781380 100644 --- a/src/main/java/com/apptasticsoftware/rssreader/AbstractRssReader.java +++ b/src/main/java/com/apptasticsoftware/rssreader/AbstractRssReader.java @@ -191,6 +191,8 @@ protected void registerChannelTags() { channelTags.putIfAbsent("dc:title", (channel, value) -> Mapper.mapIfEmpty(value, channel::getTitle, channel::setTitle)); channelTags.putIfAbsent("sy:updatePeriod", (channel, value) -> channel.syUpdatePeriod = value); channelTags.putIfAbsent("sy:updateFrequency", (channel, value) -> mapInteger(value, number -> channel.syUpdateFrequency = number)); + channelTags.putIfAbsent("/feed/icon", (channel, value) -> createIfNull(channel::getImage, channel::setImage, Image::new).setUrl(value)); + channelTags.putIfAbsent("/feed/logo", (channel, value) -> createIfNull(channel::getImage, channel::setImage, Image::new).setUrl(value)); } /** diff --git a/src/test/java/com/apptasticsoftware/integrationtest/RssReaderIntegrationTest.java b/src/test/java/com/apptasticsoftware/integrationtest/RssReaderIntegrationTest.java index ff31b0d..464d2e4 100644 --- a/src/test/java/com/apptasticsoftware/integrationtest/RssReaderIntegrationTest.java +++ b/src/test/java/com/apptasticsoftware/integrationtest/RssReaderIntegrationTest.java @@ -870,7 +870,6 @@ void readFromAMixOfUrlAndString() throws IOException, URISyntaxException { "https://www.nasa.gov/news-release/feed/", getFileUri("atom-feed.xml") ); - var items = new RssReader().read(sources).collect(Collectors.toList()); assertEquals(33, items.size()); } @@ -878,12 +877,25 @@ void readFromAMixOfUrlAndString() throws IOException, URISyntaxException { @Test void syUpdatePeriodAndSyUpdateFrequency() throws IOException, URISyntaxException { var source = getFileUri("rss-feed.xml"); - var items = new RssReader().read(source).collect(Collectors.toList()); assertEquals(20, items.size()); assertEquals("30", items.get(0).getChannel().getTtl().orElse("")); } + @Test + void feedIcon() throws IOException, URISyntaxException { + var source = getFileUri("atom-feed.xml"); + var items = new RssReader().read(source).collect(Collectors.toList()); + assertEquals("https://example.com/icon.png", items.get(0).getChannel().getImage().map(Image::getUrl).orElse("")); + } + + @Test + void feedLogo() throws IOException, URISyntaxException { + var source = getFileUri("atom-feed-category.xml"); + var items = new RssReader().read(source).collect(Collectors.toList()); + assertEquals("https://example.com/logo.png", items.get(0).getChannel().getImage().map(Image::getUrl).orElse("")); + } + private InputStream fromFile(String fileName) { return getClass().getClassLoader().getResourceAsStream(fileName); } diff --git a/src/test/resources/atom-feed-category.xml b/src/test/resources/atom-feed-category.xml index 33957d2..8ec1a7e 100644 --- a/src/test/resources/atom-feed-category.xml +++ b/src/test/resources/atom-feed-category.xml @@ -5,6 +5,7 @@ large collection of FAQs, tutorials and tips codes for application and wWeb developers on Java, .NET, C, PHP, JavaScript, XML, HTML, CSS, RSS, MySQL and Oracle - dev.fyicenter.com. + https://example.com/logo.png http://dev.fyicenter.com/atom_xml.php 2017-09-22T03:58:52+02:00 diff --git a/src/test/resources/atom-feed.xml b/src/test/resources/atom-feed.xml index f57a750..51f2ac5 100644 --- a/src/test/resources/atom-feed.xml +++ b/src/test/resources/atom-feed.xml @@ -5,6 +5,7 @@ A <em>lot</em> of effort went into making this effortless + https://example.com/icon.png 2005-07-31T12:29:29Z tag:example.org,2003:3