IFeed feed = new Feed(new URI("inmemory://rss_2_0.xml")); //$NON-NLS-1$
feed = DynamicDAO.save(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 entitiesAdded(Set<NewsEvent> events) {
addedCounter[0] += events.size();
}
public void entitiesDeleted(Set<NewsEvent> events) {
fail("Did not expect this Event");
}
public void entitiesUpdated(Set<NewsEvent> events) {
updatedCounter[0] += events.size();
}
};
DynamicDAO.addEntityListener(INews.class, 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 */
fNewsDao.setState(feedRef.resolve().getNews(), INews.State.UNREAD, true, false);
assertEquals(1, updatedCounter[0]);
/* 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());
assertEquals(2, updatedCounter[0]);
/* Set to Unread and Reload */
fNewsDao.setState(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, feed.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).getLink().toString());
assertEquals(3, updatedCounter[0]);
/* This Reload - Changed Author */
InMemoryProtocolHandler.FEED = generateFeed("Title", "http://www.link.de", null, null, "Hello World Changed", "ijuma", "http://www.download.de", "mp3");
oldNewsListener = new NewsAdapter() {
@Override
public void entitiesUpdated(Set<NewsEvent> events) {
assertEquals(1, events.size());
int attachmentsSize = events.iterator().next().getOldNews().getAttachments().size();
assertEquals(1, attachmentsSize);
}
};
DynamicDAO.addEntityListener(INews.class, oldNewsListener);
fController.reload(bookmark, null, new NullProgressMonitor());
DynamicDAO.removeEntityListener(INews.class, oldNewsListener);
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());
assertEquals(3, updatedCounter[0]);
/* Test Event Counter */
assertEquals(1, addedCounter[0]);
assertEquals(3, updatedCounter[0]);