use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class DbWriterTest method testDeleteFeedNoDownloadedFiles.
@Test
public void testDeleteFeedNoDownloadedFiles() throws Exception {
File destFolder = context.getExternalFilesDir(TEST_FOLDER);
assertNotNull(destFolder);
Feed feed = new Feed("url", null, "title");
feed.setItems(new ArrayList<>());
feed.setImageUrl("url");
// create items with downloaded media files
for (int i = 0; i < 10; i++) {
FeedItem item = new FeedItem(0, "Item " + i, "Item" + i, "url", new Date(), FeedItem.PLAYED, feed);
feed.getItems().add(item);
File enc = new File(destFolder, "file " + i);
FeedMedia media = new FeedMedia(0, item, 1, 1, 1, "mime_type", enc.getAbsolutePath(), "download_url", false, null, 0, 0);
item.setMedia(media);
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
assertTrue(feed.getId() != 0);
for (FeedItem item : feed.getItems()) {
assertTrue(item.getId() != 0);
assertTrue(item.getMedia().getId() != 0);
}
DBWriter.deleteFeed(context, feed.getId()).get(TIMEOUT, TimeUnit.SECONDS);
adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor c = adapter.getFeedCursor(feed.getId());
assertEquals(0, c.getCount());
c.close();
for (FeedItem item : feed.getItems()) {
c = adapter.getFeedItemCursor(String.valueOf(item.getId()));
assertEquals(0, c.getCount());
c.close();
c = adapter.getSingleFeedMediaCursor(item.getMedia().getId());
assertEquals(0, c.getCount());
c.close();
}
adapter.close();
}
use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class DbWriterTest method testAddItemToPlaybackHistoryAlreadyPlayed.
@Test
public void testAddItemToPlaybackHistoryAlreadyPlayed() throws Exception {
final long oldDate = 0;
FeedMedia media = playbackHistorySetup(new Date(oldDate));
DBWriter.addItemToPlaybackHistory(media).get(TIMEOUT, TimeUnit.SECONDS);
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
media = DBReader.getFeedMedia(media.getId());
adapter.close();
assertNotNull(media);
assertNotNull(media.getPlaybackCompletionDate());
assertNotEquals(media.getPlaybackCompletionDate().getTime(), oldDate);
}
use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class FeedItemDuplicateGuesserTest method item.
private FeedItem item(String guid, String title, String downloadUrl, long date, long duration, String mime) {
FeedItem item = new FeedItem(0, title, guid, "link", new Date(date), FeedItem.PLAYED, null);
FeedMedia media = new FeedMedia(item, downloadUrl, duration, mime);
item.setMedia(media);
return item;
}
use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class DownloadRequestTest method downloadRequestTestEquals.
@Test
public void downloadRequestTestEquals() {
String destStr = "file://location/media.mp3";
String username = "testUser";
String password = "testPassword";
FeedMedia item = createFeedItem(1);
DownloadRequest request1 = new DownloadRequest.Builder(destStr, item).deleteOnFailure(true).withAuthentication(username, password).build();
DownloadRequest request2 = new DownloadRequest.Builder(destStr, item).deleteOnFailure(true).withAuthentication(username, password).build();
DownloadRequest request3 = new DownloadRequest.Builder(destStr, item).deleteOnFailure(true).withAuthentication("diffUsername", "diffPassword").build();
assertEquals(request1, request2);
assertNotEquals(request1, request3);
}
use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class DbTestUtils method saveFeedlist.
/**
* Use this method when tests involve chapters.
*/
public static List<Feed> saveFeedlist(int numFeeds, int numItems, boolean withMedia, boolean withChapters, int numChapters) {
if (numFeeds <= 0) {
throw new IllegalArgumentException("numFeeds<=0");
}
if (numItems < 0) {
throw new IllegalArgumentException("numItems<0");
}
List<Feed> feeds = new ArrayList<>();
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
for (int i = 0; i < numFeeds; i++) {
Feed f = new Feed(0, null, "feed " + i, "link" + i, "descr", null, null, null, null, "id" + i, null, null, "url" + i, false);
f.setItems(new ArrayList<>());
for (int j = 0; j < numItems; j++) {
FeedItem item = new FeedItem(0, "item " + j, "id" + j, "link" + j, new Date(), FeedItem.PLAYED, f, withChapters);
if (withMedia) {
FeedMedia media = new FeedMedia(item, "url" + j, 1, "audio/mp3");
item.setMedia(media);
}
if (withChapters) {
List<Chapter> chapters = new ArrayList<>();
item.setChapters(chapters);
for (int k = 0; k < numChapters; k++) {
chapters.add(new SimpleChapter(k, "item " + j + " chapter " + k, "http://example.com", "http://example.com/image.png"));
}
}
f.getItems().add(item);
}
Collections.sort(f.getItems(), new FeedItemPubdateComparator());
adapter.setCompleteFeed(f);
assertTrue(f.getId() != 0);
for (FeedItem item : f.getItems()) {
assertTrue(item.getId() != 0);
}
feeds.add(f);
}
adapter.close();
return feeds;
}
Aggregations