*
* @throws Exception
*/
@Test
public void testNewsService() throws Exception {
NewsService service = Controller.getDefault().getNewsService();
IFeed feed = new Feed(new URL("http://www.rssowl.org/rssowl2dg/tests/manager/rss_2_0.xml")); //$NON-NLS-1$
feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
NewsModel.getDefault().getTypesFactory().createNews(null, feed, new Date()); //$NON-NLS-1$
feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
assertEquals(1, getUnreadCount(feed));
assertEquals(1, getNewCount(feed));
NewsModel.getDefault().getPersistenceLayer().getApplicationLayer().setNewsState(feed.getNews(), INews.State.READ, true, false);
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
NewsModel.getDefault().getPersistenceLayer().getApplicationLayer().setNewsState(feed.getNews(), INews.State.UNREAD, true, false);
assertEquals(1, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
NewsModel.getDefault().getPersistenceLayer().getApplicationLayer().setNewsState(feed.getNews(), INews.State.READ, true, false);
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
NewsModel.getDefault().getPersistenceLayer().getApplicationLayer().setNewsState(feed.getNews(), INews.State.UPDATED, true, false);
assertEquals(1, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
NewsModel.getDefault().getPersistenceLayer().getApplicationLayer().setNewsState(feed.getNews(), INews.State.READ, true, false);
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
/* Simulate Shutdown */
service.stopService();
NewsModel.getDefault().getTypesFactory().createNews(null, feed, new Date()); //$NON-NLS-1$
feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
NewsModel.getDefault().getTypesFactory().createNews(null, feed, new Date()); //$NON-NLS-1$
feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
assertEquals(2, getUnreadCount(feed));
assertEquals(2, getNewCount(feed));
NewsModel.getDefault().getPersistenceLayer().getApplicationLayer().setNewsState(feed.getNews(), INews.State.READ, true, false);
assertEquals(0, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
NewsModel.getDefault().getPersistenceLayer().getApplicationLayer().setNewsState(feed.getNews(), INews.State.UNREAD, true, false);
assertEquals(3, getUnreadCount(feed));
assertEquals(0, getNewCount(feed));
/* Simulate Dirty Shutdown */
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
feed = new Feed(new URL("http://www.rssowl.org/rssowl2dg/tests/manager/rss_2_0.xml")); //$NON-NLS-1$
feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
NewsModel.getDefault().getTypesFactory().createNews(null, feed, new Date()); //$NON-NLS-1$
feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
NewsModel.getDefault().getTypesFactory().createNews(null, feed, new Date()); //$NON-NLS-1$
feed = NewsModel.getDefault().getPersistenceLayer().getModelDAO().saveFeed(feed);
service.testDirtyShutdown();
assertEquals(2, getUnreadCount(feed));
assertEquals(2, getNewCount(feed));
}