1 |
| package photospace.web.tags; |
2 |
| |
3 |
| import java.io.*; |
4 |
| import java.util.*; |
5 |
| import org.springframework.context.support.*; |
6 |
| import junit.framework.*; |
7 |
| import photospace.*; |
8 |
| import photospace.meta.*; |
9 |
| import photospace.search.*; |
10 |
| |
11 |
| public class TagsTest |
12 |
| extends TestCase |
13 |
| { |
14 |
| SearchIndex searchIndex; |
15 |
| |
16 |
1
| public void setUp() throws Exception
|
17 |
| { |
18 |
1
| File index = new File(System.getProperty("java.io.tmpdir"), "test-index");
|
19 |
1
| StaticApplicationContext context = new StaticApplicationContext();
|
20 |
| |
21 |
1
| context.registerSingleton("indexer", Indexer.class, null);
|
22 |
1
| context.registerSingleton("searcher", Searcher.class, null);
|
23 |
| |
24 |
1
| new Application().setApplicationContext(context);
|
25 |
| |
26 |
1
| searchIndex = new SearchIndex(index);
|
27 |
1
| Application.indexer().setIndex(searchIndex);
|
28 |
1
| Application.searcher().setIndex(searchIndex);
|
29 |
| } |
30 |
| |
31 |
1
| public void tearDown() throws Exception
|
32 |
| { |
33 |
1
| searchIndex.closeReader();
|
34 |
| } |
35 |
| |
36 |
1
| public void testTermsTag() throws Exception
|
37 |
| { |
38 |
1
| FolderMeta root = new FolderMeta();
|
39 |
1
| FolderMeta folder = new FolderMeta();
|
40 |
1
| PhotoMeta photo = new PhotoMeta();
|
41 |
| |
42 |
1
| root.setPath("/");
|
43 |
1
| root.setTitle("test title");
|
44 |
1
| folder.setPath("/folder/");
|
45 |
1
| folder.setTitle("another title");
|
46 |
1
| photo.setPath("/folder/photo1.jpg");
|
47 |
1
| photo.setTitle(root.getTitle());
|
48 |
| |
49 |
1
| Application.indexer().index(Arrays.asList(new Meta[] { root, folder, photo }), true);
|
50 |
| |
51 |
1
| TermsTag tag = new TermsTag();
|
52 |
1
| tag.setField("title");
|
53 |
1
| tag.prepare();
|
54 |
| |
55 |
1
| assertTrue(tag.hasNext());
|
56 |
1
| int count = 0;
|
57 |
1
| while (tag.hasNext())
|
58 |
| { |
59 |
2
| Match match = (Match) tag.next();
|
60 |
2
| assertEquals("title", match.getField());
|
61 |
2
| count++;
|
62 |
| } |
63 |
1
| assertEquals(2, count);
|
64 |
| |
65 |
1
| tag.setPath(photo.getPath());
|
66 |
1
| tag.prepare();
|
67 |
| |
68 |
1
| assertTrue(tag.hasNext());
|
69 |
1
| count = 0;
|
70 |
1
| while (tag.hasNext())
|
71 |
| { |
72 |
1
| Match match = (Match) tag.next();
|
73 |
1
| assertEquals("title", match.getField());
|
74 |
1
| count++;
|
75 |
| } |
76 |
1
| assertEquals(1, count);
|
77 |
| } |
78 |
| } |