final NewsReference[] newsRef = new NewsReference[1];
newsAdapter = new NewsAdapter() {
@Override
public void entitiesAdded(Set<NewsEvent> events) {
assertEquals(1, events.size());
newsRef[0] = new NewsReference(events.iterator().next().getEntity().getId());
}
};
DynamicDAO.addEntityListener(INews.class, newsAdapter);
final News initialNews1 = (News) createNews(feed1);
initialNews1.setGuid(null);
initialNews1.setState(State.NEW);
final News initialNews2 = (News) createNews(feed2);
initialNews2.setGuid(null);
initialNews2.setState(State.NEW);
INews newsItem1 = null;
NewsReference newsRef1 = null;
INews newsItem2 = null;
NewsReference newsRef2 = null;
NewsReference newsRef3 = null;
try {
DynamicDAO.save(feed1);
newsRef1 = newsRef[0];
newsItem1 = newsRef1.resolve();
feed2 = DynamicDAO.save(feed2);
newsRef2 = newsRef[0];
newsItem2 = newsRef2.resolve();
final News initialNews3 = (News) createNews(feed2);
initialNews3.setTitle("Some other title");
initialNews3.setGuid(null);
initialNews3.setLink(null);
initialNews3.setState(State.NEW);
DynamicDAO.save(feed2);
newsRef3 = newsRef[0];
} catch (PersistenceException e) {
fail(e.getMessage());
return;
} finally {
DynamicDAO.removeEntityListener(INews.class, newsAdapter);
}
try {
List<INews> newsList1 = new ArrayList<INews>();
newsList1.add(newsItem1);
List<INews> newsList2 = new ArrayList<INews>();
newsList2.add(newsItem2);
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(newsList1, State.UPDATED, true, false);
INews news1 = newsRef1.resolve();
INews news2 = newsRef2.resolve();
INews news3 = newsRef3.resolve();
assertEquals(State.UPDATED, news1.getState());
assertEquals(State.UPDATED, news2.getState());
assertEquals(State.NEW, news3.getState());
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(newsList2, State.READ, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.READ, news1.getState());
assertEquals(State.READ, news2.getState());
assertEquals(State.NEW, news3.getState());
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(newsList1, State.UNREAD, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.UNREAD, news1.getState());
assertEquals(State.UNREAD, news2.getState());
assertEquals(State.NEW, news3.getState());
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(newsList2, State.READ, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.READ, news1.getState());
assertEquals(State.READ, news2.getState());
assertEquals(State.NEW, news3.getState());
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(newsList1, State.UNREAD, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.UNREAD, news1.getState());
assertEquals(State.UNREAD, news2.getState());
assertEquals(State.NEW, news3.getState());
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(newsList2, State.NEW, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.NEW, news1.getState());
assertEquals(State.NEW, news2.getState());
assertEquals(State.NEW, news3.getState());
// Make sure it doesn't change when we set it to the same
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(newsList1, State.NEW, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.NEW, news1.getState());
assertEquals(State.NEW, news2.getState());
assertEquals(State.NEW, news3.getState());
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(newsList1, State.HIDDEN, true, false);
news1 = newsRef1.resolve();
news2 = newsRef2.resolve();
news3 = newsRef3.resolve();
assertEquals(State.HIDDEN, news1.getState());
assertEquals(State.HIDDEN, news2.getState());
assertEquals(State.NEW, news3.getState());
DynamicDAO.delete(newsRef1.resolve());