fFactory.createNews(null, feed, new Date());
Feed savedFeed = (Feed) DynamicDAO.save(feed);
assertTrue(savedFeed.isIdentical(DynamicDAO.load(IFeed.class, savedFeed.getId())));
NewsReference news1 = new NewsReference(savedFeed.getNews().get(0).getId());
NewsReference news2 = new NewsReference(savedFeed.getNews().get(1).getId());
NewsReference news3 = new NewsReference(savedFeed.getNews().get(2).getId());
List<INews> news = new ArrayList<INews>();
news.add(news1.resolve());
news.add(news2.resolve());
assertEquals(news1.resolve().getState(), INews.State.NEW);
assertEquals(news2.resolve().getState(), INews.State.NEW);
assertEquals(news3.resolve().getState(), INews.State.NEW);
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)
assertEquals(true, event.isRoot());
}
};
DynamicDAO.addEntityListener(INews.class, newsListener);
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(news, INews.State.UNREAD, true, false);
assertEquals(news1.resolve().getState(), INews.State.UNREAD);
assertEquals(news2.resolve().getState(), INews.State.UNREAD);
assertEquals(news3.resolve().getState(), INews.State.NEW);
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(news, INews.State.READ, true, false);
assertEquals(news1.resolve().getState(), INews.State.READ);
assertEquals(news2.resolve().getState(), INews.State.READ);
assertEquals(news3.resolve().getState(), INews.State.NEW);
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(news, INews.State.DELETED, true, false);
assertEquals(news1.resolve().getState(), INews.State.DELETED);
assertEquals(news2.resolve().getState(), INews.State.DELETED);
assertEquals(news3.resolve().getState(), INews.State.NEW);
} finally {
if (newsListener != null)
DynamicDAO.removeEntityListener(INews.class, newsListener);
}
}