01: package info.jtrac.lucene;
02:
03: import info.jtrac.domain.Item;
04: import java.io.File;
05: import java.util.List;
06: import junit.framework.TestCase;
07: import org.springframework.context.ApplicationContext;
08: import org.springframework.context.support.FileSystemXmlApplicationContext;
09:
10: public class IndexSearcherTest extends TestCase {
11:
12: private ApplicationContext context;
13:
14: @Override
15: public void setUp() {
16: File home = new File("target/home");
17: if (!home.exists()) {
18: home.mkdir();
19: }
20: File file = new File("target/home/indexes");
21: if (!file.exists()) {
22: file.mkdir();
23: } else {
24: for (File f : file.listFiles()) {
25: f.delete();
26: }
27: }
28: System.setProperty("jtrac.home", home.getAbsolutePath());
29: context = new FileSystemXmlApplicationContext(
30: "src/main/webapp/WEB-INF/applicationContext-lucene.xml");
31: }
32:
33: public void testFindItemIdsBySearchingWithinSummaryAndDetailFields()
34: throws Exception {
35: Item item = new Item();
36: item.setId(1);
37: item.setSummary("this is a test summary");
38: item.setDetail("the quick brown fox jumped over the lazy dogs");
39: Indexer indexer = (Indexer) context.getBean("indexer");
40: indexer.index(item);
41: IndexSearcher searcher = (IndexSearcher) context
42: .getBean("indexSearcher");
43: List list = searcher.findItemIdsContainingText("lazy");
44: assertEquals(1, list.size());
45: list = searcher.findItemIdsContainingText("foo");
46: assertEquals(0, list.size());
47: list = searcher.findItemIdsContainingText("summary");
48: assertEquals(1, list.size());
49: }
50:
51: }
|