FeedListener feedListener = null;
NewsListener newsListener = null;
AttachmentListener attachmentListener = null;
PersonListener personListener = null;
CategoryListener categoryListener = null;
NewsAdapter newsAdapter = null;
try {
/* Check Feed Deleted and News Deleted */
final IFeed feed = fFactory.createFeed(null, new URL("http://www.foobar.com"));
final IPerson person1 = fFactory.createPerson(null, feed);
person1.setName("Person1");
final FeedReference feedRef = new FeedReference(fDao.saveFeed(feed).getId());
final PersonReference personRef1 = new PersonReference(feedRef.resolve().getAuthor().getId());
final boolean feedDeleted[] = new boolean[1];
final boolean newsDeletedFromFeed[] = new boolean[1];
feedListener = new FeedAdapter() {
@Override
public void feedDeleted(Set<FeedEvent> events) {
for (FeedEvent event : events) {
assertFalse("Already received feedDeleted Event", feedDeleted[0]);
assertTrue("Expected this Event to be Root Event", event.isRoot());
if (feedRef.references(event.getEntity()))
feedDeleted[0] = true;
}
}
};
fModel.addFeedListener(feedListener);
/* Check News Deleted */
final INews news1 = fFactory.createNews(null, feedRef.resolve(), new Date());
news1.setTitle("News1 Title");
news1.setLink(new URI("http://www.news.com/news1.html"));
final IPerson person2 = fFactory.createPerson(null, news1);
person2.setName("Person2");
fFactory.createSource(news1).setUrl(new URI("http://www.source1.com"));
fFactory.createGuid(news1, "Guid1");
final NewsReference[] newsRef = new NewsReference[1];
newsAdapter = new NewsAdapter() {
@Override
public void newsAdded(Set<NewsEvent> events) {
assertEquals(1, events.size());
newsRef[0] = new NewsReference(events.iterator().next().getEntity().getId());
}
};
fModel.addNewsListener(newsAdapter);
/* Must save parent because it gets changed during creation of news */
fDao.saveFeed(feedRef.resolve());
final NewsReference newsRef1 = newsRef[0];
final PersonReference personRef2 = new PersonReference(newsRef1.resolve().getAuthor().getId());
final INews news2 = fFactory.createNews(null, feedRef.resolve(), new Date());
news2.setTitle("News2 Title");
news2.setLink(new URI("http://www.news.com/news2.html"));
fFactory.createSource(news2).setUrl(new URI("http://www.source2.com"));
fFactory.createGuid(news2, "Guid2");
/* Must save parent because it gets changed during creation of news */
fDao.saveFeed(feedRef.resolve());
final NewsReference newsRef2 = newsRef[0];
final INews news3 = fFactory.createNews(null, feedRef.resolve(), new Date());
news3.setTitle("News3 Title");
news3.setLink(new URI("http://www.news.com/news3.html"));
fFactory.createSource(news3).setUrl(new URI("http://www.source3.com"));
fFactory.createGuid(news3, "Guid3");
/* Must save parent because it gets changed during creation of news */
fDao.saveFeed(feedRef.resolve());
final NewsReference newsRef3 = newsRef[0];
final boolean newsDeleted[] = new boolean[3];
newsListener = new NewsAdapter() {
@Override
public void newsDeleted(Set<NewsEvent> events) {
for (NewsEvent event : events) {
assertFalse("Expected this Event to be no Root Event", event.isRoot());