From 4e732e00dc435b0a458be153d608ca9b68ea0ffd Mon Sep 17 00:00:00 2001 From: Peter Westling Date: Thu, 8 Aug 2024 16:29:53 +0200 Subject: [PATCH] Atom category support (#166) --- .../rssreader/AbstractRssReader.java | 2 + .../RssReaderIntegrationTest.java | 34 ++++++++ src/test/resources/atom-feed-category.xml | 87 +++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 src/test/resources/atom-feed-category.xml diff --git a/src/main/java/com/apptasticsoftware/rssreader/AbstractRssReader.java b/src/main/java/com/apptasticsoftware/rssreader/AbstractRssReader.java index 208ef64..ef567de 100644 --- a/src/main/java/com/apptasticsoftware/rssreader/AbstractRssReader.java +++ b/src/main/java/com/apptasticsoftware/rssreader/AbstractRssReader.java @@ -189,6 +189,7 @@ protected void registerChannelTags() { */ protected void registerChannelAttributes() { channelAttributes.computeIfAbsent("link", k -> new HashMap<>()).put("href", Channel::setLink); + channelAttributes.computeIfAbsent("category", k -> new HashMap<>()).putIfAbsent("term", Channel::addCategory); } /** @@ -227,6 +228,7 @@ protected void registerItemTags() { protected void registerItemAttributes() { itemAttributes.computeIfAbsent("link", k -> new HashMap<>()).putIfAbsent("href", Item::setLink); itemAttributes.computeIfAbsent("guid", k -> new HashMap<>()).putIfAbsent("isPermaLink", (item, value) -> item.setIsPermaLink(Boolean.parseBoolean(value)) ); + itemAttributes.computeIfAbsent("category", k -> new HashMap<>()).putIfAbsent("term", Item::addCategory); var enclosureAttributes = itemAttributes.computeIfAbsent("enclosure", k -> new HashMap<>()); enclosureAttributes.putIfAbsent("url", (item, value) -> item.getEnclosure().ifPresent(a -> a.setUrl(value))); diff --git a/src/test/java/com/apptasticsoftware/integrationtest/RssReaderIntegrationTest.java b/src/test/java/com/apptasticsoftware/integrationtest/RssReaderIntegrationTest.java index aab037c..16c2fb5 100644 --- a/src/test/java/com/apptasticsoftware/integrationtest/RssReaderIntegrationTest.java +++ b/src/test/java/com/apptasticsoftware/integrationtest/RssReaderIntegrationTest.java @@ -745,6 +745,40 @@ void readRdfFeed() { assertEquals("doi:10.1080/19322909.2024.2326687", item.getGuid().orElse("")); } + @Test + void atomFeedWithCategory() { + var list = new RssReader().read(fromFile("atom-feed-category.xml")) + .collect(Collectors.toList()); + assertEquals(3, list.size()); + + // Item 1 + assertEquals(3, list.get(0).getChannel().getCategories().size()); + assertEquals("Programming", list.get(0).getChannel().getCategories().get(0)); + assertEquals("Computer", list.get(0).getChannel().getCategories().get(1)); + assertEquals("Developer", list.get(0).getChannel().getCategories().get(2)); + assertEquals(2, list.get(0).getCategories().size()); + assertEquals("Microsoft", list.get(0).getCategories().get(0)); + assertEquals("Azure", list.get(0).getCategories().get(1)); + + // Item 2 + assertEquals(3, list.get(1).getChannel().getCategories().size()); + assertEquals("Programming", list.get(1).getChannel().getCategories().get(0)); + assertEquals("Computer", list.get(1).getChannel().getCategories().get(1)); + assertEquals("Developer", list.get(1).getChannel().getCategories().get(2)); + assertEquals(1, list.get(1).getCategories().size()); + assertEquals("Microsoft", list.get(1).getCategories().get(0)); + + // Item 3 + assertEquals(3, list.get(2).getChannel().getCategories().size()); + assertEquals("Programming", list.get(2).getChannel().getCategories().get(0)); + assertEquals("Computer", list.get(2).getChannel().getCategories().get(1)); + assertEquals("Developer", list.get(2).getChannel().getCategories().get(2)); + assertEquals(3, list.get(2).getCategories().size()); + assertEquals("Microsoft", list.get(2).getCategories().get(0)); + assertEquals("API", list.get(2).getCategories().get(1)); + assertEquals("Azure", list.get(2).getCategories().get(2)); + } + 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 new file mode 100644 index 0000000..33957d2 --- /dev/null +++ b/src/test/resources/atom-feed-category.xml @@ -0,0 +1,87 @@ + + + FYI Center for Software Developers + FYI (For Your Information) Center for Software Developers with + 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. + + http://dev.fyicenter.com/atom_xml.php + 2017-09-22T03:58:52+02:00 + + FYIcenter.com + + Copyright (c) 2017 FYIcenter.com + + + + + Use Developer Portal Internally + + + http://dev.fyicenter.com/1000702_Use_Developer_Portal_Internally.html + + 2017-09-20T13:29:08+02:00 + <img align='left' width='64' height='64' + src='http://dev.fyicenter.com/Azure-API/_icon_Azure-API.png' />How to + use the Developer Portal internally by you as the publisher? Normally, + the Developer Portal of an Azure API Management Service is used by + client developers. But as a publisher, you can also use the Developer + Portal to test API operations internally. You can follow this tutorial + to access the ... - Rank: 120; Updated: 2017-09-20 13:29:06 -> <a + href='http://dev.fyicenter.com/1000702_Use_Developer_Portal_Internally.ht + ml'>Source</a> + + FYIcenter.com + + + + + + Using Azure API Management Developer Portal + + + http://dev.fyicenter.com/1000701_Using_Azure_API_Management_Developer + _Portal.html + 2017-09-20T13:29:07+02:00 + <img align='left' width='64' height='64' + src='http://dev.fyicenter.com/Azure-API/_icon_Azure-API.png' />Where to + find tutorials on Using Azure API Management Developer Portal? Here is + a list of tutorials to answer many frequently asked questions compiled + by FYIcenter.com team on Using Azure API Management Developer Portal: + Use Developer Portal Internally What Can I See on Developer Portal What + I You T... - Rank: 120; Updated: 2017-09-20 13:29:06 -> <a + href='http://dev.fyicenter.com/1000701_Using_Azure_API_Management_Develop + er_Portal.html'>Source</a> + + FYIcenter.com + + + + + Add API to API Products + + http://dev.fyicenter.com/1000700_Add_API_to_API_Products.html + 2017-09-20T13:29:06+02:00 + <img align='left' width='64' height='64' + src='http://dev.fyicenter.com/Azure-API/_icon_Azure-API.png' />How to + add an API to an API product for internal testing on the Publisher + Portal of an Azure API Management Service? You can follow this tutorial + to add an API to an API product on the Publisher Portal of an Azure API + Management Service. 1. Click API from the left menu on the Publisher + Portal. You s... - Rank: 119; Updated: 2017-09-20 13:29:06 -> <a + href='http://dev.fyicenter.com/1000700_Add_API_to_API_Products.html'>Sour + ce</a> + + FYIcenter.com + + + + + + \ No newline at end of file