예제 #1
0
  public void testMarkAllItemsReadSameFeed()
      throws InterruptedException, ExecutionException, TimeoutException {
    final int NUM_ITEMS = 10;
    Feed feed = new Feed("url", null, "title");
    feed.setItems(new ArrayList<>());
    for (int i = 0; i < NUM_ITEMS; i++) {
      FeedItem item =
          new FeedItem(
              0, "title " + i, "id " + i, "link " + i, new Date(), FeedItem.UNPLAYED, feed);
      feed.getItems().add(item);
    }

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();

    assertTrue(feed.getId() != 0);
    for (FeedItem item : feed.getItems()) {
      assertTrue(item.getId() != 0);
    }

    DBWriter.markAllItemsRead().get(TIMEOUT, TimeUnit.SECONDS);
    List<FeedItem> loadedItems = DBReader.getFeedItemList(feed);
    for (FeedItem item : loadedItems) {
      assertTrue(item.isPlayed());
    }
  }
예제 #2
0
  public void testSetFeedMediaPlaybackInformation()
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    final int POSITION = 50;
    final long LAST_PLAYED_TIME = 1000;
    final int PLAYED_DURATION = 60;
    final int DURATION = 100;

    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.PLAYED, feed);
    items.add(item);
    FeedMedia media =
        new FeedMedia(
            0, item, DURATION, 1, 1, "mime_type", "dummy path", "download_url", true, null, 0, 0);
    item.setMedia(media);

    DBWriter.setFeedItem(item).get(TIMEOUT, TimeUnit.SECONDS);

    media.setPosition(POSITION);
    media.setLastPlayedTime(LAST_PLAYED_TIME);
    media.setPlayedDuration(PLAYED_DURATION);

    DBWriter.setFeedMediaPlaybackInformation(item.getMedia()).get(TIMEOUT, TimeUnit.SECONDS);

    FeedItem itemFromDb = DBReader.getFeedItem(item.getId());
    FeedMedia mediaFromDb = itemFromDb.getMedia();

    assertEquals(POSITION, mediaFromDb.getPosition());
    assertEquals(LAST_PLAYED_TIME, mediaFromDb.getLastPlayedTime());
    assertEquals(PLAYED_DURATION, mediaFromDb.getPlayedDuration());
    assertEquals(DURATION, mediaFromDb.getDuration());
  }
예제 #3
0
  public void testAddItemToPlaybackHistoryNotPlayedYet()
      throws ExecutionException, InterruptedException, TimeoutException {
    FeedMedia media = playbackHistorySetup(null);
    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());
  }
예제 #4
0
  public void testAddItemToPlaybackHistoryAlreadyPlayed()
      throws ExecutionException, InterruptedException, TimeoutException {
    final long OLD_DATE = 0;

    FeedMedia media = playbackHistorySetup(new Date(OLD_DATE));
    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());
    assertFalse(OLD_DATE == media.getPlaybackCompletionDate().getTime());
  }
예제 #5
0
  public void testDeleteFeedMediaOfItemFileExists()
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    File dest =
        new File(
            getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER), "testFile");

    assertTrue(dest.createNewFile());

    Feed feed = new Feed("url", null, "title");
    List<FeedItem> items = new ArrayList<>();
    feed.setItems(items);
    FeedItem item = new FeedItem(0, "Item", "Item", "url", new Date(), FeedItem.PLAYED, feed);

    FeedMedia media =
        new FeedMedia(
            0,
            item,
            1,
            1,
            1,
            "mime_type",
            dest.getAbsolutePath(),
            "download_url",
            true,
            null,
            0,
            0);
    item.setMedia(media);

    items.add(item);

    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(feed);
    adapter.close();
    assertTrue(media.getId() != 0);
    assertTrue(item.getId() != 0);

    DBWriter.deleteFeedMediaOfItem(getInstrumentation().getTargetContext(), media.getId())
        .get(TIMEOUT, TimeUnit.SECONDS);
    media = DBReader.getFeedMedia(media.getId());
    assertNotNull(media);
    assertFalse(dest.exists());
    assertFalse(media.isDownloaded());
    assertNull(media.getFile_url());
  }
 @Override
 protected void loadData() {
   super.loadData();
   feeds = DBReader.getFeedList(this);
 }