From ce48b186edf28ba03821e541c235497b99aba628 Mon Sep 17 00:00:00 2001 From: Herbert Reiter <46045854+damoasda@users.noreply.github.com> Date: Sat, 23 Jan 2021 19:26:46 +0100 Subject: [PATCH] Run AtomParserTest and RssParserTest with Robolectric --- .../antennapod/handler/AtomParserTest.java | 40 ----- .../handler/FeedParserTestBase.java | 154 ------------------ .../antennapod/handler/RssParserTest.java | 63 ------- .../feedgenerator/AtomGenerator.java | 131 --------------- .../syndication/handler/AtomParserTest.java | 70 ++++++++ .../handler/FeedParserTestHelper.java | 35 ++++ .../syndication/handler/RssParserTest.java | 86 ++++++++++ .../resources/feed-atom-testAtomBasic.xml | 1 + .../feed-atom-testLogoWithWhitespace.xml | 2 + .../feed-rss-testImageWithWhitespace.xml | 2 + .../feed-rss-testMediaContentMime.xml | 1 + .../test/resources/feed-rss-testRss2Basic.xml | 1 + 12 files changed, 198 insertions(+), 388 deletions(-) delete mode 100644 app/src/androidTest/java/de/test/antennapod/handler/AtomParserTest.java delete mode 100644 app/src/androidTest/java/de/test/antennapod/handler/FeedParserTestBase.java delete mode 100644 app/src/androidTest/java/de/test/antennapod/handler/RssParserTest.java delete mode 100644 app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/AtomGenerator.java create mode 100644 core/src/test/java/de/danoeh/antennapod/core/syndication/handler/AtomParserTest.java create mode 100644 core/src/test/java/de/danoeh/antennapod/core/syndication/handler/FeedParserTestHelper.java create mode 100644 core/src/test/java/de/danoeh/antennapod/core/syndication/handler/RssParserTest.java create mode 100644 core/src/test/resources/feed-atom-testAtomBasic.xml create mode 100644 core/src/test/resources/feed-atom-testLogoWithWhitespace.xml create mode 100644 core/src/test/resources/feed-rss-testImageWithWhitespace.xml create mode 100644 core/src/test/resources/feed-rss-testMediaContentMime.xml create mode 100644 core/src/test/resources/feed-rss-testRss2Basic.xml diff --git a/app/src/androidTest/java/de/test/antennapod/handler/AtomParserTest.java b/app/src/androidTest/java/de/test/antennapod/handler/AtomParserTest.java deleted file mode 100644 index de9f53ae2..000000000 --- a/app/src/androidTest/java/de/test/antennapod/handler/AtomParserTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package de.test.antennapod.handler; - -import androidx.test.filters.SmallTest; -import de.danoeh.antennapod.core.feed.Feed; -import de.test.antennapod.util.syndication.feedgenerator.AtomGenerator; -import org.junit.Test; -import org.xmlpull.v1.XmlSerializer; - -import java.io.IOException; - -import static org.junit.Assert.assertEquals; - -/** - * Tests for Atom feeds in FeedHandler. - */ -@SmallTest -public class AtomParserTest extends FeedParserTestBase { - @Test - public void testAtomBasic() throws Exception { - Feed f1 = createTestFeed(10, true); - Feed f2 = runFeedTest(f1, new AtomGenerator(), "UTF-8", 0); - feedValid(f1, f2, Feed.TYPE_ATOM1); - } - - @Test - public void testLogoWithWhitespace() throws Exception { - String logo = "https://example.com/image.png"; - Feed f1 = createTestFeed(0, false); - f1.setImageUrl(null); - Feed f2 = runFeedTest(f1, new AtomGenerator() { - @Override - protected void writeAdditionalAttributes(XmlSerializer xml) throws IOException { - xml.startTag(null, "logo"); - xml.text(" " + logo + "\n"); - xml.endTag(null, "logo"); - } - }, "UTF-8", 0); - assertEquals(logo, f2.getImageUrl()); - } -} diff --git a/app/src/androidTest/java/de/test/antennapod/handler/FeedParserTestBase.java b/app/src/androidTest/java/de/test/antennapod/handler/FeedParserTestBase.java deleted file mode 100644 index 83f334633..000000000 --- a/app/src/androidTest/java/de/test/antennapod/handler/FeedParserTestBase.java +++ /dev/null @@ -1,154 +0,0 @@ -package de.test.antennapod.handler; - -import android.content.Context; -import androidx.test.platform.app.InstrumentationRegistry; -import de.danoeh.antennapod.core.feed.Chapter; -import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.core.feed.FeedItem; -import de.danoeh.antennapod.core.feed.FeedMedia; -import de.danoeh.antennapod.core.syndication.handler.FeedHandler; -import de.danoeh.antennapod.core.syndication.handler.UnsupportedFeedtypeException; -import de.test.antennapod.util.syndication.feedgenerator.FeedGenerator; -import org.junit.After; -import org.junit.Before; -import org.xml.sax.SAXException; - -import javax.xml.parsers.ParserConfigurationException; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Tests for FeedHandler. - */ -public abstract class FeedParserTestBase { - private static final String FEEDS_DIR = "testfeeds"; - - private File file = null; - private OutputStream outputStream = null; - - @Before - public void setUp() throws Exception { - Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); - File destDir = context.getExternalFilesDir(FEEDS_DIR); - assertNotNull(destDir); - - file = new File(destDir, "feed.xml"); - file.delete(); - - assertNotNull(file); - assertFalse(file.exists()); - - outputStream = new FileOutputStream(file); - } - - - @After - public void tearDown() throws Exception { - file.delete(); - file = null; - - outputStream.close(); - outputStream = null; - } - - protected Feed runFeedTest(Feed feed, FeedGenerator g, String encoding, long flags) - throws IOException, UnsupportedFeedtypeException, SAXException, ParserConfigurationException { - g.writeFeed(feed, outputStream, encoding, flags); - FeedHandler handler = new FeedHandler(); - Feed parsedFeed = new Feed(feed.getDownload_url(), feed.getLastUpdate()); - parsedFeed.setFile_url(file.getAbsolutePath()); - parsedFeed.setDownloaded(true); - handler.parseFeed(parsedFeed); - return parsedFeed; - } - - protected void feedValid(Feed feed, Feed parsedFeed, String feedType) { - assertEquals(feed.getTitle(), parsedFeed.getTitle()); - if (feedType.equals(Feed.TYPE_ATOM1)) { - assertEquals(feed.getFeedIdentifier(), parsedFeed.getFeedIdentifier()); - } else { - assertEquals(feed.getLanguage(), parsedFeed.getLanguage()); - } - - assertEquals(feed.getLink(), parsedFeed.getLink()); - assertEquals(feed.getDescription(), parsedFeed.getDescription()); - assertEquals(feed.getPaymentLink(), parsedFeed.getPaymentLink()); - assertEquals(feed.getImageUrl(), parsedFeed.getImageUrl()); - - if (feed.getItems() != null) { - assertNotNull(parsedFeed.getItems()); - assertEquals(feed.getItems().size(), parsedFeed.getItems().size()); - - for (int i = 0; i < feed.getItems().size(); i++) { - FeedItem item = feed.getItems().get(i); - FeedItem parsedItem = parsedFeed.getItems().get(i); - - if (item.getItemIdentifier() != null) { - assertEquals(item.getItemIdentifier(), parsedItem.getItemIdentifier()); - } - assertEquals(item.getTitle(), parsedItem.getTitle()); - assertEquals(item.getDescription(), parsedItem.getDescription()); - assertEquals(item.getContentEncoded(), parsedItem.getContentEncoded()); - assertEquals(item.getLink(), parsedItem.getLink()); - assertEquals(item.getPubDate().getTime(), parsedItem.getPubDate().getTime()); - assertEquals(item.getPaymentLink(), parsedItem.getPaymentLink()); - - if (item.hasMedia()) { - assertTrue(parsedItem.hasMedia()); - FeedMedia media = item.getMedia(); - FeedMedia parsedMedia = parsedItem.getMedia(); - - assertEquals(media.getDownload_url(), parsedMedia.getDownload_url()); - assertEquals(media.getSize(), parsedMedia.getSize()); - assertEquals(media.getMime_type(), parsedMedia.getMime_type()); - } - - assertEquals(feed.getImageUrl(), item.getImageLocation()); - - if (item.getChapters() != null) { - assertNotNull(parsedItem.getChapters()); - assertEquals(item.getChapters().size(), parsedItem.getChapters().size()); - List chapters = item.getChapters(); - List parsedChapters = parsedItem.getChapters(); - for (int j = 0; j < chapters.size(); j++) { - Chapter chapter = chapters.get(j); - Chapter parsedChapter = parsedChapters.get(j); - - assertEquals(chapter.getTitle(), parsedChapter.getTitle()); - assertEquals(chapter.getLink(), parsedChapter.getLink()); - } - } - } - } - } - - protected Feed createTestFeed(int numItems, boolean withFeedMedia) { - Feed feed = new Feed(0, null, "title", "http://example.com", "This is the description", - "http://example.com/payment", "Daniel", "en", null, "http://example.com/feed", - "http://example.com/picture", file.getAbsolutePath(), "http://example.com/feed", true); - feed.setItems(new ArrayList<>()); - - for (int i = 0; i < numItems; i++) { - FeedItem item = new FeedItem(0, "item-" + i, "http://example.com/item-" + i, - "http://example.com/items/" + i, new Date(i * 60000), FeedItem.UNPLAYED, feed); - feed.getItems().add(item); - if (withFeedMedia) { - item.setMedia(new FeedMedia(0, item, 4711, 0, 1024 * 1024, "audio/mp3", null, - "http://example.com/media-" + i, false, null, 0, 0)); - } - } - - return feed; - } - -} diff --git a/app/src/androidTest/java/de/test/antennapod/handler/RssParserTest.java b/app/src/androidTest/java/de/test/antennapod/handler/RssParserTest.java deleted file mode 100644 index c2e319233..000000000 --- a/app/src/androidTest/java/de/test/antennapod/handler/RssParserTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package de.test.antennapod.handler; - -import androidx.test.filters.SmallTest; -import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.core.feed.MediaType; -import de.danoeh.antennapod.core.syndication.namespace.NSMedia; -import de.test.antennapod.util.syndication.feedgenerator.Rss2Generator; -import org.junit.Test; -import org.xmlpull.v1.XmlSerializer; - -import java.io.IOException; - -import static org.junit.Assert.assertEquals; - -/** - * Tests for RSS feeds in FeedHandler. - */ -@SmallTest -public class RssParserTest extends FeedParserTestBase { - @Test - public void testRss2Basic() throws Exception { - Feed f1 = createTestFeed(10, true); - Feed f2 = runFeedTest(f1, new Rss2Generator(), "UTF-8", Rss2Generator.FEATURE_WRITE_GUID); - feedValid(f1, f2, Feed.TYPE_RSS2); - } - - @Test - public void testImageWithWhitespace() throws Exception { - String image = "https://example.com/image.png"; - Feed f1 = createTestFeed(0, false); - f1.setImageUrl(null); - Feed f2 = runFeedTest(f1, new Rss2Generator() { - @Override - protected void writeAdditionalAttributes(XmlSerializer xml) throws IOException { - xml.startTag(null, "image"); - xml.startTag(null, "url"); - xml.text(" " + image + "\n"); - xml.endTag(null, "url"); - xml.endTag(null, "image"); - } - }, "UTF-8", 0); - assertEquals(image, f2.getImageUrl()); - } - - @Test - public void testMediaContentMime() throws Exception { - Feed f1 = createTestFeed(0, false); - f1.setImageUrl(null); - Feed f2 = runFeedTest(f1, new Rss2Generator() { - @Override - protected void writeAdditionalAttributes(XmlSerializer xml) throws IOException { - xml.setPrefix(NSMedia.NSTAG, NSMedia.NSURI); - xml.startTag(null, "item"); - xml.startTag(NSMedia.NSURI, "content"); - xml.attribute(null, "url", "https://www.example.com/file.mp4"); - xml.attribute(null, "medium", "video"); - xml.endTag(NSMedia.NSURI, "content"); - xml.endTag(null, "item"); - } - }, "UTF-8", 0); - assertEquals(MediaType.VIDEO, f2.getItems().get(0).getMedia().getMediaType()); - } -} diff --git a/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/AtomGenerator.java b/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/AtomGenerator.java deleted file mode 100644 index c80e3bbb1..000000000 --- a/app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/AtomGenerator.java +++ /dev/null @@ -1,131 +0,0 @@ -package de.test.antennapod.util.syndication.feedgenerator; - -import android.util.Xml; - -import org.xmlpull.v1.XmlSerializer; - -import java.io.IOException; -import java.io.OutputStream; - -import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.core.feed.FeedItem; -import de.danoeh.antennapod.core.feed.FeedMedia; -import de.danoeh.antennapod.core.util.DateUtils; - -/** - * Creates Atom feeds. See FeedGenerator for more information. - */ -public class AtomGenerator implements FeedGenerator { - - private static final String NS_ATOM = "http://www.w3.org/2005/Atom"; - - private static final long FEATURE_USE_RFC3339LOCAL = 1; - - @Override - public void writeFeed(Feed feed, OutputStream outputStream, String encoding, long flags) throws IOException { - if (feed == null) throw new IllegalArgumentException("feed = null"); - if (outputStream == null) throw new IllegalArgumentException("outputStream = null"); - if (encoding == null) throw new IllegalArgumentException("encoding = null"); - - XmlSerializer xml = Xml.newSerializer(); - xml.setOutput(outputStream, encoding); - xml.startDocument(encoding, null); - - xml.startTag(null, "feed"); - xml.attribute(null, "xmlns", NS_ATOM); - - // Write Feed data - if (feed.getIdentifyingValue() != null) { - xml.startTag(null, "id"); - xml.text(feed.getIdentifyingValue()); - xml.endTag(null, "id"); - } - if (feed.getTitle() != null) { - xml.startTag(null, "title"); - xml.text(feed.getTitle()); - xml.endTag(null, "title"); - } - if (feed.getLink() != null) { - xml.startTag(null, "link"); - xml.attribute(null, "rel", "alternate"); - xml.attribute(null, "href", feed.getLink()); - xml.endTag(null, "link"); - } - if (feed.getDescription() != null) { - xml.startTag(null, "subtitle"); - xml.text(feed.getDescription()); - xml.endTag(null, "subtitle"); - } - if (feed.getImageUrl() != null) { - xml.startTag(null, "logo"); - xml.text(feed.getImageUrl()); - xml.endTag(null, "logo"); - } - - if (feed.getPaymentLink() != null) { - GeneratorUtil.addPaymentLink(xml, feed.getPaymentLink(), false); - } - - // Write FeedItem data - if (feed.getItems() != null) { - for (FeedItem item : feed.getItems()) { - xml.startTag(null, "entry"); - - if (item.getIdentifyingValue() != null) { - xml.startTag(null, "id"); - xml.text(item.getIdentifyingValue()); - xml.endTag(null, "id"); - } - if (item.getTitle() != null) { - xml.startTag(null, "title"); - xml.text(item.getTitle()); - xml.endTag(null, "title"); - } - if (item.getLink() != null) { - xml.startTag(null, "link"); - xml.attribute(null, "rel", "alternate"); - xml.attribute(null, "href", item.getLink()); - xml.endTag(null, "link"); - } - if (item.getPubDate() != null) { - xml.startTag(null, "published"); - if ((flags & FEATURE_USE_RFC3339LOCAL) != 0) { - xml.text(DateUtils.formatRFC3339Local(item.getPubDate())); - } else { - xml.text(DateUtils.formatRFC3339UTC(item.getPubDate())); - } - xml.endTag(null, "published"); - } - if (item.getDescription() != null) { - xml.startTag(null, "content"); - xml.text(item.getDescription()); - xml.endTag(null, "content"); - } - if (item.getMedia() != null) { - FeedMedia media = item.getMedia(); - xml.startTag(null, "link"); - xml.attribute(null, "rel", "enclosure"); - xml.attribute(null, "href", media.getDownload_url()); - xml.attribute(null, "type", media.getMime_type()); - xml.attribute(null, "length", String.valueOf(media.getSize())); - xml.endTag(null, "link"); - } - - if (item.getPaymentLink() != null) { - GeneratorUtil.addPaymentLink(xml, item.getPaymentLink(), false); - } - - xml.endTag(null, "entry"); - } - } - - writeAdditionalAttributes(xml); - - xml.endTag(null, "feed"); - xml.endDocument(); - } - - protected void writeAdditionalAttributes(XmlSerializer xml) throws IOException { - - } -} diff --git a/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/AtomParserTest.java b/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/AtomParserTest.java new file mode 100644 index 000000000..82f7fcfca --- /dev/null +++ b/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/AtomParserTest.java @@ -0,0 +1,70 @@ +package de.danoeh.antennapod.core.syndication.handler; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +import java.io.File; +import java.util.Date; + +import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.feed.FeedMedia; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * Tests for Atom feeds in FeedHandler. + */ +@RunWith(RobolectricTestRunner.class) +public class AtomParserTest { + + @Test + public void testAtomBasic() throws Exception { + File feedFile = FeedParserTestHelper.getFeedFile("feed-atom-testAtomBasic.xml"); + Feed feed = FeedParserTestHelper.runFeedParser(feedFile); + assertEquals(Feed.TYPE_ATOM1, feed.getType()); + assertEquals("title", feed.getTitle()); + assertEquals("http://example.com/feed", feed.getFeedIdentifier()); + assertEquals("http://example.com", feed.getLink()); + assertEquals("This is the description", feed.getDescription()); + assertEquals("http://example.com/payment", feed.getPaymentLink()); + assertEquals("http://example.com/picture", feed.getImageUrl()); + assertEquals(10, feed.getItems().size()); + for (int i = 0; i < feed.getItems().size(); i++) { + FeedItem item = feed.getItems().get(i); + assertEquals("http://example.com/item-" + i, item.getItemIdentifier()); + assertEquals("item-" + i, item.getTitle()); + assertNull(item.getDescription()); + assertNull(item.getContentEncoded()); + assertEquals("http://example.com/items/" + i, item.getLink()); + assertEquals(new Date(i * 60000), item.getPubDate()); + assertNull(item.getPaymentLink()); + assertEquals("http://example.com/picture", item.getImageLocation()); + // media + assertTrue(item.hasMedia()); + FeedMedia media = item.getMedia(); + //noinspection ConstantConditions + assertEquals("http://example.com/media-" + i, media.getDownload_url()); + assertEquals(1024 * 1024, media.getSize()); + assertEquals("audio/mp3", media.getMime_type()); + // chapters + assertNull(item.getChapters()); + } + } + + @Test + public void testLogoWithWhitespace() throws Exception { + File feedFile = FeedParserTestHelper.getFeedFile("feed-atom-testLogoWithWhitespace.xml"); + Feed feed = FeedParserTestHelper.runFeedParser(feedFile); + assertEquals("title", feed.getTitle()); + assertEquals("http://example.com/feed", feed.getFeedIdentifier()); + assertEquals("http://example.com", feed.getLink()); + assertEquals("This is the description", feed.getDescription()); + assertEquals("http://example.com/payment", feed.getPaymentLink()); + assertEquals("https://example.com/image.png", feed.getImageUrl()); + assertEquals(0, feed.getItems().size()); + } +} diff --git a/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/FeedParserTestHelper.java b/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/FeedParserTestHelper.java new file mode 100644 index 000000000..c02a7d209 --- /dev/null +++ b/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/FeedParserTestHelper.java @@ -0,0 +1,35 @@ +package de.danoeh.antennapod.core.syndication.handler; + +import androidx.annotation.NonNull; + +import java.io.File; + +import de.danoeh.antennapod.core.feed.Feed; + +/** + * Tests for FeedHandler. + */ +public abstract class FeedParserTestHelper { + + /** + * Returns the File object for a file in the resources folder. + */ + @NonNull + static File getFeedFile(@NonNull String fileName) { + //noinspection ConstantConditions + return new File(FeedParserTestHelper.class.getClassLoader().getResource(fileName).getFile()); + } + + /** + * Runs the feed parser on the given file. + */ + @NonNull + static Feed runFeedParser(@NonNull File feedFile) throws Exception { + FeedHandler handler = new FeedHandler(); + Feed parsedFeed = new Feed("http://example.com/feed", null); + parsedFeed.setFile_url(feedFile.getAbsolutePath()); + parsedFeed.setDownloaded(true); + handler.parseFeed(parsedFeed); + return parsedFeed; + } +} diff --git a/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/RssParserTest.java b/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/RssParserTest.java new file mode 100644 index 000000000..1195520a6 --- /dev/null +++ b/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/RssParserTest.java @@ -0,0 +1,86 @@ +package de.danoeh.antennapod.core.syndication.handler; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +import java.io.File; +import java.util.Date; + +import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.feed.FeedMedia; +import de.danoeh.antennapod.core.feed.MediaType; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * Tests for RSS feeds in FeedHandler. + */ +@RunWith(RobolectricTestRunner.class) +public class RssParserTest { + + @Test + public void testRss2Basic() throws Exception { + File feedFile = FeedParserTestHelper.getFeedFile("feed-rss-testRss2Basic.xml"); + Feed feed = FeedParserTestHelper.runFeedParser(feedFile); + assertEquals(Feed.TYPE_RSS2, feed.getType()); + assertEquals("title", feed.getTitle()); + assertEquals("en", feed.getLanguage()); + assertEquals("http://example.com", feed.getLink()); + assertEquals("This is the description", feed.getDescription()); + assertEquals("http://example.com/payment", feed.getPaymentLink()); + assertEquals("http://example.com/picture", feed.getImageUrl()); + assertEquals(10, feed.getItems().size()); + for (int i = 0; i < feed.getItems().size(); i++) { + FeedItem item = feed.getItems().get(i); + assertEquals("http://example.com/item-" + i, item.getItemIdentifier()); + assertEquals("item-" + i, item.getTitle()); + assertNull(item.getDescription()); + assertNull(item.getContentEncoded()); + assertEquals("http://example.com/items/" + i, item.getLink()); + assertEquals(new Date(i * 60000), item.getPubDate()); + assertNull(item.getPaymentLink()); + assertEquals("http://example.com/picture", item.getImageLocation()); + // media + assertTrue(item.hasMedia()); + FeedMedia media = item.getMedia(); + //noinspection ConstantConditions + assertEquals("http://example.com/media-" + i, media.getDownload_url()); + assertEquals(1024 * 1024, media.getSize()); + assertEquals("audio/mp3", media.getMime_type()); + // chapters + assertNull(item.getChapters()); + } + } + + @Test + public void testImageWithWhitespace() throws Exception { + File feedFile = FeedParserTestHelper.getFeedFile("feed-rss-testImageWithWhitespace.xml"); + Feed feed = FeedParserTestHelper.runFeedParser(feedFile); + assertEquals("title", feed.getTitle()); + assertEquals("http://example.com", feed.getLink()); + assertEquals("This is the description", feed.getDescription()); + assertEquals("http://example.com/payment", feed.getPaymentLink()); + assertEquals("https://example.com/image.png", feed.getImageUrl()); + assertEquals(0, feed.getItems().size()); + } + + @Test + public void testMediaContentMime() throws Exception { + File feedFile = FeedParserTestHelper.getFeedFile("feed-rss-testMediaContentMime.xml"); + Feed feed = FeedParserTestHelper.runFeedParser(feedFile); + assertEquals("title", feed.getTitle()); + assertEquals("http://example.com", feed.getLink()); + assertEquals("This is the description", feed.getDescription()); + assertEquals("http://example.com/payment", feed.getPaymentLink()); + assertNull(feed.getImageUrl()); + assertEquals(1, feed.getItems().size()); + FeedItem feedItem = feed.getItems().get(0); + //noinspection ConstantConditions + assertEquals(MediaType.VIDEO, feedItem.getMedia().getMediaType()); + assertEquals("https://www.example.com/file.mp4", feedItem.getMedia().getDownload_url()); + } +} diff --git a/core/src/test/resources/feed-atom-testAtomBasic.xml b/core/src/test/resources/feed-atom-testAtomBasic.xml new file mode 100644 index 000000000..cefc4f979 --- /dev/null +++ b/core/src/test/resources/feed-atom-testAtomBasic.xml @@ -0,0 +1 @@ +http://example.com/feedtitleThis is the descriptionhttp://example.com/picturehttp://example.com/item-0item-01970-01-01T00:00:00Zhttp://example.com/item-1item-11970-01-01T00:01:00Zhttp://example.com/item-2item-21970-01-01T00:02:00Zhttp://example.com/item-3item-31970-01-01T00:03:00Zhttp://example.com/item-4item-41970-01-01T00:04:00Zhttp://example.com/item-5item-51970-01-01T00:05:00Zhttp://example.com/item-6item-61970-01-01T00:06:00Zhttp://example.com/item-7item-71970-01-01T00:07:00Zhttp://example.com/item-8item-81970-01-01T00:08:00Zhttp://example.com/item-9item-91970-01-01T00:09:00Z \ No newline at end of file diff --git a/core/src/test/resources/feed-atom-testLogoWithWhitespace.xml b/core/src/test/resources/feed-atom-testLogoWithWhitespace.xml new file mode 100644 index 000000000..f4886d56a --- /dev/null +++ b/core/src/test/resources/feed-atom-testLogoWithWhitespace.xml @@ -0,0 +1,2 @@ +http://example.com/feedtitleThis is the description https://example.com/image.png + \ No newline at end of file diff --git a/core/src/test/resources/feed-rss-testImageWithWhitespace.xml b/core/src/test/resources/feed-rss-testImageWithWhitespace.xml new file mode 100644 index 000000000..2be9401d2 --- /dev/null +++ b/core/src/test/resources/feed-rss-testImageWithWhitespace.xml @@ -0,0 +1,2 @@ +titleThis is the descriptionhttp://example.comen https://example.com/image.png + \ No newline at end of file diff --git a/core/src/test/resources/feed-rss-testMediaContentMime.xml b/core/src/test/resources/feed-rss-testMediaContentMime.xml new file mode 100644 index 000000000..a715abb37 --- /dev/null +++ b/core/src/test/resources/feed-rss-testMediaContentMime.xml @@ -0,0 +1 @@ +titleThis is the descriptionhttp://example.comen \ No newline at end of file diff --git a/core/src/test/resources/feed-rss-testRss2Basic.xml b/core/src/test/resources/feed-rss-testRss2Basic.xml new file mode 100644 index 000000000..dd771b61a --- /dev/null +++ b/core/src/test/resources/feed-rss-testRss2Basic.xml @@ -0,0 +1 @@ +titleThis is the descriptionhttp://example.comenhttp://example.com/pictureitem-0http://example.com/items/001 Jan 70 01:00:00 +0100http://example.com/item-0item-1http://example.com/items/101 Jan 70 01:01:00 +0100http://example.com/item-1item-2http://example.com/items/201 Jan 70 01:02:00 +0100http://example.com/item-2item-3http://example.com/items/301 Jan 70 01:03:00 +0100http://example.com/item-3item-4http://example.com/items/401 Jan 70 01:04:00 +0100http://example.com/item-4item-5http://example.com/items/501 Jan 70 01:05:00 +0100http://example.com/item-5item-6http://example.com/items/601 Jan 70 01:06:00 +0100http://example.com/item-6item-7http://example.com/items/701 Jan 70 01:07:00 +0100http://example.com/item-7item-8http://example.com/items/801 Jan 70 01:08:00 +0100http://example.com/item-8item-9http://example.com/items/901 Jan 70 01:09:00 +0100http://example.com/item-9 \ No newline at end of file