KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.lucene.index;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import junit.framework.TestCase;
20 import org.apache.lucene.store.RAMDirectory;
21 import org.apache.lucene.document.Document;
22 import org.apache.lucene.document.Field;
23 import org.apache.lucene.analysis.WhitespaceAnalyzer;
24 import org.apache.lucene.search.Similarity;
25
26 import java.util.Map JavaDoc;
27 import java.io.IOException JavaDoc;
28
29 public class TestFieldsReader extends TestCase {
30   private RAMDirectory dir = new RAMDirectory();
31   private Document testDoc = new Document();
32   private FieldInfos fieldInfos = null;
33
34   public TestFieldsReader(String JavaDoc s) {
35     super(s);
36   }
37
38   protected void setUp() {
39     fieldInfos = new FieldInfos();
40     DocHelper.setupDoc(testDoc);
41     fieldInfos.add(testDoc);
42     DocumentWriter writer = new DocumentWriter(dir, new WhitespaceAnalyzer(),
43             Similarity.getDefault(), 50);
44     assertTrue(writer != null);
45     try {
46       writer.addDocument("test", testDoc);
47     }
48     catch (IOException JavaDoc e)
49     {
50       
51     }
52   }
53
54   protected void tearDown() {
55
56   }
57
58   public void test() {
59     assertTrue(dir != null);
60     assertTrue(fieldInfos != null);
61     try {
62       FieldsReader reader = new FieldsReader(dir, "test", fieldInfos);
63       assertTrue(reader != null);
64       assertTrue(reader.size() == 1);
65       Document doc = reader.doc(0);
66       assertTrue(doc != null);
67       assertTrue(doc.getField("textField1") != null);
68       Field field = doc.getField("textField2");
69       assertTrue(field != null);
70       assertTrue(field.isTermVectorStored() == true);
71       reader.close();
72     } catch (IOException JavaDoc e) {
73       e.printStackTrace();
74       assertTrue(false);
75     }
76   }
77 }
78
Popular Tags