2 * Copyright 2006 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.apache.lucene.store.instantiated;
19 import java.io.IOException;
20 import java.util.Arrays;
22 import org.apache.lucene.analysis.MockAnalyzer;
23 import org.apache.lucene.index.IndexReader;
24 import org.apache.lucene.index.IndexWriter;
25 import org.apache.lucene.index.Term;
26 import org.apache.lucene.index.TermEnum;
27 import org.apache.lucene.search.IndexSearcher;
28 import org.apache.lucene.search.TermQuery;
29 import org.apache.lucene.search.TopDocs;
30 import org.apache.lucene.store.Directory;
31 import org.apache.lucene.util.LuceneTestCase;
33 public class TestEmptyIndex extends LuceneTestCase {
35 public void testSearch() throws Exception {
37 InstantiatedIndex ii = new InstantiatedIndex();
39 IndexReader r = new InstantiatedIndexReader(ii);
40 IndexSearcher s = newSearcher(r);
42 TopDocs td = s.search(new TermQuery(new Term("foo", "bar")), 1);
44 assertEquals(0, td.totalHits);
52 public void testNorms() throws Exception {
54 InstantiatedIndex ii = new InstantiatedIndex();
55 IndexReader r = new InstantiatedIndexReader(ii);
60 // make sure a Directory acts the same
61 Directory d = newDirectory();
62 new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))).close();
63 r = IndexReader.open(d, false);
70 private void testNorms(IndexReader r) throws IOException {
72 norms = r.norms("foo");
74 assertEquals(0, norms.length);
76 Arrays.fill(norms, (byte)10);
77 r.norms("foo", norms, 10);
78 for (byte b : norms) {
79 assertEquals((byte)10, b);
84 public void testTermEnum() throws Exception {
86 InstantiatedIndex ii = new InstantiatedIndex();
87 IndexReader r = new InstantiatedIndexReader(ii);
92 // make sure a Directory acts the same
93 Directory d = newDirectory();
94 new IndexWriter(d, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))).close();
95 r = IndexReader.open(d, false);
101 public void termEnumTest(IndexReader r) throws Exception {
102 TermEnum terms = r.terms();
104 assertNull(terms.term());
105 assertFalse(terms.next());