feed = DynamicDAO.save(createFeed());
} catch (PersistenceException e) {
fail(e.getMessage());
return;
}
final News initialNews = (News) createNews(feed);
final Feed[] initialFeed = new Feed[1];
final Person[] initialAuthor = new Person[1];
final Source[] initialSource = new Source[1];
final Guid[] initialGuid = new Guid[1];
final News[] updatedNews = new News[1];
final boolean[] NewsAddedCalled = new boolean[] { false };
final boolean[] NewsUpdatedCalled = new boolean[] { false };
NewsListener newsListener = null;
try {
newsListener = new NewsAdapter() {
@Override
public void entitiesAdded(Set<NewsEvent> events) {
NewsEvent event = events.iterator().next();
try {
NewsAddedCalled[0] = true;
initialFeed[0] = (Feed) initialNews.getFeedReference().resolve();
initialAuthor[0] = (Person) initialNews.getAuthor();
initialSource[0] = (Source) initialNews.getSource();
initialGuid[0] = (Guid) initialNews.getGuid();
News dbNews = (News) event.getEntity();
initialAuthor[0].setId(dbNews.getAuthor().getId());
initialAuthor[0].isIdentical(dbNews.getAuthor());
initialNews.setId(dbNews.getId());
assertTrue(initialNews.isIdentical(dbNews));
dbNews.setDescription("The description has been changed in the news");
dbNews.setState(State.UNREAD);
updatedNews[0] = dbNews;
DynamicDAO.save(dbNews);
} catch (PersistenceException e) {
fail(e.getMessage());
}
}
@Override
public void entitiesUpdated(Set<NewsEvent> events) {
NewsEvent event = events.iterator().next();
NewsUpdatedCalled[0] = true;
News dbNews = (News) event.getEntity();
assertTrue(updatedNews[0].isIdentical(dbNews));
}
};
DynamicDAO.addEntityListener(INews.class, newsListener);
DynamicDAO.save(initialNews);