*/
@Test
public void testSetNewsStateOnPlanet() throws Exception {
NewsListener newsListener = null;
try {
NewsCounter newsCounter = DynamicDAO.getDAO(INewsCounterDAO.class).load();
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, newsCounter.getUnreadCount(news1.getFeedLinkAsText()));
assertEquals(2, newsCounter.getNewCount(news1.getFeedLinkAsText()));
assertEquals(2, newsCounter.getUnreadCount(news2.getFeedLinkAsText()));
assertEquals(2, newsCounter.getNewCount(news2.getFeedLinkAsText()));
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().longValue());
else if (news.getId() == news2ID)
assertEquals(feed2ID, parent.getId().longValue());
else
fail("Unexpected Reference in Event!");
}
}
};
DynamicDAO.addEntityListener(INews.class, newsListener);
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(Arrays.asList(new INews[] { new NewsReference(news1ID).resolve() }), INews.State.READ, true, false);
assertEquals(1, newsCounter.getUnreadCount(news1.getFeedLinkAsText()));
assertEquals(1, newsCounter.getNewCount(news1.getFeedLinkAsText()));
assertEquals(1, newsCounter.getUnreadCount(news2.getFeedLinkAsText()));
assertEquals(1, newsCounter.getNewCount(news2.getFeedLinkAsText()));
} finally {
if (newsListener != null)
DynamicDAO.removeEntityListener(INews.class, newsListener);
}
}