news.setState(INews.State.UNREAD);
final ICategory category = fFactory.createCategory(null, news);
category.setName("Category name");
final IAttachment attachment = fFactory.createAttachment(null, news);
attachment.setLink(new URI("http://attachment.com"));
feed = DynamicDAO.save(feed);
final INews savedNews = feed.getNews().get(0);
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);