*/
@Test
public void testSetNewsStateWithEquivalentNewsHasNewsEventEntityActivated() throws Exception {
NewsListener newsListener = null;
try {
IFeed feed1 = fFactory.createFeed(null, new URI("http://www.feed.com"));
IFeed feed2 = fFactory.createFeed(null, new URI("http://www.feed2.com"));
INews news1 = fFactory.createNews(null, feed1, new Date());
news1.setLink(new URI("www.link.com"));
INews news2 = fFactory.createNews(null, feed2, new Date());
news2.setLink(new URI("www.link.com"));
fFactory.createNews(null, feed1, new Date());
fFactory.createNews(null, feed2, new Date());
DynamicDAO.save(feed1);
feed2 = DynamicDAO.save(feed2);
feed1 = null;
feed2 = null;
news1 = null;
System.gc();
List<INews> newsList = Collections.singletonList(news2);
final boolean[] newsUpdatedCalled = new boolean[1];
newsListener = new NewsAdapter() {
@Override
public void entitiesUpdated(Set<NewsEvent> events) {
newsUpdatedCalled[0] = true;
assertEquals(2, events.size());
for (NewsEvent event : events) {
IFeed feed = event.getEntity().getFeedReference().resolve();
/* This should be enough to verify that the news is fully activated */
assertNotNull(feed.getId());
assertNotNull(feed.getNews());
assertNotNull(feed.getNews().get(0));
}
}
};
DynamicDAO.addEntityListener(INews.class, newsListener);
Owl.getPersistenceService().getDAOService().getNewsDAO().setState(newsList, INews.State.READ, true, false);