1 |
| package photospace.search; |
2 |
| |
3 |
| import java.util.*; |
4 |
| import org.apache.commons.logging.*; |
5 |
| import org.apache.lucene.document.*; |
6 |
| import junit.framework.*; |
7 |
| import photospace.meta.*; |
8 |
| |
9 |
| public class DocumentFactoryTest |
10 |
| extends TestCase |
11 |
| { |
12 |
| private static final Log log = LogFactory.getLog(DocumentFactoryTest.class); |
13 |
| |
14 |
1
| public void testCreatePhotoDocument() throws Exception
|
15 |
| { |
16 |
1
| DocumentFactory factory = new DocumentFactory();
|
17 |
| |
18 |
1
| PhotoMeta meta = getPhotoMeta();
|
19 |
| |
20 |
1
| Document doc = factory.createDocument(meta);
|
21 |
1
| Field text = doc.getField(DocumentFactory.TEXT_FIELD);
|
22 |
1
| assertNotNull(text);
|
23 |
1
| assertTrue(text.stringValue().indexOf(meta.getTitle()) != -1);
|
24 |
1
| assertTrue(text.stringValue().indexOf(meta.getDescription()) != -1);
|
25 |
1
| assertTrue(text.stringValue().indexOf(meta.getLabels()[0]) != -1);
|
26 |
1
| assertNotNull(doc.getField("parent"));
|
27 |
1
| assertEquals("/images/", doc.getField("parent").stringValue());
|
28 |
| |
29 |
1
| assertNotNull(doc.getField("created-date"));
|
30 |
1
| assertEquals("20040109", doc.getField("created-date").stringValue());
|
31 |
1
| assertEquals("20040109130102", doc.getField("created-datetime").stringValue());
|
32 |
| |
33 |
1
| assertNotNull(doc.getField(DocumentFactory.SORT_FIELD));
|
34 |
| |
35 |
1
| PhotoMeta fromDoc = (PhotoMeta) factory.createMeta(doc);
|
36 |
| |
37 |
1
| assertEquals(meta.getPath(), fromDoc.getPath());
|
38 |
1
| assertEquals(meta.getTitle(), fromDoc.getTitle());
|
39 |
1
| assertEquals(meta.getDescription(), fromDoc.getDescription());
|
40 |
1
| assertEquals(meta.getCreated(), fromDoc.getCreated());
|
41 |
1
| assertEquals(meta.getUpdated(), fromDoc.getUpdated());
|
42 |
1
| assertEquals(meta.getLabels().length, fromDoc.getLabels().length);
|
43 |
1
| assertEquals(meta.getPosition().getLatitude(), fromDoc.getPosition().getLatitude());
|
44 |
1
| assertEquals(meta.getViewCount(), fromDoc.getViewCount());
|
45 |
1
| assertEquals(meta.getWidth(), fromDoc.getWidth());
|
46 |
| } |
47 |
| |
48 |
1
| public void testCreateFolderDocument() throws Exception
|
49 |
| { |
50 |
1
| DocumentFactory factory = new DocumentFactory();
|
51 |
| |
52 |
1
| FolderMeta meta = new FolderMeta();
|
53 |
1
| meta.setPath("/images/");
|
54 |
1
| meta.setCreated(new Date());
|
55 |
1
| meta.addFile(getPhotoMeta());
|
56 |
1
| meta.addFile(new FolderMeta());
|
57 |
| |
58 |
1
| Document doc = factory.createDocument(meta);
|
59 |
| |
60 |
1
| assertNull(doc.getField("files"));
|
61 |
1
| assertNull(doc.getField("folders"));
|
62 |
1
| assertNull(doc.getField("photos"));
|
63 |
| |
64 |
1
| assertNotNull(doc.getField("created-date"));
|
65 |
1
| assertNotNull(doc.getField("parent"));
|
66 |
1
| assertEquals("/", doc.getField("parent").stringValue());
|
67 |
| |
68 |
1
| FolderMeta fromDoc = (FolderMeta) factory.createMeta(doc);
|
69 |
| |
70 |
1
| assertEquals(meta.getCreated(), fromDoc.getCreated());
|
71 |
1
| assertTrue(fromDoc.getFiles().length == 0);
|
72 |
| } |
73 |
| |
74 |
7
| public static PhotoMeta getPhotoMeta()
|
75 |
| { |
76 |
7
| PhotoMeta meta = new PhotoMeta();
|
77 |
7
| meta.setPath("/images/foo.jpg");
|
78 |
7
| meta.setTitle("a test title");
|
79 |
7
| meta.setDescription("a test description");
|
80 |
| |
81 |
7
| Calendar calendar = Calendar.getInstance();
|
82 |
7
| calendar.set(Calendar.DAY_OF_MONTH, 9);
|
83 |
7
| calendar.set(Calendar.MONTH, 0);
|
84 |
7
| calendar.set(Calendar.YEAR, 2004);
|
85 |
7
| calendar.set(Calendar.HOUR_OF_DAY, 13);
|
86 |
7
| calendar.set(Calendar.MINUTE, 1);
|
87 |
7
| calendar.set(Calendar.SECOND, 2);
|
88 |
7
| meta.setCreated(calendar.getTime());
|
89 |
7
| calendar.set(Calendar.MONTH, 10);
|
90 |
7
| meta.setUpdated(calendar.getTime());
|
91 |
7
| meta.setViewCount(new Integer(3));
|
92 |
7
| meta.setLabels(new String[] { "keyword1", "keyword2"} );
|
93 |
7
| meta.getPosition().setLatitude(new Double("-119.4"));
|
94 |
7
| meta.setWidth(100);
|
95 |
7
| return meta;
|
96 |
| } |
97 |
| |
98 |
| } |