IFeed feed = new Feed(new URL("inmemory://rss_2_0.xml")); //$NON-NLS-1$
feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
FeedReference feedRef = new FeedReference(feed.getId());
IBookMark bookmark = createBookMark(feed);
final int addedCounter[] = new int[] { 0 };
final int updatedCounter[] = new int[] { 0 };
newsListener = new NewsListener() {
public void newsAdded(Set<NewsEvent> events) {
addedCounter[0] += events.size();
}
public void newsDeleted(Set<NewsEvent> events) {
fail("Did not expect this Event");
}
public void newsUpdated(Set<NewsEvent> events) {
updatedCounter[0] += events.size();
}
};
NewsModel.getDefault().addNewsListener(newsListener);
/* First Reload */
InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", null, null, "Hello World", "bpasero", null, "mp3");
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(1, getUnreadCount(feed));
assertEquals(1, getNewCount(feed));
assertEquals(INews.State.NEW, feedRef.resolve().getNews().get(0).getState());
assertEquals("Hello World", feedRef.resolve().getNews().get(0).getDescription());
assertEquals("bpasero", feedRef.resolve().getNews().get(0).getAuthor().getName());
/* Set to Unread */
fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);
/* Second Reload - changed Description */
InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", null, null, "Hello World Changed", "bpasero", null, "mp3");
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(1, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.UNREAD, feedRef.resolve().getNews().get(0).getState());
assertEquals("Hello World Changed", feedRef.resolve().getNews().get(0).getDescription());
/* Set to Unread and Reload */
fApplicationLayer.setNewsState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);
fController.reload(bookmark, null, new NullProgressMonitor());
/* This Reload - added Enclosure */
InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", null, null, "Hello World Changed", "bpasero", "http://www.download.de", "mp3");
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(1, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.UNREAD, feedRef.resolve().getNews().get(0).getState());
assertEquals(1, feedRef.resolve().getNews().get(0).getAttachments().size());
assertEquals("http://www.download.de", feedRef.resolve().getNews().get(0).getAttachments().get(0).getUrl().toString());
/* This Reload - Changed Author */
InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", null, null, "Hello World Changed", "ijuma", "http://www.download.de", "mp3");
fController.reload(bookmark, null, new NullProgressMonitor());
assertEquals(1, feedRef.resolve().getNews().size());
assertEquals(1, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
assertEquals(INews.State.UNREAD, feedRef.resolve().getNews().get(0).getState());
assertEquals("ijuma", feedRef.resolve().getNews().get(0).getAuthor().getName());
/* Test Event Counter */
assertEquals(1, addedCounter[0]);
assertEquals(3, updatedCounter[0]);
} finally {