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 import org.apache.lucene.index.Term;
25 import org.apache.lucene.search.PrefixQuery;
26 import org.apache.lucene.store.ByteBuffersDirectory;
27 import org.apache.lucene.store.Directory;
28 import org.apache.maven.index.context.IndexingContext;
29
30 import static org.junit.Assert.assertEquals;
31
32 public abstract class AbstractNexusIndexerTest
33 extends AbstractIndexCreatorHelper
34 {
35 protected NexusIndexer nexusIndexer;
36
37 protected Directory indexDir = new ByteBuffersDirectory();
38
39 protected IndexingContext context;
40
41 @Override
42 public void setUp()
43 throws Exception
44 {
45
46 super.setUp();
47
48 nexusIndexer = lookup( NexusIndexer.class );
49 prepareNexusIndexer( nexusIndexer );
50 }
51
52 @Override
53 public void tearDown()
54 throws Exception
55 {
56 unprepareNexusIndexer( nexusIndexer );
57 super.tearDown();
58
59
60 }
61
62 protected abstract void prepareNexusIndexer( NexusIndexer nexusIndexer )
63 throws Exception;
64
65 protected void unprepareNexusIndexer( NexusIndexer nexusIndexer )
66 throws Exception
67 {
68 nexusIndexer.removeIndexingContext( context, false );
69 }
70
71 protected void assertGroup( int expected, String group, IndexingContext context )
72 throws IOException
73 {
74
75
76
77 Term term = new Term( ArtifactInfo.GROUP_ID, group );
78 PrefixQuery pq = new PrefixQuery( term );
79
80
81
82
83
84
85 FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( pq, context ) );
86 Collection<ArtifactInfo> artifacts = response.getResults();
87 assertEquals( artifacts.toString(), expected, artifacts.size() );
88 }
89
90 }