1 package org.apache.maven.index;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.util.Collection;
24
25 import org.apache.lucene.index.Term;
26 import org.apache.lucene.search.PrefixQuery;
27 import org.apache.lucene.store.Directory;
28 import org.apache.lucene.store.RAMDirectory;
29 import org.apache.maven.index.ArtifactInfo;
30 import org.apache.maven.index.FlatSearchRequest;
31 import org.apache.maven.index.FlatSearchResponse;
32 import org.apache.maven.index.NexusIndexer;
33 import org.apache.maven.index.context.IndexingContext;
34
35 public abstract class AbstractNexusIndexerTest
36 extends AbstractIndexCreatorHelper
37 {
38 protected NexusIndexer nexusIndexer;
39
40 protected Directory indexDir = new RAMDirectory();
41
42 protected IndexingContext context;
43
44 @Override
45 protected void setUp()
46 throws Exception
47 {
48 super.setUp();
49
50 nexusIndexer = lookup( NexusIndexer.class );
51 prepareNexusIndexer( nexusIndexer );
52 }
53
54 @Override
55 protected void tearDown()
56 throws Exception
57 {
58 unprepareNexusIndexer( nexusIndexer );
59 super.tearDown();
60
61
62 }
63
64 protected abstract void prepareNexusIndexer( NexusIndexer nexusIndexer )
65 throws Exception;
66
67 protected void unprepareNexusIndexer( NexusIndexer nexusIndexer )
68 throws Exception
69 {
70 nexusIndexer.removeIndexingContext( context, false );
71 }
72
73 protected void assertGroup( int expected, String group, IndexingContext context )
74 throws IOException
75 {
76
77
78
79 Term term = new Term( ArtifactInfo.GROUP_ID, group );
80 PrefixQuery pq = new PrefixQuery( term );
81
82
83
84
85
86
87 FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( pq, context ) );
88 Collection<ArtifactInfo> artifacts = response.getResults();
89 assertEquals( artifacts.toString(), expected, artifacts.size() );
90 }
91
92 }