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);
DynamicDAO.delete(feed);
assertNull(DynamicDAO.load(IFeed.class, feed.getId()));
assertNull(DynamicDAO.load(INews.class, newsRef.getId()));
assertNull(DynamicDAO.load(IAttachment.class, attachmentRef0.getId()));
assertNull(DynamicDAO.load(IAttachment.class, attachmentRef1.getId()));
assertTrue("Missed newsDeleted Event in NewsListener!", newsDeleted[0]);
assertTrue("Missed attachmentDeleted Event in PersonListener!", attachmentDeleted[0]);
assertTrue("Missed attachmentDeleted Event in PersonListener!", attachmentDeleted[1]);
} finally {