pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / instantiated / src / test / org / apache / lucene / store / instantiated / TestSerialization.java
1 package org.apache.lucene.store.instantiated;
2
3 /**
4  * Copyright 2006 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
20 import org.apache.lucene.store.Directory;
21 import org.apache.lucene.util.LuceneTestCase;
22 import org.apache.lucene.index.IndexWriter;
23 import org.apache.lucene.index.IndexReader;
24 import org.apache.lucene.analysis.WhitespaceAnalyzer;
25 import org.apache.lucene.document.Document;
26 import org.apache.lucene.document.Field;
27
28 import java.io.ByteArrayOutputStream;
29 import java.io.ObjectOutputStream;
30
31 public class TestSerialization extends LuceneTestCase {
32
33   public void test() throws Exception {
34     Directory dir = newDirectory();
35
36     IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
37     Document doc = new Document();
38     doc.add(new Field("foo", "bar rab abr bra rba", Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
39     doc.add(new Field("moo", "bar rab abr bra rba", Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
40     iw.addDocument(doc);
41     iw.close();
42
43     IndexReader ir = IndexReader.open(dir, false);
44     InstantiatedIndex ii = new InstantiatedIndex(ir);
45     ir.close();
46
47     ByteArrayOutputStream baos = new ByteArrayOutputStream(5000);
48     ObjectOutputStream oos = new ObjectOutputStream(baos);
49     oos.writeObject(ii);
50     oos.close();
51     baos.close();
52     dir.close();
53     
54   }
55
56 }