FeedReference feedReference = new FeedReference(DynamicDAO.save(feed).getId());
/* Check News Added */
final INews news = fFactory.createNews(null, feedReference.resolve(), new Date());
news.setTitle("News Title");
final IAttachment attachment0 = fFactory.createAttachment(null, news);
attachment0.setLink(new URI("http://www.attachment1.com"));
final IAttachment attachment1 = fFactory.createAttachment(null, news);
attachment1.setLink(new URI("http://www.attachment1.com"));
DynamicDAO.save(feed);
NewsReference newsRef = new NewsReference(feed.getNews().get(0).getId());
AttachmentReference attachmentRef0 = new AttachmentReference(news.getAttachments().get(0).getId());
AttachmentReference attachmentRef1 = new AttachmentReference(news.getAttachments().get(1).getId());
final boolean[] newsDeleted = new boolean[1];
newsListener = new NewsListener() {
public void entitiesDeleted(Set<NewsEvent> events) {
for (NewsEvent event : events) {
assertFalse("Expected this Event to be no Root Event", event.isRoot());
if (event.getEntity().getTitle().equals(news.getTitle()))
newsDeleted[0] = true;
try {
assertEquals(new URI("http://www.foobar.com").toString(), event.getEntity().getFeedReference().getLink().toString());
} catch (URISyntaxException e) {
fail(e.getMessage());
}
}
}
public void entitiesUpdated(Set<NewsEvent> events) {
fail("Unexpected event");
}
public void entitiesAdded(Set<NewsEvent> events) {
fail("Unexpected event");
}
};
DynamicDAO.addEntityListener(INews.class, newsListener);
/* Check Attachments Added */
final boolean attachmentDeleted[] = new boolean[2];
attachmentListener = new AttachmentAdapter() {
@Override
public void entitiesDeleted(Set<AttachmentEvent> events) {
for (AttachmentEvent event : events) {
assertFalse("Expected this Event to be no Root Event", event.isRoot());
IAttachment attachment = event.getEntity();
if (attachment.getLink().equals(attachment0.getLink()))
attachmentDeleted[0] = true;
if (attachment.getLink().equals(attachment1.getLink()))
attachmentDeleted[1] = true;
}
}
};
DynamicDAO.addEntityListener(IAttachment.class, attachmentListener);