Package org.rssowl.core.persist

Examples of org.rssowl.core.persist.INews


   * @throws Exception
   */
  @Test
  public void testSaveNews() throws Exception {
    IFeed feed1 = new Feed(new URI("http://www.feed1.com"));
    INews news11 = fFactory.createNews(null, feed1, new Date());
    news11.setLink(new URI("http://www.link11.com"));
    INews news12 = fFactory.createNews(null, feed1, new Date());
    news12.setLink(new URI("http://www.link12.com"));
    feed1 = DynamicDAO.save(feed1);

    IFeed feed2 = new Feed(new URI("http://www.feed2.com"));
    INews news21 = fFactory.createNews(null, feed2, new Date());
    news21.setLink(new URI("http://www.link21.com"));
    INews news22 = fFactory.createNews(null, feed2, new Date());
    news22.setLink(new URI("http://www.link22.com"));
    feed2 = DynamicDAO.save(feed2);

    final List<INews> newsList = new ArrayList<INews>();

    for (INews news : feed1.getNews())
View Full Code Here


   */
 
  @Test
  public void testLoadAllNewsByFeedAndState() throws Exception {
    IFeed feed = fFactory.createFeed(null, new URI("http://www.feed.com"));
    INews news = fFactory.createNews(null, feed, new Date());
    FeedLinkReference feedRef = news.getFeedReference();
    news.setState(INews.State.HIDDEN);
    fFactory.createNews(null, feed, new Date()).setState(INews.State.UNREAD);
    fFactory.createNews(null, feed, new Date()).setState(INews.State.UPDATED);
    DynamicDAO.save(feed);
   
    IFeed anotherFeed = fFactory.createFeed(null, new URI("http://www.anotherfeed.com"));
    INews anotherNews = fFactory.createNews(null, anotherFeed, new Date());
    FeedLinkReference anotherFeedRef = anotherNews.getFeedReference();
    fFactory.createNews(null, anotherFeed, new Date());
    fFactory.createNews(null, anotherFeed, new Date()).setState(INews.State.DELETED);
    DynamicDAO.save(anotherFeed);

    INewsDAO newsDao = DynamicDAO.getDAO(INewsDAO.class);
View Full Code Here

      NewsService service = Controller.getDefault().getNewsService();

      IFeed feed1 = fFactory.createFeed(null, new URI("http://www.feed.com"));
      IFeed feed2 = fFactory.createFeed(null, new URI("http://www.feed2.com"));

      INews news1 = fFactory.createNews(null, feed1, new Date());
      news1.setLink(new URI("www.link.com"));

      INews news2 = fFactory.createNews(null, feed2, new Date());
      news2.setLink(new URI("www.link.com"));

      fFactory.createNews(null, feed1, new Date());
      fFactory.createNews(null, feed2, new Date());

      feed1 = DynamicDAO.save(feed1);
      feed2 = DynamicDAO.save(feed2);

      assertEquals(2, service.getUnreadCount(news1.getFeedReference()));
      assertEquals(2, service.getNewCount(news1.getFeedReference()));
      assertEquals(2, service.getUnreadCount(news2.getFeedReference()));
      assertEquals(2, service.getNewCount(news2.getFeedReference()));

      final long feed1ID = feed1.getId();
      final long feed2ID = feed2.getId();
      final long news1ID = feed1.getNews().get(0).getId();
      final long news2ID = feed2.getNews().get(0).getId();

      newsListener = new NewsListener() {
        public void entitiesAdded(Set<NewsEvent> events) {
          fail("Unexpected Event!");
        }

        public void entitiesDeleted(Set<NewsEvent> events) {
          fail("Unexpected Event!");
        }

        public void entitiesUpdated(Set<NewsEvent> events) {
          assertEquals(2, events.size());
          for (NewsEvent event : events) {
            INews news = event.getEntity();
            IFeed parent = news.getFeedReference().resolve();

            if (news.getId() == news1ID)
              assertEquals(feed1ID, parent.getId());
            else if (news.getId() == news2ID)
              assertEquals(feed2ID, parent.getId());
            else
              fail("Unexpected Reference in Event!");
          }
        }
View Full Code Here

  private List<INews> getNewNewsAdded(IFeed feed) {
    List<INews> newsList = feed.getNewsByStates(EnumSet.of(INews.State.NEW));

    for (ListIterator<INews> it = newsList.listIterator(newsList.size()); it.hasPrevious();) {
      INews news = it.previous();
      /*
       * Relies on the fact that news added during merge have no id assigned
       * yet.
       */
      if (news.getId() != null)
        it.remove();
    }
    return newsList;
  }
View Full Code Here

        return;

      List<NewsReference> equivalentNewsRefs = guidToNewsRefs.get(newsItem.getGuid());
      if (equivalentNewsRefs != null && !equivalentNewsRefs.isEmpty()) {
        NewsReference newsRef = equivalentNewsRefs.get(0);
        INews resolvedNews = newsRef.resolve();
        if (resolvedNews != null)
          newsItem.setState(resolvedNews.getState());
        else
          logWarning(NLS.bind(Messages.ApplicationServiceImpl_ERROR_STALE_LUCENE_INDEX, newsRef.getId()));
      } else {
        equivalentNewsRefs = linkToNewsRefs.get(newsItem.getLink());
        if (equivalentNewsRefs != null && !equivalentNewsRefs.isEmpty()) {
          NewsReference newsRef = equivalentNewsRefs.get(0);
          INews resolvedNews = newsRef.resolve();
          if (resolvedNews != null)
            newsItem.setState(resolvedNews.getState());
          else
            logWarning(NLS.bind(Messages.ApplicationServiceImpl_ERROR_STALE_LUCENE_INDEX, newsRef.getId()));
        }
      }
    }
View Full Code Here

    }

    INewsDAO newsDao = DynamicDAO.getDAO(INewsDAO.class);
    for (int i = 0, c = descriptionUpdatedIds.size(); i < c; ++i) {
      long newsId = descriptionUpdatedIds.get(i);
      INews news = newsDao.load(newsId);
      INews oldNews = DBHelper.peekPersistedNews(fDb, news);
      EventsMap.getInstance().putUpdateEvent(new NewsEvent(oldNews, news, false));
    }
  }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testNewsWithCategoriesMerge() throws Exception {
    IFeed feed = fFactory.createFeed(null, new URI("http://www.feed.com"));
    INews news = fFactory.createNews(null, feed, new Date());
    news.setLink(new URI("http://news.com"));
    fFactory.createCategory(null, news);
    INews anotherNews = fFactory.createNews(null, feed, new Date());
    anotherNews.setLink(new URI("http://anothernews.com"));
    fFactory.createCategory(null, anotherNews);
    ICategory category = fFactory.createCategory(null, anotherNews);
    category.setName("name");
    news.merge(anotherNews);
  }
