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