Package org.rssowl.core.model.reference

Examples of org.rssowl.core.model.reference.FeedReference


      IFeed feed = new Feed(new URL("inmemory://rss_2_0.xml")); //$NON-NLS-1$
      feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      FeedReference feedRef = new FeedReference(feed.getId());

      IBookMark bookmark = createBookMark(feed);

      final int addedCounter[] = new int[] { 0 };
      final int updatedCounter[] = new int[] { 0 };
      newsListener = new NewsListener() {
        public void newsAdded(Set<NewsEvent> events) {
          addedCounter[0] += events.size();
        }

        public void newsDeleted(Set<NewsEvent> events) {
          fail("Did not expect this Event");
        }

        public void newsUpdated(Set<NewsEvent> events) {
          updatedCounter[0] += events.size();
        }
      };
      NewsModel.getDefault().addNewsListener(newsListener);

      /* First Reload */
      InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", null, null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));
      assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());

      /* Set to Unread */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);

      /* Second Reload with updated Title */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link.de", null, null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fourth Reload with added News */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link_other.de", null, null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));

      List<INews> news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("http://www.link.de".equals(newsItem.getLink().toString()))
          assertEquals(INews.State.READ, newsItem.getState());
        else if ("http://www.link_other.de".equals(newsItem.getLink().toString()))
          assertEquals(INews.State.NEW, newsItem.getState());
      }

      /* Set to Read */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(1).getState());

      /* Test Event Counter */
      assertEquals(2, addedCounter[0]);
      assertEquals(4, updatedCounter[0]);
    } finally {
View Full Code Here


      IFeed feed = new Feed(new URL("inmemory://rss_2_0.xml")); //$NON-NLS-1$
      feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      FeedReference feedRef = new FeedReference(feed.getId());

      IBookMark bookmark = createBookMark(feed);

      final int addedCounter[] = new int[] { 0 };
      final int updatedCounter[] = new int[] { 0 };
      newsListener = new NewsListener() {
        public void newsAdded(Set<NewsEvent> events) {
          addedCounter[0] += events.size();
        }

        public void newsDeleted(Set<NewsEvent> events) {
          fail("Did not expect this Event");
        }

        public void newsUpdated(Set<NewsEvent> events) {
          updatedCounter[0] += events.size();
        }
      };
      NewsModel.getDefault().addNewsListener(newsListener);

      /* First Reload */
      InMemoryProtocolHandler.FEED = generateFeed("Title", null, "http://www.guid.de", null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));
      assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());

      /* Set to Unread */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);

      /* Second Reload with updated Title */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", null, "http://www.guid.de", null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fourth Reload with added News */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", null, "http://www.guid_other.de", null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));

      List<INews> news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("http://www.guid.de".equals(newsItem.getGuid().getValue()))
          assertEquals(INews.State.READ, newsItem.getState());
        else if ("http://www.guid_other.de".equals(newsItem.getGuid().getValue()))
          assertEquals(INews.State.NEW, newsItem.getState());
      }

      /* Set to Read */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(1).getState());

      /* Test Event Counter */
      assertEquals(2, addedCounter[0]);
      assertEquals(4, updatedCounter[0]);
    } finally {
View Full Code Here

      IFeed feed = new Feed(new URL("inmemory://rss_2_0.xml")); //$NON-NLS-1$
      feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      FeedReference feedRef = new FeedReference(feed.getId());

      IBookMark bookmark = createBookMark(feed);

      final int addedCounter[] = new int[] { 0 };
      final int updatedCounter[] = new int[] { 0 };
      newsListener = new NewsListener() {
        public void newsAdded(Set<NewsEvent> events) {
          addedCounter[0] += events.size();
        }

        public void newsDeleted(Set<NewsEvent> events) {
          fail("Did not expect this Event");
        }

        public void newsUpdated(Set<NewsEvent> events) {
          updatedCounter[0] += events.size();
        }
      };
      NewsModel.getDefault().addNewsListener(newsListener);

      long now = System.currentTimeMillis();

      String description = "Initial description";
      /* First Reload */
      InMemoryProtocolHandler.FEED = generateFeed("Title", null, null, fDateFormat.format(now), description);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));
      assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());

      /* Set to Unread */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);

      /* Second Reload with updated description */
      long ms = now + 100000;
      String updatedDescription = description + "updated";
      InMemoryProtocolHandler.FEED = generateFeed("Title", null, null, fDateFormat.format(new Date(ms)), updatedDescription);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UNREAD, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fourth Reload with added News */
      ms = System.currentTimeMillis() + 1000000;
      InMemoryProtocolHandler.FEED = generateFeed("Title Other", null, null, fDateFormat.format(ms));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));

      List<INews> news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("Title".equals(newsItem.getTitle()))
          assertEquals(INews.State.READ, newsItem.getState());
        else if ("Title Other".equals(newsItem.getTitle()))
          assertEquals(INews.State.NEW, newsItem.getState());
      }

      /* Set to Read */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(1).getState());

      /* Test Event Counter */
      assertEquals(2, addedCounter[0]);
      assertEquals(4, updatedCounter[0]);
    } finally {
View Full Code Here

      IFeed feed = new Feed(new URL("inmemory://rss_2_0.xml")); //$NON-NLS-1$
      feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      FeedReference feedRef = new FeedReference(feed.getId());

      IBookMark bookmark = createBookMark(feed);

      final int addedCounter[] = new int[] { 0 };
      final int updatedCounter[] = new int[] { 0 };
      newsListener = new NewsListener() {
        public void newsAdded(Set<NewsEvent> events) {
          addedCounter[0] += events.size();
        }

        public void newsDeleted(Set<NewsEvent> events) {
          fail("Did not expect this Event");
        }

        public void newsUpdated(Set<NewsEvent> events) {
          updatedCounter[0] += events.size();
        }
      };
      NewsModel.getDefault().addNewsListener(newsListener);

      long now = System.currentTimeMillis();

      /* First Reload */
      InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", null, fDateFormat.format(now));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));
      assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());

      /* Set to Unread */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);

      /* Second Reload with updated Title */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link.de", null, fDateFormat.format(now));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fourth Reload with updated Publish Date */
      long ms = now + 100000;
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link.de", null, fDateFormat.format(ms));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fifth Reload with updated Title and Publish Date */
      ms = now + 1000000;
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2*", "http://www.link.de", null, fDateFormat.format(ms));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Sixth Reload with added News */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2*", "http://www.link_other.de", null, fDateFormat.format(now));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));

      List<INews> news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("http://www.link.de".equals(newsItem.getLink().toString()))
          assertEquals(INews.State.READ, newsItem.getState());
        else if ("http://www.link_other.de".equals(newsItem.getLink().toString()))
          assertEquals(INews.State.NEW, newsItem.getState());
      }

      /* Set to Read */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(1).getState());

      /* Test Event Counter */
      assertEquals(2, addedCounter[0]);
      assertEquals(7, updatedCounter[0]);
    } finally {
View Full Code Here

      IFeed feed = new Feed(new URL("inmemory://rss_2_0.xml")); //$NON-NLS-1$
      feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      FeedReference feedRef = new FeedReference(feed.getId());

      IBookMark bookmark = createBookMark(feed);

      final int addedCounter[] = new int[] { 0 };
      final int updatedCounter[] = new int[] { 0 };
      newsListener = new NewsListener() {
        public void newsAdded(Set<NewsEvent> events) {
          addedCounter[0] += events.size();
        }

        public void newsDeleted(Set<NewsEvent> events) {
          fail("Did not expect this Event");
        }

        public void newsUpdated(Set<NewsEvent> events) {
          updatedCounter[0] += events.size();
        }
      };
      NewsModel.getDefault().addNewsListener(newsListener);

      long now = System.currentTimeMillis();

      /* First Reload */
      InMemoryProtocolHandler.FEED = generateFeed("Title", null, "http://www.guid.de", fDateFormat.format(now));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));
      assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());

      /* Set to Unread */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);

      /* Second Reload with updated Title */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", null, "http://www.guid.de", fDateFormat.format(now));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fourth Reload with updated Publish Date */
      long ms = now + 100000;
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", null, "http://www.guid.de", fDateFormat.format(ms));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fifth Reload with updated Title and Publish Date */
      ms = now + 1000000;
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2*", null, "http://www.guid.de", fDateFormat.format(ms));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Sixth Reload with added News */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2*", null, "http://www.guid_other.de", fDateFormat.format(now));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));

      List<INews> news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("http://www.guid.de".equals(newsItem.getGuid().getValue()))
          assertEquals(INews.State.READ, newsItem.getState());
        else if ("http://www.guid_other.de".equals(newsItem.getGuid().getValue()))
          assertEquals(INews.State.NEW, newsItem.getState());
      }

      /* Set to Read */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(1).getState());

      /* Test Event Counter */
      assertEquals(2, addedCounter[0]);
      assertEquals(7, updatedCounter[0]);
    } finally {
View Full Code Here

      IFeed feed = new Feed(new URL("inmemory://rss_2_0.xml")); //$NON-NLS-1$
      feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      FeedReference feedRef = new FeedReference(feed.getId());

      IBookMark bookmark = createBookMark(feed);

      final int addedCounter[] = new int[] { 0 };
      final int updatedCounter[] = new int[] { 0 };
      newsListener = new NewsListener() {
        public void newsAdded(Set<NewsEvent> events) {
          addedCounter[0] += events.size();
        }

        public void newsDeleted(Set<NewsEvent> events) {
          fail("Did not expect this Event");
        }

        public void newsUpdated(Set<NewsEvent> events) {
          updatedCounter[0] += events.size();
        }
      };
      NewsModel.getDefault().addNewsListener(newsListener);

      long now = System.currentTimeMillis();

      /* First Reload */
      InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", "http://www.guid.de", null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));
      assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());

      /* Set to Unread */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);

      /* Second Reload with updated Title */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link.de", "http://www.guid.de", null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fourth Reload with updated Link */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link_updated.de", "http://www.guid.de", null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fifth Reload with updated Title and Link */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2*", "http://www.link_updated_again.de", "http://www.guid.de", null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Sixth Reload with added News */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2*", "http://www.link_updated_again.de", "http://www.guid_other.de", null);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));

      List<INews> news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("http://www.guid.de".equals(newsItem.getGuid().getValue()))
          assertEquals(INews.State.READ, newsItem.getState());
        else if ("http://www.guid_other.de".equals(newsItem.getGuid().getValue()))
          assertEquals(INews.State.NEW, newsItem.getState());
      }

      /* Set to Read */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(1).getState());

      /* Test Event Counter */
      assertEquals(2, addedCounter[0]);
      assertEquals(7, updatedCounter[0]);
    } finally {
View Full Code Here

      IFeed feed = new Feed(new URL("inmemory://rss_2_0.xml")); //$NON-NLS-1$
      feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      FeedReference feedRef = new FeedReference(feed.getId());

      IBookMark bookmark = createBookMark(feed);

      final int addedCounter[] = new int[] { 0 };
      final int updatedCounter[] = new int[] { 0 };
      newsListener = new NewsListener() {
        public void newsAdded(Set<NewsEvent> events) {
          addedCounter[0] += events.size();
        }

        public void newsDeleted(Set<NewsEvent> events) {
          fail("Did not expect this Event");
        }

        public void newsUpdated(Set<NewsEvent> events) {
          updatedCounter[0] += events.size();
        }
      };
      NewsModel.getDefault().addNewsListener(newsListener);

      long now = System.currentTimeMillis();

      /* First Reload */
      InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", "http://www.guid.de", fDateFormat.format(now));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));
      assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());

      /* Set to Unread */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);

      /* Second Reload with updated Title */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link.de", "http://www.guid.de", fDateFormat.format(now));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fourth Reload with updated Link */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link_updated.de", "http://www.guid.de", fDateFormat.format(now));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Reload with updated description */
      String updatedDescription = "updatedDescription";
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated*", "http://www.link_updated.de", "http://www.guid.de", fDateFormat.format(now), updatedDescription);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Fifth Reload with updated Title and Link */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2*", "http://www.link_updated_again.de", "http://www.guid.de", fDateFormat.format(now), updatedDescription);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Reload with updated Title and Publish Date */
      long ms2 = now + 200000;
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2 #3*", "http://www.link_updated_again.de", "http://www.guid.de", fDateFormat.format(ms2), updatedDescription + " again");
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Reload with updated Title, Link and Publish Date */
      long ms3 = now + 500000;
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2 #3 #4*", "http://www.link_updated_again_again.de", "http://www.guid.de", fDateFormat.format(ms3));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.UPDATED, feedRef.resolve().getNews().get(0).getState());

      /* Set to Read and Reload */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());

      /* Sixth Reload with added News */
      InMemoryProtocolHandler.FEED = generateFeed("Title *updated #2 #3 #4*", "http://www.link_updated_again_again.de", "http://www.guid_other.de", fDateFormat.format(ms3));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));

      List<INews> news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("http://www.guid.de".equals(newsItem.getGuid().getValue()))
          assertEquals(INews.State.READ, newsItem.getState());
        else if ("http://www.guid_other.de".equals(newsItem.getGuid().getValue()))
          assertEquals(INews.State.NEW, newsItem.getState());
      }

      /* Set to Read */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.READ, true, false);
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(0).getState());
      assertEquals(INews.State.READ, feedRef.resolve().getNews().get(1).getState());

      /* Test Event Counter */
      assertEquals(2, addedCounter[0]);
      assertEquals(12, updatedCounter[0]);
    } finally {
View Full Code Here

      IFeed feed = new Feed(new URL("inmemory://rss_2_0.xml")); //$NON-NLS-1$
      feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      FeedReference feedRef = new FeedReference(feed.getId());

      IBookMark bookmark = createBookMark(feed);

      final int addedCounter[] = new int[] { 0 };
      final int updatedCounter[] = new int[] { 0 };
      final int removedCounter[] = new int[] { 0 };
      newsListener = new NewsListener() {
        public void newsAdded(Set<NewsEvent> events) {
          addedCounter[0] += events.size();
        }

        public void newsDeleted(Set<NewsEvent> events) {
          removedCounter[0] += events.size();
        }

        public void newsUpdated(Set<NewsEvent> events) {
          updatedCounter[0] += events.size();
        }
      };
      NewsModel.getDefault().addNewsListener(newsListener);

      /* First Reload */
      InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", null, fDateFormat.format(System.currentTimeMillis()));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));
      assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());

      /* Delete News (set to Hidden) */
      fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.HIDDEN, true, false);
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      /* Reload unchanged Feed */
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());
      assertEquals(0, getUnreadCount(feed));
      assertEquals(0, getNewCount(feed));

      /* Second Reload */
      InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link_other.de", null, fDateFormat.format(System.currentTimeMillis()));
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(2, feedRef.resolve().getNews().size());
      assertEquals(1, getUnreadCount(feed));
      assertEquals(1, getNewCount(feed));

      List<INews> news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("http://www.link.de".equals(newsItem.getLink().toString()))
          assertEquals(INews.State.HIDDEN, newsItem.getState());
        else if ("http://www.link_other.de".equals(newsItem.getLink().toString()))
          assertEquals(INews.State.NEW, newsItem.getState());
      }

      /* Really Delete News */
      news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("http://www.link.de".equals(newsItem.getLink().toString()))
          fApplicationLayer.setNewsState(new ArrayList<INews>(Arrays.asList(newsItem)), INews.State.DELETED, true, false);
      }

      news = feedRef.resolve().getNews();
      for (INews newsItem : news) {
        if ("http://www.link.de".equals(newsItem.getLink().toString()))
          assertEquals(INews.State.DELETED, newsItem.getState());
        else if ("http://www.link_other.de".equals(newsItem.getLink().toString()))
          assertEquals(INews.State.NEW, newsItem.getState());
      }

      /* Reload unchanged Feed */
      fController.reload(bookmark, null, new NullProgressMonitor());
      assertEquals(1, feedRef.resolve().getNews().size());

      /* Test Event Counter */
      assertEquals(2, addedCounter[0]);
      assertEquals(2, updatedCounter[0]);
      assertEquals(1, removedCounter[0]);
View Full Code Here

  public final void testEntityScope() throws Exception {
    IFolder folder = fDao.saveFolder(fFactory.createFolder(null, null, "Root"));
    IFeed feed = fFactory.createFeed(null, new URL("http://www.link.com"));
    feed = fDao.saveFeed(feed);
    fFactory.createBookMark(null, folder, feed.getLink(),
        new FeedReference(feed.getId()), "BookMark");
    folder = fDao.saveFolder(folder);

    IPreferencesScope entityScope = NewsModel.getDefault().getEntityScope(folder);

    /* Test Defaults Taken */
 
View Full Code Here

    try {
      IFolder folder = fDao.saveFolder(fFactory.createFolder(null, null, "Root"));
      IFeed feed = fFactory.createFeed(null, new URL("http://www.link.com"));
      feed = fDao.saveFeed(feed);
      fFactory.createBookMark(null, folder, feed.getLink(),
          new FeedReference(feed.getId()), "BookMark");
      folder = fDao.saveFolder(folder);

      final int eventsCounter[] = new int[] { 0 };
      bookmarkListener = new BookMarkAdapter() {
        @Override
View Full Code Here

TOP

Related Classes of org.rssowl.core.model.reference.FeedReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.