news4.setState(INews.State.NEW);
ILabel label = fFactory.createLabel(null, "New Label");
DynamicDAO.save(label);
INewsBin bin1 = fFactory.createNewsBin(null, bm.getParent(), "Bin 1");
INewsBin bin2 = fFactory.createNewsBin(null, bm.getParent(), "Bin 2");
DynamicDAO.save(bin1);
DynamicDAO.save(bin2);
/* Filter "Title is Title": Mark Read, Sticky, Label, Copy */
{
ISearch search = createTitleSearch("Title");
ISearchFilter filter = fFactory.createSearchFilter(null, search, "Title is Title");
filter.setEnabled(true);
filter.setOrder(0);
filter.addAction(fFactory.createFilterAction(MARK_READ_ID));
filter.addAction(fFactory.createFilterAction(MARK_STICKY_ID));
IFilterAction labelAction = fFactory.createFilterAction(LABEL_NEWS_ID);
labelAction.setData(label.getId());
filter.addAction(labelAction);
IFilterAction copyAction = fFactory.createFilterAction(COPY_NEWS_ID);
copyAction.setData(new Long[] { bin1.getId(), bin2.getId() });
filter.addAction(copyAction);
DynamicDAO.save(filter);
}
/* Filter "Title is Other": Move */
{
ISearch search = createTitleSearch("Other");
ISearchFilter filter = fFactory.createSearchFilter(null, search, "Title is Other");
filter.setEnabled(true);
filter.setOrder(1);
IFilterAction moveAction = fFactory.createFilterAction(MOVE_NEWS_ID);
moveAction.setData(new Long[] { bin1.getId(), bin2.getId() });
filter.addAction(moveAction);
DynamicDAO.save(filter);
}
/* Filter "Match All": Label News */
{
ISearchFilter filter = fFactory.createSearchFilter(null, null, "All News");
filter.setEnabled(true);
filter.setMatchAllNews(true);
filter.setOrder(2);
IFilterAction labelAction = fFactory.createFilterAction(LABEL_NEWS_ID);
labelAction.setData(label.getId());
filter.addAction(labelAction);
DynamicDAO.save(filter);
}
final AtomicInteger listenerCalled = new AtomicInteger();
SearchFilterAdapter listener = new SearchFilterAdapter() {
@Override
public void filterApplied(ISearchFilter f, Collection<INews> news) {
listenerCalled.incrementAndGet();
}
};
DynamicDAO.addEntityListener(ISearchFilter.class, listener);
try {
fAppService.handleFeedReload(bm, feed, null, false, true, new NullProgressMonitor());
} finally {
DynamicDAO.removeEntityListener(ISearchFilter.class, listener);
}
assertEquals(3, listenerCalled.get());
List<INews> news = bm.getFeedLinkReference().resolve().getNews();
assertEquals(4, news.size());
assertEquals(2, bm.getNewsCount(EnumSet.of(INews.State.READ)));
assertEquals(1, bm.getNewsCount(EnumSet.of(INews.State.DELETED)));
assertEquals(1, bm.getNewsCount(EnumSet.of(INews.State.NEW)));
for (INews newsitem : news) {
if (newsitem.equals(news1)) {
assertEquals(INews.State.READ, news1.getState());
assertTrue(newsitem.isFlagged());
assertTrue(!news1.getLabels().isEmpty());
assertEquals(label, news1.getLabels().iterator().next());
} else if (newsitem.equals(news2)) {
assertEquals(INews.State.READ, news2.getState());
assertTrue(newsitem.isFlagged());
assertTrue(!news2.getLabels().isEmpty());
assertEquals(label, news2.getLabels().iterator().next());
} else if (newsitem.equals(news3)) {
assertEquals(INews.State.DELETED, news3.getState());
} else if (newsitem.equals(news4)) {
assertTrue(!news4.getLabels().isEmpty());
assertEquals(label, news4.getLabels().iterator().next());
}
}
assertEquals(3, bin1.getNews().size());
assertEquals(1, bin1.getNewsCount(EnumSet.of(INews.State.NEW)));
assertEquals(2, bin1.getNewsCount(EnumSet.of(INews.State.READ)));
List<INews> binNews = bin1.getNews();
for (INews newsitem : binNews) {
if (newsitem.equals(news1)) {
assertEquals(INews.State.READ, news1.getState());
assertTrue(newsitem.isFlagged());
assertTrue(!news1.getLabels().isEmpty());
assertEquals(label, news1.getLabels().iterator().next());
} else if (newsitem.equals(news2)) {
assertEquals(INews.State.READ, news2.getState());
assertTrue(newsitem.isFlagged());
assertTrue(!news2.getLabels().isEmpty());
assertEquals(label, news2.getLabels().iterator().next());
} else if (newsitem.equals(news3)) {
assertEquals(INews.State.NEW, news3.getState());
assertTrue(newsitem.getLabels().isEmpty());
assertTrue(!newsitem.isFlagged());
}
}
assertEquals(3, bin2.getNews().size());
assertEquals(1, bin2.getNewsCount(EnumSet.of(INews.State.NEW)));
assertEquals(2, bin2.getNewsCount(EnumSet.of(INews.State.READ)));
binNews = bin2.getNews();
for (INews newsitem : binNews) {
if (newsitem.equals(news1)) {
assertEquals(INews.State.READ, news1.getState());
assertTrue(newsitem.isFlagged());
} else if (newsitem.equals(news2)) {