savedNews.setTitle("News Title Updated #1");
Collection<INews> newsList = new ArrayList<INews>();
newsList.add(savedNews);
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));
INews oldNews = event.getOldNews();
assertEquals(State.UNREAD, oldNews.getState());
assertEquals(State.UNREAD, event.getEntity().getState());
assertEquals(category.getName(), oldNews.getCategories().get(0).getName());
IAttachment oldAttachment = oldNews.getAttachments().get(0);
assertEquals(attachment.getLink(), oldAttachment.getLink());
assertEquals(oldNews.getId(), oldAttachment.getNews().getId());
}
};
DynamicDAO.addEntityListener(INews.class, newsListener);
try {
DynamicDAO.saveAll(newsList);
} 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().longValue(), event.getEntity().getId().longValue());