add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / test / org / apache / lucene / index / TestFieldInfos.java
1 package org.apache.lucene.index;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import org.apache.lucene.util.LuceneTestCase;
21 import org.apache.lucene.document.Document;
22 import org.apache.lucene.index.FieldInfo.IndexOptions;
23 import org.apache.lucene.store.Directory;
24 import org.apache.lucene.store.IndexOutput;
25
26 import java.io.IOException;
27
28 //import org.cnlp.utils.properties.ResourceBundleHelper;
29
30 public class TestFieldInfos extends LuceneTestCase {
31
32   private Document testDoc = new Document();
33
34   @Override
35   public void setUp() throws Exception {
36     super.setUp();
37     DocHelper.setupDoc(testDoc);
38   }
39
40   public void test() throws IOException {
41     //Positive test of FieldInfos
42     assertTrue(testDoc != null);
43     FieldInfos fieldInfos = new FieldInfos();
44     fieldInfos.add(testDoc);
45     //Since the complement is stored as well in the fields map
46     assertTrue(fieldInfos.size() == DocHelper.all.size()); //this is all b/c we are using the no-arg constructor
47     Directory dir = newDirectory();
48     String name = "testFile";
49     IndexOutput output = dir.createOutput(name);
50     assertTrue(output != null);
51     //Use a RAMOutputStream
52     
53       fieldInfos.write(output);
54       output.close();
55       assertTrue(dir.fileLength(name) > 0);
56       FieldInfos readIn = new FieldInfos(dir, name);
57       assertTrue(fieldInfos.size() == readIn.size());
58       FieldInfo info = readIn.fieldInfo("textField1");
59       assertTrue(info != null);
60       assertTrue(info.storeTermVector == false);
61       assertTrue(info.omitNorms == false);
62
63       info = readIn.fieldInfo("textField2");
64       assertTrue(info != null);
65       assertTrue(info.storeTermVector == true);
66       assertTrue(info.omitNorms == false);
67
68       info = readIn.fieldInfo("textField3");
69       assertTrue(info != null);
70       assertTrue(info.storeTermVector == false);
71       assertTrue(info.omitNorms == true);
72
73       info = readIn.fieldInfo("omitNorms");
74       assertTrue(info != null);
75       assertTrue(info.storeTermVector == false);
76       assertTrue(info.omitNorms == true);
77
78       dir.close();
79   }
80 }