final URI news2Link = new URI("http://www.news2.com/index.html");
final URI news3Link = new URI("http://www.news3.com/index.html");
news1.setLink(news1Link);
news2.setLink(news2Link);
news3.setLink(news3Link);
FeedReference feedRef = new FeedReference(fDao.saveFeed(feed).getId());
assertEquals(3, fDao.loadFeed(feedRef.getId()).getNews().size());
/* Mark 2 News as Deleted and save News */
news1 = fDao.loadFeed(feedRef.getId()).getNews().get(0);
news1.setState(INews.State.DELETED);
news2 = fDao.loadFeed(feedRef.getId()).getNews().get(1);
news2.setState(INews.State.DELETED);
news3 = fDao.loadFeed(feedRef.getId()).getNews().get(2);
news3.setState(INews.State.READ);
final boolean newsUpdatedEvents[] = new boolean[2];
newsListener = new NewsAdapter() {
@Override
public void newsUpdated(Set<NewsEvent> events) {
for (NewsEvent event : events) {
INews news = event.getEntity();
if (news.getLink().equals(news1Link))
newsUpdatedEvents[0] = true;
else if (news.getLink().equals(news2Link))
newsUpdatedEvents[1] = true;
}
}
};
fModel.addNewsListener(newsListener);
NewsReference newsReference1 = new NewsReference(fDao.saveNews(news1).getId());
NewsReference newsReference2 = new NewsReference(fDao.saveNews(news2).getId());
NewsReference newsReference3 = new NewsReference(fDao.saveNews(news3).getId());
assertEquals(INews.State.DELETED, fDao.loadFeed(feedRef.getId()).getNews().get(0).getState());
assertEquals(INews.State.DELETED, fDao.loadFeed(feedRef.getId()).getNews().get(1).getState());
assertEquals(INews.State.READ, fDao.loadFeed(feedRef.getId()).getNews().get(2).getState());
/* Check Deleted News now being Deleted from DB */
feed = fFactory.createFeed(null, new URL("http://www.feed.com"));
List<INews> removedNews = feedRef.resolve().mergeAndCleanUp(feed);
fAppLayer.saveFeed(feed, removedNews);
/* Asserts follow */
assertEquals(1, fDao.loadFeed(feedRef.getId()).getNews().size());
assertNull(fDao.loadNews(newsReference1.getId()));
assertNull(fDao.loadNews(newsReference2.getId()));
assertNotNull(fDao.loadNews(newsReference3.getId()));
for (int i = 0; i < newsUpdatedEvents.length; i++)