01: package org.apache.lucene.index;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * 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.store.RAMDirectory;
23: import org.apache.lucene.store.IndexOutput;
24:
25: import java.io.IOException;
26:
27: //import org.cnlp.utils.properties.ResourceBundleHelper;
28:
29: public class TestFieldInfos extends LuceneTestCase {
30:
31: private Document testDoc = new Document();
32:
33: public TestFieldInfos(String s) {
34: super (s);
35: }
36:
37: protected void setUp() throws Exception {
38: super .setUp();
39: DocHelper.setupDoc(testDoc);
40: }
41:
42: public void test() throws IOException {
43: //Positive test of FieldInfos
44: assertTrue(testDoc != null);
45: FieldInfos fieldInfos = new FieldInfos();
46: fieldInfos.add(testDoc);
47: //Since the complement is stored as well in the fields map
48: assertTrue(fieldInfos.size() == DocHelper.all.size()); //this is all b/c we are using the no-arg constructor
49: RAMDirectory dir = new RAMDirectory();
50: String name = "testFile";
51: IndexOutput output = dir.createOutput(name);
52: assertTrue(output != null);
53: //Use a RAMOutputStream
54:
55: try {
56: fieldInfos.write(output);
57: output.close();
58: assertTrue(output.length() > 0);
59: FieldInfos readIn = new FieldInfos(dir, name);
60: assertTrue(fieldInfos.size() == readIn.size());
61: FieldInfo info = readIn.fieldInfo("textField1");
62: assertTrue(info != null);
63: assertTrue(info.storeTermVector == false);
64: assertTrue(info.omitNorms == false);
65:
66: info = readIn.fieldInfo("textField2");
67: assertTrue(info != null);
68: assertTrue(info.storeTermVector == true);
69: assertTrue(info.omitNorms == false);
70:
71: info = readIn.fieldInfo("textField3");
72: assertTrue(info != null);
73: assertTrue(info.storeTermVector == false);
74: assertTrue(info.omitNorms == true);
75:
76: info = readIn.fieldInfo("omitNorms");
77: assertTrue(info != null);
78: assertTrue(info.storeTermVector == false);
79: assertTrue(info.omitNorms == true);
80:
81: dir.close();
82:
83: } catch (IOException e) {
84: assertTrue(false);
85: }
86:
87: }
88: }
|