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 ; 12 import java.util.Map ; 13 14 16 public class TestFieldInfos extends TestCase { 17 18 private Document testDoc = new Document(); 19 20 public TestFieldInfos(String 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 assertTrue(testDoc != null); 34 FieldInfos fieldInfos = new FieldInfos(); 35 fieldInfos.add(testDoc); 36 assertTrue(fieldInfos.size() == 7); RAMDirectory dir = new RAMDirectory(); 39 String name = "testFile"; 40 OutputStream output = dir.createFile(name); 41 assertTrue(output != null); 42 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 e) { 61 assertTrue(false); 62 } 63 64 } 65 } 66 | Popular Tags |