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.File;
22 import java.util.Set;
23
24 import org.apache.lucene.index.Term;
25 import org.apache.lucene.search.WildcardQuery;
26 import org.apache.lucene.store.ByteBuffersDirectory;
27 import org.apache.lucene.store.Directory;
28 import org.apache.maven.index.context.IndexingContext;
29 import org.junit.Test;
30
31 import static org.junit.Assert.assertEquals;
32
33 public class Nexus3177HitLimitChecks extends AbstractNexusIndexerTest {
34 protected File repo = new File(getBasedir(), "src/test/repo");
35
36 protected Directory secondIndexDir = new ByteBuffersDirectory();
37
38 protected IndexingContext secondContext;
39
40 @Override
41 protected void prepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception {
42 context = nexusIndexer.addIndexingContext(
43 "nexus-3177", "nexus-3177", repo, indexDir, null, null, DEFAULT_CREATORS);
44
45 secondContext = nexusIndexer.addIndexingContext(
46 "nexus-3177b", "nexus-3177b", repo, secondIndexDir, null, null, DEFAULT_CREATORS);
47
48 nexusIndexer.scan(context);
49 nexusIndexer.scan(secondContext);
50 }
51
52 @Override
53 protected void unprepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception {
54 super.unprepareNexusIndexer(nexusIndexer);
55
56 nexusIndexer.removeIndexingContext(secondContext, false);
57 }
58
59
60
61
62
63
64
65
66
67 @Test
68 public void testHitLimitNotReachedSingleContext() throws Exception {
69 WildcardQuery q = new WildcardQuery(new Term(ArtifactInfo.UINFO, "*testng*"));
70
71 FlatSearchRequest request = new FlatSearchRequest(q);
72 request.setCount(5);
73
74 request.getContexts().add(context);
75
76 FlatSearchResponse response = nexusIndexer.searchFlat(request);
77 Set<ArtifactInfo> r = response.getResults();
78 assertEquals(r.toString(), 4, r.size());
79 assertEquals(r.toString(), 4, response.getTotalHitsCount());
80 }
81
82 @Test
83 public void testHitLimitEqualSingleContext() throws Exception {
84 WildcardQuery q = new WildcardQuery(new Term(ArtifactInfo.UINFO, "*testng*"));
85
86 FlatSearchRequest request = new FlatSearchRequest(q);
87 request.setCount(4);
88
89 request.getContexts().add(context);
90
91 FlatSearchResponse response = nexusIndexer.searchFlat(request);
92 Set<ArtifactInfo> r = response.getResults();
93 assertEquals(r.toString(), 4, r.size());
94 assertEquals(r.toString(), 4, response.getTotalHitsCount());
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 @Test
114 public void testHitLimitNotReachedMultipleContexts() throws Exception {
115 WildcardQuery q = new WildcardQuery(new Term(ArtifactInfo.UINFO, "*testng*"));
116
117 FlatSearchRequest request = new FlatSearchRequest(q);
118 request.setCount(9);
119
120 request.setArtifactInfoComparator(ArtifactInfo.REPOSITORY_VERSION_COMPARATOR);
121 request.getContexts().add(context);
122 request.getContexts().add(secondContext);
123
124 FlatSearchResponse response = nexusIndexer.searchFlat(request);
125 Set<ArtifactInfo> r = response.getResults();
126 assertEquals(r.toString(), 8, r.size());
127 assertEquals(r.toString(), 8, response.getTotalHitsCount());
128 }
129
130 @Test
131 public void testHitLimitEqualMultipleContexts() throws Exception {
132 WildcardQuery q = new WildcardQuery(new Term(ArtifactInfo.UINFO, "*testng*"));
133
134 FlatSearchRequest request = new FlatSearchRequest(q);
135 request.setCount(8);
136
137 request.setArtifactInfoComparator(ArtifactInfo.REPOSITORY_VERSION_COMPARATOR);
138 request.getContexts().add(context);
139 request.getContexts().add(secondContext);
140
141 FlatSearchResponse response = nexusIndexer.searchFlat(request);
142 Set<ArtifactInfo> r = response.getResults();
143 assertEquals(r.toString(), 8, r.size());
144 assertEquals(r.toString(), 8, response.getTotalHitsCount());
145 }
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 }