final IAttachment attachment0 = fFactory.createAttachment(null, news);
attachment0.setUrl(new URI("http://www.attachment1.com"));
final IAttachment attachment1 = fFactory.createAttachment(null, news);
attachment1.setUrl(new URI("http://www.attachment1.com"));
fDao.saveFeed(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 newsDeleted(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 URL("http://www.foobar.com").toString(),
event.getEntity().getFeedReference().getLink().toString());
} catch (MalformedURLException e) {
fail(e.getMessage());
}
}
}
public void newsUpdated(Set<NewsEvent> events) {
fail("Unexpected event");
}
public void newsAdded(Set<NewsEvent> events) {
fail("Unexpected event");
}
};
fModel.addNewsListener(newsListener);
/* Check Attachments Added */
final boolean attachmentDeleted[] = new boolean[2];
attachmentListener = new AttachmentAdapter() {
@Override
public void attachmentDeleted(Set<AttachmentEvent> events) {
for (AttachmentEvent event : events) {
assertFalse("Expected this Event to be no Root Event", event.isRoot());
IAttachment attachment = event.getEntity();
if (attachment.getUrl().equals(attachment0.getUrl()))
attachmentDeleted[0] = true;
if (attachment.getUrl().equals(attachment1.getUrl()))
attachmentDeleted[1] = true;
}
}
};
fModel.addAttachmentListener(attachmentListener);
fDao.deleteFeed(new FeedReference(feed.getId()));
assertNull(fDao.loadFeed(feed.getId()));
assertNull(fDao.loadNews(newsRef.getId()));
assertNull(fDao.loadAttachment(attachmentRef0.getId()));
assertNull(fDao.loadAttachment(attachmentRef1.getId()));
assertTrue("Missed newsDeleted Event in NewsListener!", newsDeleted[0]);
assertTrue("Missed attachmentDeleted Event in PersonListener!", attachmentDeleted[0]);