fFactory.createAttachment(null, news);
fFactory.createAttachment(null, news);
fFactory.createAttachment(null, news);
/* Save News */
final NewsReference newsRef = new NewsReference(DynamicDAO.save(news).getId());
final PersonReference personRef = new PersonReference(DynamicDAO.load(INews.class, newsRef.getId()).getAuthor().getId());
final AttachmentReference attachmentRef1 = new AttachmentReference(DynamicDAO.load(INews.class, newsRef.getId()).getAttachments().get(0).getId());
final AttachmentReference attachmentRef2 = new AttachmentReference(DynamicDAO.load(INews.class, newsRef.getId()).getAttachments().get(1).getId());
final AttachmentReference attachmentRef3 = new AttachmentReference(DynamicDAO.load(INews.class, newsRef.getId()).getAttachments().get(2).getId());
final CategoryReference categoryRef = new CategoryReference(DynamicDAO.load(INews.class, newsRef.getId()).getCategories().get(0).getId());
/* Check News Deleted */
final boolean newsDeleted[] = new boolean[1];
newsListener = new NewsAdapter() {
@Override
public void entitiesDeleted(Set<NewsEvent> events) {
for (NewsEvent event : events) {
assertTrue("Expected this Event to be Root Event", event.isRoot());
if (newsRef.references(event.getEntity()))
newsDeleted[0] = true;
try {
assertEquals(new URI("http://www.foobar.com").toString(), event.getEntity().getFeedReference().getLink().toString());
} catch (URISyntaxException e) {
fail(e.getMessage());
}
}
}
};
DynamicDAO.addEntityListener(INews.class, newsListener);
/* Check Author Deleted */
final boolean personDeleted[] = new boolean[1];
personListener = new PersonAdapter() {
@Override
public void entitiesDeleted(Set<PersonEvent> events) {
for (PersonEvent event : events) {
assertFalse("Expected this Event to be no Root Event", event.isRoot());
if (personRef.references(event.getEntity()))
personDeleted[0] = true;
}
}
};
DynamicDAO.addEntityListener(IPerson.class, personListener);
/* Check Attachments Deleted */
final boolean attachmentDeleted[] = new boolean[3];
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 (attachmentRef1.references(attachment))
attachmentDeleted[0] = true;
else if (attachmentRef2.references(attachment))
attachmentDeleted[1] = true;
else if (attachmentRef3.references(attachment))
attachmentDeleted[2] = true;
}
}
};
DynamicDAO.addEntityListener(IAttachment.class, attachmentListener);
/* Check Category Deleted */
final boolean categoryDeleted[] = new boolean[1];
categoryListener = new CategoryAdapter() {
@Override
public void entitiesDeleted(Set<CategoryEvent> events) {
for (CategoryEvent event : events) {
assertFalse("Expected this Event to be no Root Event", event.isRoot());
if (categoryRef.references(event.getEntity()))
categoryDeleted[0] = true;
}
}
};
DynamicDAO.addEntityListener(ICategory.class, categoryListener);
/* Delete News */
DynamicDAO.delete(newsRef.resolve());
/* Asserts Follow */
assertTrue("Missed newsDeleted Event in NewsListener!", newsDeleted[0]);
assertTrue("Missed personDeleted Event in PersonListener!", personDeleted[0]);
assertTrue("Missed categoryDeleted Event in CategoryListener!", categoryDeleted[0]);