Beispiel #1
0
 /** tests the getpodcastbyurl functionality */
 public void testGetPodcastByUrl() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   String url = "supergeileurl";
   p1.setUrl(url);
   pdao.insertPodcast(p1);
   Podcast nw = pdao.getPodcastByUrl(url);
   assertEquals(url, nw.getUrl());
 }
Beispiel #2
0
 /** tests the updateLastUpdate functionality */
 public void testUpdateLastUpdate() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   p1 = pdao.insertPodcast(p1);
   long currentMilis = System.currentTimeMillis();
   p1.setLastUpdate(currentMilis);
   assertEquals(1, pdao.updateLastUpdate(p1));
   Podcast pod = pdao.getPodcastById(p1.getId());
   assertEquals(currentMilis, pod.getLastUpdate());
 }
Beispiel #3
0
 /** tests the updateLogoFilePath functionality */
 public void testUpdateLogoFilePath() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   p1 = pdao.insertPodcast(p1);
   String newFilePath = "new path haha";
   p1.setLogoFilePath(newFilePath);
   assertEquals(1, pdao.updateLogoFilePath(p1));
   Podcast pod = pdao.getPodcastById(p1.getId());
   assertEquals(newFilePath, pod.getLogoFilePath());
 }
Beispiel #4
0
  private Podcast insertPodcast() {
    Podcast p = new Podcast();
    uuid = java.util.UUID.randomUUID().toString();
    p.setTitle(uuid);
    p.setLocalAdd(true);

    assertTrue(dao.insertPodcast(p) != null);

    return p;
  }
Beispiel #5
0
  /** Upon adding a new podcast to the DAO, it should be displayed in the podcast list. */
  public void testAddPodcast() {
    Podcast p = insertPodcast();

    while (solo.scrollDown()) ;

    assertTrue(
        String.format("New podcast %s should be displayed in list", uuid), solo.searchText(uuid));
    assertTrue(
        String.format("New podcast %s should be in DAO", uuid),
        dao.getPodcastById(p.getId()) != null);
  }
Beispiel #6
0
  public void testRotation() {
    Podcast p = insertPodcast();

    solo.setActivityOrientation(Solo.LANDSCAPE);
    while (solo.scrollDown()) ;

    assertTrue(
        String.format("New podcast %s should be displayed in list", uuid), solo.searchText(uuid));
    assertTrue(
        String.format("New podcast %s should be in DAO", uuid),
        dao.getPodcastById(p.getId()) != null);
  }
Beispiel #7
0
  private List<Podcast> cacheResults(List<Podcast> ps) {
    if (ps == null) {
      return null;
    }

    synchronized (cache) {
      for (Podcast p : ps) {
        if (!cache.containsKey(p.getId())) {
          cache.put(p.getId(), p);
        }
      }

      return new ArrayList<Podcast>(cache.values());
    }
  }
Beispiel #8
0
  /**
   * After deleting the newly added podcast, it should not be displayed in the podcast list, and
   * should not be contained in the podcast DAO.
   */
  public void testRemovePodcast() {
    Podcast p = insertPodcast();

    while (solo.scrollDown()) ;

    solo.clickLongOnText(uuid);
    solo.clickOnText(getActivity().getString(at.ac.tuwien.detlef.R.string.delete_feed));

    assertFalse(
        String.format("Deleted podcast %s should not be displayed in list", uuid),
        solo.searchText(uuid));
    assertFalse(
        String.format("Deleted podcast %s should not be in DAO", uuid),
        dao.getPodcastById(p.getId()) != null);
  }
Beispiel #9
0
 /** tests the getPodcastById functionality */
 public void testGetPodcastById() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   p1.setTitle("expected title");
   p1 = pdao.insertPodcast(p1);
   Podcast pod = pdao.getPodcastById(p1.getId());
   assertEquals("expected title", pod.getTitle());
   assertEquals(p1.getLastUpdate(), pod.getLastUpdate());
   assertEquals(p1.hashCode(), pod.hashCode());
 }
Beispiel #10
0
  @Override
  public boolean localDeletePodcast(Podcast podcast) {
    synchronized (cache) {
      cache.remove(podcast.getId());
    }

    return dao.localDeletePodcast(podcast);
  }
Beispiel #11
0
  @Override
  public int deletePodcast(Podcast podcast) {
    synchronized (cache) {
      cache.remove(podcast.getId());
    }

    return dao.deletePodcast(podcast);
  }
Beispiel #12
0
 /** tests the insertPodcast functionality */
 public void testInsertPodcast() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   int countBeforeInsert = pdao.getAllPodcasts().size();
   p1 = pdao.insertPodcast(p1);
   int countAfterInsert = pdao.getAllPodcasts().size();
   assertEquals(countBeforeInsert + 1, countAfterInsert);
   assertTrue(p1.getId() > 0);
 }
Beispiel #13
0
  @Override
  public Podcast insertPodcast(Podcast podcast) {
    if (dao.insertPodcast(podcast) == null) {
      return null;
    }

    synchronized (cache) {
      cache.put(podcast.getId(), podcast);
    }

    return podcast;
  }
Beispiel #14
0
  @Override
  public Podcast getPodcastByUrl(String url) {
    synchronized (cache) {
      for (Podcast p : cache.values()) {
        if (p.getUrl().equals(url)) {
          return p;
        }
      }
    }

    Podcast p = dao.getPodcastByUrl(url);
    if (p == null) {
      return null;
    }

    synchronized (cache) {
      cache.put(p.getId(), p);
    }

    return p;
  }
Beispiel #15
0
  @Override
  public Podcast getPodcastById(long podcastId) {
    Podcast p;
    synchronized (cache) {
      p = cache.get(podcastId);
    }

    if (p != null) {
      return p;
    }

    p = dao.getPodcastById(podcastId);
    if (p == null) {
      return null;
    }

    synchronized (cache) {
      cache.put(p.getId(), p);
    }

    return p;
  }
Beispiel #16
0
 @Override
 protected void setUp() throws Exception {
   p1 = new Podcast();
   p1.setDescription("description");
   p1.setLastUpdate(111);
   p1.setLogoFilePath("logoFilePath");
   p1.setLogoUrl("logoUrl");
   p1.setTitle("title");
   p1.setUrl("url");
   super.setUp();
 }
Beispiel #17
0
  @Override
  public void onPodcastDeleted(final Podcast podcast) {
    Log.v(TAG, String.format("onPodcastDeleted: %s", podcast.getTitle()));
    Activity activity = getActivity();
    if (activity == null) {
      return;
    }

    activity.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            model.removePodcast(podcast);
          }
        });
    updatePodcastList();
  }
Beispiel #18
0
 /** tests insert podcast functionality with trying to insert null on a non nullable column */
 public void testInsertNotNullableColumnShouldFail() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   p1.setUrl(null);
   Podcast pod = pdao.insertPodcast(p1);
   assertNull(pod);
 }
Beispiel #19
0
 @Override
 public void onPodcastChanged(Podcast podcast) {
   Log.v(TAG, String.format("onPodcastChanged: %s", podcast.getTitle()));
   updatePodcastList();
 }
Beispiel #20
0
 /** tests insert podcast functionality with inserting null on a nullable column */
 public void testInsertNullOnNullableColumn() {
   PodcastDAOImpl pdao = PodcastDAOImpl.i(this.mContext);
   p1.setLogoFilePath(null);
   Podcast pod = pdao.insertPodcast(p1);
   assertNotNull(pod);
 }