summaryrefslogtreecommitdiff
path: root/app/src/androidTest
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2021-01-24 12:20:09 +0100
committerGitHub <noreply@github.com>2021-01-24 12:20:09 +0100
commita36d66bf35e7660e678af342e1cf7e2be783c8ce (patch)
tree7fa67c294ed1ad3c5460b88ccec5ccbcb315a2e8 /app/src/androidTest
parent72ab17f1533317c676d9182c92519fffe75ba5db (diff)
parentce48b186edf28ba03821e541c235497b99aba628 (diff)
downloadAntennaPod-a36d66bf35e7660e678af342e1cf7e2be783c8ce.zip
Merge pull request #4893 from damoasda/robolectric-feed-parser2
Run AtomParserTest and RssParserTest with Robolectric
Diffstat (limited to 'app/src/androidTest')
-rw-r--r--app/src/androidTest/java/de/test/antennapod/handler/AtomParserTest.java40
-rw-r--r--app/src/androidTest/java/de/test/antennapod/handler/FeedParserTestBase.java154
-rw-r--r--app/src/androidTest/java/de/test/antennapod/handler/RssParserTest.java63
-rw-r--r--app/src/androidTest/java/de/test/antennapod/util/syndication/feedgenerator/AtomGenerator.java131
4 files changed, 0 insertions, 388 deletions
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<Chapter> chapters = item.getChapters();
- List<Chapter> 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 {
-
- }
-}