/* First add some Types */
IFeed feed1 = fTypesFactory.createFeed(null, new URL("http://www.feed.com/feed1.xml"));
IFeed feed2 = fTypesFactory.createFeed(null, new URL("http://www.feed.com/feed2.xml"));
INews news1 = fTypesFactory.createNews(null, feed1, new Date(System.currentTimeMillis()));
news1.setDescription("News #1 Description");
news1.setLink(new URI("http://www.news.com/news1.html"));
INews news2 = fTypesFactory.createNews(null, feed1, new Date(System.currentTimeMillis()));
news2.setDescription("News #2 Description");
news2.setLink(new URI("http://www.news.com/news2.html"));
INews news3 = fTypesFactory.createNews(null, feed1, new Date(System.currentTimeMillis()));
news3.setDescription("News #3 Description");
news3.setLink(new URI("http://www.news.com/news3.html"));
INews news4 = fTypesFactory.createNews(null, feed2, new Date(System.currentTimeMillis()));
news4.setDescription("News #4 Description");
news4.setLink(new URI("http://www.news.com/news4.html"));
INews news5 = fTypesFactory.createNews(null, feed2, new Date(System.currentTimeMillis()));
news5.setDescription("News #5 Description Foo Bar");
news5.setLink(new URI("http://www.news.com/news5.html"));
INews news6 = fTypesFactory.createNews(null, feed2, new Date(System.currentTimeMillis()));
news6.setLink(new URI("http://www.news.com/news6.html"));
fDao.saveFeed(feed1);
fDao.saveFeed(feed2);
// TODO Replace this by a event-based solution if that becomes available
Thread.sleep(500);
/* 1. SearchCondition: News coming from Feed that contains "feed2.xml" */
ISearchField field1 = fTypesFactory.createSearchField(IFeed.LINK, IFeed.class);
ISearchCondition cond1 = fTypesFactory.createSearchCondition(field1, SearchSpecifier.CONTAINS, "feed2.xml", true);
conditions.add(cond1);
/* 2. SearchCondition: News Description does not contain "Foo" */
ISearchField field2 = fTypesFactory.createSearchField(INews.DESCRIPTION, INews.class);
ISearchCondition cond2 = fTypesFactory.createSearchCondition(field2, SearchSpecifier.CONTAINS_NOT, "Foo", true);
conditions.add(cond2);
/* 3. SearchCondition: News State is NEW */
ISearchField field3 = fTypesFactory.createSearchField(INews.STATE, INews.class);
ISearchCondition cond3 = fTypesFactory.createSearchCondition(field3, SearchSpecifier.IS, State.NEW.name(), true);
conditions.add(cond3);
List<ISearchHit<NewsReference>> results = fModelSearch.searchNews(conditions);
assertEquals(2, results.size());
boolean resultsMatch[] = new boolean[2];
for (ISearchHit<NewsReference> searchHit : results) {
INews news = searchHit.getResult().resolve();
if (news.getTitle().equals(news4.getTitle()))
resultsMatch[0] = true;
else if (news.getTitle().equals(news6.getTitle()))
resultsMatch[1] = true;
}
for (boolean element : resultsMatch)
assertTrue("Missing a result match", element);