use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class DbTasksTest method testUpdateFeedRemoveUnlistedItems.
@Test
public void testUpdateFeedRemoveUnlistedItems() {
final Feed feed = new Feed("url", null, "title");
feed.setItems(new ArrayList<>());
for (int i = 0; i < 10; i++) {
feed.getItems().add(new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.PLAYED, feed));
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
// delete some items
feed.getItems().subList(0, 2).clear();
Feed newFeed = DBTasks.updateFeed(context, feed, true);
// 10 - 2 = 8 items
assertEquals(8, newFeed.getItems().size());
Feed feedFromDB = DBReader.getFeed(newFeed.getId());
// 10 - 2 = 8 items
assertEquals(8, feedFromDB.getItems().size());
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class DbTasksTest method testUpdateFeedUpdatedFeed.
@Test
public void testUpdateFeedUpdatedFeed() {
final int numItemsOld = 10;
final int numItemsNew = 10;
final Feed feed = new Feed("url", null, "title");
feed.setItems(new ArrayList<>());
for (int i = 0; i < numItemsOld; i++) {
feed.getItems().add(new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.PLAYED, feed));
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
// ensure that objects have been saved in db, then reset
assertTrue(feed.getId() != 0);
final long feedID = feed.getId();
feed.setId(0);
List<Long> itemIDs = new ArrayList<>();
for (FeedItem item : feed.getItems()) {
assertTrue(item.getId() != 0);
itemIDs.add(item.getId());
item.setId(0);
}
for (int i = numItemsOld; i < numItemsNew + numItemsOld; i++) {
feed.getItems().add(0, new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.UNPLAYED, feed));
}
final Feed newFeed = DBTasks.updateFeed(context, feed, false);
assertNotSame(newFeed, feed);
updatedFeedTest(newFeed, feedID, itemIDs, numItemsOld, numItemsNew);
final Feed feedFromDB = DBReader.getFeed(newFeed.getId());
assertNotNull(feedFromDB);
assertEquals(newFeed.getId(), feedFromDB.getId());
updatedFeedTest(feedFromDB, feedID, itemIDs, numItemsOld, numItemsNew);
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class DbTasksTest method testUpdateFeedSetDuplicate.
@Test
public void testUpdateFeedSetDuplicate() {
final Feed feed = new Feed("url", null, "title");
feed.setItems(new ArrayList<>());
for (int i = 0; i < 10; i++) {
FeedItem item = new FeedItem(0, "item " + i, "id " + i, "link " + i, new Date(i), FeedItem.PLAYED, feed);
FeedMedia media = new FeedMedia(item, "download url " + i, 123, "media/mp3");
item.setMedia(media);
feed.getItems().add(item);
}
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
// change the guid of the first item, but leave the download url the same
FeedItem item = feed.getItemAtIndex(0);
item.setItemIdentifier("id 0-duplicate");
item.setTitle("item 0 duplicate");
Feed newFeed = DBTasks.updateFeed(context, feed, false);
// id 1-duplicate replaces because the stream url is the same
assertEquals(10, newFeed.getItems().size());
Feed feedFromDB = DBReader.getFeed(newFeed.getId());
// id1-duplicate should override id 1
assertEquals(10, feedFromDB.getItems().size());
FeedItem updatedItem = feedFromDB.getItemAtIndex(9);
assertEquals("item 0 duplicate", updatedItem.getTitle());
// Should use the new ID for sync etc
assertEquals("id 0-duplicate", updatedItem.getItemIdentifier());
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class DbTasksTest method updatedFeedTest.
@SuppressWarnings("SameParameterValue")
private void updatedFeedTest(final Feed newFeed, long feedID, List<Long> itemIDs, int numItemsOld, int numItemsNew) {
assertEquals(feedID, newFeed.getId());
assertEquals(numItemsNew + numItemsOld, newFeed.getItems().size());
Collections.reverse(newFeed.getItems());
Date lastDate = new Date(0);
for (int i = 0; i < numItemsOld; i++) {
FeedItem item = newFeed.getItems().get(i);
assertSame(newFeed, item.getFeed());
assertEquals((long) itemIDs.get(i), item.getId());
assertTrue(item.isPlayed());
assertTrue(item.getPubDate().getTime() >= lastDate.getTime());
lastDate = item.getPubDate();
}
for (int i = numItemsOld; i < numItemsNew + numItemsOld; i++) {
FeedItem item = newFeed.getItems().get(i);
assertSame(newFeed, item.getFeed());
assertTrue(item.getId() != 0);
assertFalse(item.isPlayed());
assertTrue(item.getPubDate().getTime() >= lastDate.getTime());
lastDate = item.getPubDate();
}
}
use of de.danoeh.antennapod.model.feed.FeedItem in project AntennaPod by AntennaPod.
the class DbWriterTest method testAddQueueItemSingleItem.
@Test
public void testAddQueueItemSingleItem() throws Exception {
Feed feed = new Feed("url", null, "title");
feed.setItems(new ArrayList<>());
FeedItem item = new FeedItem(0, "title", "id", "link", new Date(), FeedItem.PLAYED, feed);
feed.getItems().add(item);
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setCompleteFeed(feed);
adapter.close();
assertTrue(item.getId() != 0);
DBWriter.addQueueItem(context, item).get(TIMEOUT, TimeUnit.SECONDS);
adapter = PodDBAdapter.getInstance();
adapter.open();
Cursor cursor = adapter.getQueueIDCursor();
assertTrue(cursor.moveToFirst());
assertEquals(item.getId(), cursor.getLong(0));
cursor.close();
adapter.close();
}
Aggregations