View Full Code Here

  @Test
  public void testSaveFeedSetsCurrentAndOldStateInNews() throws Exception {
    IFeed feed = new Feed(new URI("http://www.feed.com"));
    feed = DynamicDAO.save(feed);

    INews news = fFactory.createNews(null, feed, new Date());
    news.setTitle("News Title #1");
    news.setLink(new URI("http://www.link.com"));
    news.setState(INews.State.UNREAD);

    feed = DynamicDAO.save(feed);

    final INews savedNews = feed.getNews().get(0);
    savedNews.setTitle("News Title Updated #1");

    NewsListener newsListener = new NewsAdapter() {
      @Override
      public void entitiesUpdated(Set<NewsEvent> events) {
        assertEquals(1, events.size());
        NewsEvent event = events.iterator().next();
        assertEquals(true, event.getEntity().equals(savedNews));
        assertEquals(State.UNREAD, event.getOldNews().getState());
        assertEquals(State.UNREAD, event.getEntity().getState());
      }
    };
    DynamicDAO.addEntityListener(INews.class, newsListener);
    try {
      feed = DynamicDAO.save(feed);
    } finally {
      DynamicDAO.removeEntityListener(INews.class, newsListener);
    }
    newsListener = new NewsAdapter() {
      @Override
      public void entitiesUpdated(Set<NewsEvent> events) {
        assertEquals(1, events.size());
        NewsEvent event = events.iterator().next();
        assertEquals(savedNews.getId(), event.getEntity().getId());
        assertEquals(State.UNREAD, event.getOldNews().getState());
        assertEquals(State.UPDATED, event.getEntity().getState());
      }
    };
    DynamicDAO.addEntityListener(INews.class, newsListener);
View Full Code Here

  @Test
  public void testSaveNewsSetsCurrentAndOldState() throws Exception {
    IFeed feed = fFactory.createFeed(null, new URI("http://www.feed.com"));
    feed = DynamicDAO.save(feed);

    INews news = fFactory.createNews(null, feed, new Date());
    news.setTitle("News Title #1");
    news.setLink(new URI("http://www.link.com"));
    news.setState(INews.State.UNREAD);

    feed = DynamicDAO.save(feed);

    INews savedNews = feed.getNews().get(0);
    final Long savedNewsId = savedNews.getId();
    savedNews.setTitle("News Title Updated #1");

    NewsListener newsListener = new NewsAdapter() {
      @Override
      public void entitiesUpdated(Set<NewsEvent> events) {
        assertEquals(1, events.size());
        NewsEvent event = events.iterator().next();
        assertEquals(savedNewsId, event.getEntity().getId());
        assertEquals(State.UNREAD, event.getOldNews().getState());
        assertEquals(State.UNREAD, event.getEntity().getState());
      }
    };
    DynamicDAO.addEntityListener(INews.class, newsListener);
    try {
      savedNews = DynamicDAO.save(savedNews);
    } finally {
      DynamicDAO.removeEntityListener(INews.class, newsListener);
    }
    newsListener = new NewsAdapter() {
      @Override
      public void entitiesUpdated(Set<NewsEvent> events) {
        assertEquals(1, events.size());
        NewsEvent event = events.iterator().next();
        assertEquals(savedNewsId, event.getEntity().getId());
        assertEquals(State.UNREAD, event.getOldNews().getState());
        assertEquals(State.UPDATED, event.getEntity().getState());
      }
    };
    DynamicDAO.addEntityListener(INews.class, newsListener);
    savedNews.setState(State.UPDATED);
    try {
      DynamicDAO.save(savedNews);
    } finally {
      DynamicDAO.removeEntityListener(INews.class, newsListener);
    }
View Full Code Here

    feed = DynamicDAO.save(feed);

    int newNewsCount = 4;
    List<INews> newNews = new ArrayList<INews>();
    for (int i = 0; i < newNewsCount; ++i) {
      INews news = fFactory.createNews(null, feed, new Date());
      news.setTitle("new News: " + i);
      news.setState(State.NEW);
      newNews.add(news);
    }

    int readNewsCount = 2;
    List<INews> readNews = new ArrayList<INews>();
    for (int i = 0; i < readNewsCount; ++i) {
      INews news = fFactory.createNews(null, feed, new Date());
      news.setTitle("read News: " + i);
      news.setState(State.READ);
      readNews.add(news);
    }

    int unreadNewsCount = 3;
    List<INews> unreadNews = new ArrayList<INews>();
    for (int i = 0; i < unreadNewsCount; ++i) {
      INews news = fFactory.createNews(null, feed, new Date());
      news.setTitle("unread News: " + i);
      news.setState(State.UNREAD);
      unreadNews.add(news);
    }

    int updatedNewsCount = 6;
    List<INews> updatedNews = new ArrayList<INews>();
    for (int i = 0; i < updatedNewsCount; ++i) {
      INews news = fFactory.createNews(null, feed, new Date());
      news.setTitle("updated News: " + i);
      news.setState(State.UPDATED);
      updatedNews.add(news);
    }

    int hiddenNewsCount = 8;
    List<INews> hiddenNews = new ArrayList<INews>();
    for (int i = 0; i < hiddenNewsCount; ++i) {
      INews news = fFactory.createNews(null, feed, new Date());
      news.setTitle("hidden News: " + i);
      news.setState(State.HIDDEN);
      hiddenNews.add(news);
    }

    int deletedNewsCount = 7;
    List<INews> deletedNews = new ArrayList<INews>();
    for (int i = 0; i < deletedNewsCount; ++i) {
      INews news = fFactory.createNews(null, feed, new Date());
      news.setTitle("deleted News: " + i);
      news.setState(State.DELETED);
      deletedNews.add(news);
    }

    assertEquals(newNewsCount, feed.getNewsByStates(EnumSet.of(State.NEW)).size());
    int counter = 0;
    for (INews news : feed.getNewsByStates(EnumSet.of(State.NEW))) {
      INews newsItem = newNews.get(counter++);
      assertEquals(newsItem.getTitle(), news.getTitle());
    }

    assertEquals(readNewsCount, feed.getNewsByStates(EnumSet.of(State.READ)).size());
    counter = 0;
    for (INews news : feed.getNewsByStates(EnumSet.of(State.READ))) {
      INews newsItem = readNews.get(counter++);
      assertEquals(newsItem.getTitle(), news.getTitle());
    }

    assertEquals(unreadNewsCount, feed.getNewsByStates(EnumSet.of(State.UNREAD)).size());
    counter = 0;
    for (INews news : feed.getNewsByStates(EnumSet.of(State.UNREAD))) {
      INews newsItem = unreadNews.get(counter++);
      assertEquals(newsItem.getTitle(), news.getTitle());
    }

    assertEquals(updatedNewsCount, feed.getNewsByStates(EnumSet.of(State.UPDATED)).size());
    counter = 0;
    for (INews news : feed.getNewsByStates(EnumSet.of(State.UPDATED))) {
      INews newsItem = updatedNews.get(counter++);
      assertEquals(newsItem.getTitle(), news.getTitle());
    }

    assertEquals(hiddenNewsCount, feed.getNewsByStates(EnumSet.of(State.HIDDEN)).size());
    counter = 0;
    for (INews news : feed.getNewsByStates(EnumSet.of(State.HIDDEN))) {
      INews newsItem = hiddenNews.get(counter++);
      assertEquals(newsItem.getTitle(), news.getTitle());
    }

    assertEquals(deletedNewsCount, feed.getNewsByStates(EnumSet.of(State.DELETED)).size());
    counter = 0;
    for (INews news : feed.getNewsByStates(EnumSet.of(State.DELETED))) {
      INews newsItem = deletedNews.get(counter++);
      assertEquals(newsItem.getTitle(), news.getTitle());
    }

    int visibleNewsCount = newNewsCount + readNewsCount + unreadNewsCount + updatedNewsCount;
    assertEquals(visibleNewsCount, feed.getVisibleNews().size());

    for (INews news : feed.getVisibleNews()) {
      boolean matchFound = false;
      for (INews newsItem : newNews) {
        if (news.getTitle().equals(newsItem.getTitle())) {
          matchFound = true;
          break;
        }
      }
      if (matchFound)
        continue;

      for (INews newsItem : readNews) {
        if (news.getTitle().equals(newsItem.getTitle())) {
          matchFound = true;
          break;
        }
      }
      if (matchFound)
        continue;

      for (INews newsItem : unreadNews) {
        if (news.getTitle().equals(newsItem.getTitle())) {
          matchFound = true;
          break;
        }
      }
      if (matchFound)
        continue;

      for (INews newsItem : updatedNews) {
        if (news.getTitle().equals(newsItem.getTitle())) {
          matchFound = true;
          break;
        }
      }
      if (matchFound)
        continue;
      fail("No match was found. A news that had the wrong state was returned");
    }

    for (INews news : feed.getNewsByStates(EnumSet.of(State.NEW, State.HIDDEN, State.DELETED))) {
      boolean matchFound = false;
      for (INews newsItem : newNews) {
        if (news.getTitle().equals(newsItem.getTitle())) {
          matchFound = true;
          break;
        }
      }
      if (matchFound)
        continue;

      for (INews newsItem : hiddenNews) {
        if (news.getTitle().equals(newsItem.getTitle())) {
          matchFound = true;
          break;
        }
      }
      if (matchFound)
        continue;

      for (INews newsItem : deletedNews) {
        if (news.getTitle().equals(newsItem.getTitle())) {
          matchFound = true;
          break;
        }
      }
      if (matchFound)
View Full Code Here

TOP

Related Classes of org.rssowl.core.persist.INews

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.