View Javadoc

1   package org.apache.maven.index.archetype;
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  import java.io.IOException;
24  
25  import org.apache.lucene.store.Directory;
26  import org.apache.lucene.store.FSDirectory;
27  import org.apache.lucene.store.RAMDirectory;
28  import org.apache.maven.archetype.catalog.ArchetypeCatalog;
29  import org.apache.maven.archetype.source.ArchetypeDataSource;
30  import org.apache.maven.index.AbstractIndexCreatorHelper;
31  import org.apache.maven.index.NexusIndexer;
32  import org.apache.maven.index.context.IndexingContext;
33  import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
34  
35  public class NexusArchetypeDataSourceTest
36      extends AbstractIndexCreatorHelper
37  {
38      private IndexingContext context;
39  
40      private NexusIndexer nexusIndexer;
41  
42      // private IndexUpdater indexUpdater;
43  
44      private NexusArchetypeDataSource nexusArchetypeDataSource;
45  
46      protected void setUp()
47          throws Exception
48      {
49          super.setUp();
50  
51          prepare( true );
52      }
53  
54      private void prepare( boolean inRam )
55          throws Exception, IOException, UnsupportedExistingLuceneIndexException
56      {
57          nexusIndexer = lookup( NexusIndexer.class );
58  
59          // indexUpdater = lookup( IndexUpdater.class );
60  
61          Directory indexDir = null;
62  
63          if ( inRam )
64          {
65              indexDir = new RAMDirectory();
66          }
67          else
68          {
69              File indexDirFile = super.getDirectory( "index/test" );
70  
71              super.deleteDirectory( indexDirFile );
72  
73              indexDir = FSDirectory.open( indexDirFile );
74          }
75  
76          File repo = new File( getBasedir(), "src/test/repo" );
77  
78          context =
79              nexusIndexer.addIndexingContext( "test", "public", repo, indexDir,
80                  "http://repository.sonatype.org/content/groups/public/", null, DEFAULT_CREATORS );
81          nexusIndexer.scan( context );
82  
83          // to update, uncomment this
84          // IndexUpdateRequest updateRequest = new IndexUpdateRequest( context );
85          // indexUpdater.fetchAndUpdateIndex( updateRequest );
86  
87          nexusArchetypeDataSource = (NexusArchetypeDataSource) lookup( ArchetypeDataSource.class, "nexus" );
88      }
89  
90      public void testArchetype()
91          throws Exception
92      {
93          ArchetypeCatalog catalog = nexusArchetypeDataSource.getArchetypeCatalog( null );
94  
95          assertEquals( "Not correct numbers of archetypes in catalog!", 4, catalog.getArchetypes().size() );
96      }
97  
98  }