View Javadoc

1   package org.apache.maven.index;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0    
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  
24  import org.apache.lucene.store.Directory;
25  import org.apache.lucene.store.FSDirectory;
26  import org.apache.maven.index.context.IndexingContext;
27  
28  public class FSDirectoryDeleteTest
29      extends AbstractIndexCreatorHelper
30  {
31      protected NexusIndexer nexusIndexer;
32  
33      protected File repo = new File( getBasedir(), "src/test/nexus-13" );
34  
35      protected IndexingContext context;
36  
37      protected File indexDirFile = super.getDirectory( "fsdirectorytest/one" );
38  
39      protected Directory indexDir;
40  
41      protected IndexingContext otherContext;
42  
43      protected File otherIndexDirFile = super.getDirectory( "fsdirectorytest/other" );
44  
45      protected Directory otherIndexDir;
46  
47      @Override
48      protected void setUp()
49          throws Exception
50      {
51          super.setUp();
52  
53          nexusIndexer = lookup( NexusIndexer.class );
54  
55          indexDir = FSDirectory.open( indexDirFile );
56  
57          context = nexusIndexer.addIndexingContext( "one", "nexus-13", repo, indexDir, null, null, DEFAULT_CREATORS );
58  
59          nexusIndexer.scan( context );
60  
61          otherIndexDir = FSDirectory.open( otherIndexDirFile );
62  
63          otherContext =
64              nexusIndexer.addIndexingContext( "other", "nexus-13", repo, otherIndexDir, null, null, DEFAULT_CREATORS );
65  
66          nexusIndexer.scan( otherContext );
67      }
68  
69      @Override
70      protected void tearDown()
71          throws Exception
72      {
73          super.tearDown();
74  
75          nexusIndexer.removeIndexingContext( context, true );
76  
77          nexusIndexer.removeIndexingContext( otherContext, true );
78  
79          super.deleteDirectory( indexDirFile );
80  
81          super.deleteDirectory( otherIndexDirFile );
82      }
83  
84      public void testIndexAndDelete()
85          throws Exception
86      {
87          context.getIndexReader().maxDoc();
88  
89          otherContext.getIndexReader().maxDoc();
90  
91          context.replace( otherIndexDir );
92  
93          context.merge( otherIndexDir );
94      }
95  }