*
* @throws Exception
*/
@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);
feed.getNews().get(0).setState(State.UPDATED);
try {
feed = DynamicDAO.save(feed);
} finally {
DynamicDAO.removeEntityListener(INews.class, newsListener);
}