1   /*  Copyright 2004 Brian McCallister
2    *
3    *   Licensed under the Apache License, Version 2.0 (the "License");
4    *   you may not use this file except in compliance with the License.
5    *   You may obtain a copy of the License at
6    *
7    *       http://www.apache.org/licenses/LICENSE-2.0
8    *
9    *   Unless required by applicable law or agreed to in writing, software
10   *   distributed under the License is distributed on an "AS IS" BASIS,
11   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   *   See the License for the specific language governing permissions and
13   *   limitations under the License.
14   */
15  package org.skife.lucene.graph;
16  
17  import junit.framework.TestCase;
18  
19  import java.io.File;
20  import java.util.Iterator;
21  
22  import org.skife.lucene.graph.helper.Beer;
23  import org.skife.lucene.graph.helper.Cozy;
24  import org.skife.lucene.graph.helper.Cooler;
25  import org.apache.lucene.index.IndexReader;
26  
27  public class GraphIndexerTest extends TestCase
28  {
29      private GraphIndexer indexer = new GraphIndexer();
30  
31      public void testCorrectNumberOfDocumentsSingle() throws Exception
32      {
33          final File index = indexer.index(new Beer(1, "Schlitz"));
34          final IndexReader reader = IndexReader.open(index);
35          assertEquals(1, reader.numDocs());
36  
37          reader.close();
38      }
39  
40      public void testCorrectNumberOfDocumentsReference() throws Exception
41      {
42          final Cozy cozy = new Cozy(1, new Beer(2, "Schlitz)"));
43  
44          final File index = indexer.index(cozy);
45          final IndexReader reader = IndexReader.open(index);
46          assertEquals(2, reader.numDocs());
47  
48          reader.close();
49      }
50  
51      public void testCorrectNumberOfDocumentsCollection() throws Exception
52      {
53          final Cooler cooler = new Cooler(1);
54          cooler.stock(new Beer(2, "Schlitz"));
55          final File index = indexer.index(cooler);
56          final IndexReader reader = IndexReader.open(index);
57          assertEquals(2, reader.numDocs());
58  
59          reader.close();
60      }
61  
62      public void testEmptyFieldNotThere() throws Exception
63      {
64          final File index = indexer.index(new Beer(1, "Schlitz"));
65          final IndexReader reader = IndexReader.open(index);
66  
67          for (Iterator i = reader.getFieldNames().iterator(); i.hasNext();)
68          {
69              System.err.println("Field [" + i.next() + "]") ;
70          }
71          assertEquals(1, reader.numDocs());
72  
73          reader.close();
74      }
75  }