1 package org.apache.maven.index.archetype;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
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
84
85
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 }