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());
assertNull(oldAttachment.getNews());
}
};
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());
assertEquals(State.UNREAD, event.getOldNews().getState());
assertEquals(State.UPDATED, event.getEntity().getState());
}
};
DynamicDAO.addEntityListener(INews.class, newsListener);
newsList.iterator().next().setState(State.UPDATED);
try {