KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > index > TestFieldInfos


1 package org.apache.lucene.index;
2
3
4 import junit.framework.TestCase;
5 import org.apache.lucene.document.Document;
6 import org.apache.lucene.document.Field;
7 import org.apache.lucene.store.RAMOutputStream;
8 import org.apache.lucene.store.RAMDirectory;
9 import org.apache.lucene.store.OutputStream;
10
11 import java.io.IOException JavaDoc;
12 import java.util.Map JavaDoc;
13
14 //import org.cnlp.utils.properties.ResourceBundleHelper;
15

16 public class TestFieldInfos extends TestCase {
17
18   private Document testDoc = new Document();
19
20   public TestFieldInfos(String JavaDoc s) {
21     super(s);
22   }
23
24   protected void setUp() {
25     DocHelper.setupDoc(testDoc);
26   }
27
28   protected void tearDown() {
29   }
30
31   public void test() {
32     //Positive test of FieldInfos
33
assertTrue(testDoc != null);
34     FieldInfos fieldInfos = new FieldInfos();
35     fieldInfos.add(testDoc);
36     //Since the complement is stored as well in the fields map
37
assertTrue(fieldInfos.size() == 7); //this is 7 b/c we are using the no-arg constructor
38
RAMDirectory dir = new RAMDirectory();
39     String JavaDoc name = "testFile";
40     OutputStream output = dir.createFile(name);
41     assertTrue(output != null);
42     //Use a RAMOutputStream
43

44     try {
45       fieldInfos.write(output);
46       output.close();
47       assertTrue(output.length() > 0);
48       FieldInfos readIn = new FieldInfos(dir, name);
49       assertTrue(fieldInfos.size() == readIn.size());
50       FieldInfo info = readIn.fieldInfo("textField1");
51       assertTrue(info != null);
52       assertTrue(info.storeTermVector == false);
53       
54       info = readIn.fieldInfo("textField2");
55       assertTrue(info != null);
56       assertTrue(info.storeTermVector == true);
57       
58       dir.close();
59
60     } catch (IOException JavaDoc e) {
61       assertTrue(false);
62     }
63
64   }
65 }
66
Popular Tags