Skip to content

Commit e8e4015

Browse files
ahornaceVladimir Kotal
authored andcommitted
Add additional tests
1 parent 3e2dc55 commit e8e4015

File tree

7 files changed

+274
-0
lines changed

7 files changed

+274
-0
lines changed

suggester/src/test/java/org/opengrok/suggest/FieldWFSTCollectionTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,20 @@
4141
import java.io.IOException;
4242
import java.nio.file.Files;
4343
import java.nio.file.Path;
44+
import java.util.AbstractMap.SimpleEntry;
4445
import java.util.Arrays;
4546
import java.util.Collections;
4647
import java.util.HashSet;
4748
import java.util.List;
49+
import java.util.Map.Entry;
4850
import java.util.stream.Collectors;
4951

5052
import static junit.framework.Assert.assertTrue;
5153
import static junit.framework.TestCase.assertEquals;
5254
import static junit.framework.TestCase.assertFalse;
5355
import static org.hamcrest.MatcherAssert.assertThat;
5456
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
57+
import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
5558

5659
public class FieldWFSTCollectionTest {
5760

@@ -288,4 +291,20 @@ public void testUnknownFieldIgnored() throws IOException {
288291
assertTrue(res.isEmpty());
289292
}
290293

294+
@Test
295+
public void testGetSearchCountMapSorted() throws IOException {
296+
addText(FIELD, "test1 test2");
297+
init(true);
298+
299+
Term t1 = new Term(FIELD, "test1");
300+
Term t2 = new Term(FIELD, "test2");
301+
302+
f.incrementSearchCount(t1, 10);
303+
f.incrementSearchCount(t2, 5);
304+
305+
List<Entry<BytesRef, Integer>> searchCounts = f.getSearchCountsSorted(FIELD, 0, 10);
306+
307+
assertThat(searchCounts, contains(new SimpleEntry<>(t1.bytes(), 10), new SimpleEntry<>(t2.bytes(), 5)));
308+
}
309+
291310
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opengrok.suggest;
24+
25+
import org.junit.Test;
26+
27+
import java.io.IOException;
28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
30+
import java.time.Duration;
31+
32+
public class SuggesterTest {
33+
34+
@Test(expected = IllegalArgumentException.class)
35+
public void testNullSuggesterDir() {
36+
new Suggester(null, 10, Duration.ofMinutes(5), false, true, null);
37+
}
38+
39+
@Test(expected = IllegalArgumentException.class)
40+
public void testNullDuration() throws IOException {
41+
Path tempFile = Files.createTempFile("opengrok", "test");
42+
try {
43+
new Suggester(tempFile.toFile(), 10, null, false, true, null);
44+
} finally {
45+
tempFile.toFile().delete();
46+
}
47+
}
48+
49+
@Test(expected = IllegalArgumentException.class)
50+
public void testNegativeDuration() throws IOException {
51+
Path tempFile = Files.createTempFile("opengrok", "test");
52+
try {
53+
new Suggester(tempFile.toFile(), 10, Duration.ofMinutes(-4), false, true, null);
54+
} finally {
55+
tempFile.toFile().delete();
56+
}
57+
}
58+
59+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opengrok.suggest.query;
24+
25+
import org.apache.lucene.index.Term;
26+
import org.junit.Test;
27+
28+
import static org.junit.Assert.assertEquals;
29+
30+
public class SuggesterFuzzyQueryTest {
31+
32+
@Test
33+
public void testLength() {
34+
SuggesterFuzzyQuery q = new SuggesterFuzzyQuery(new Term("test", "test"), 2, 0);
35+
assertEquals("test".length(), q.length());
36+
}
37+
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opengrok.suggest.query;
24+
25+
import org.apache.lucene.index.Term;
26+
import org.junit.Test;
27+
28+
import static org.junit.Assert.assertEquals;
29+
30+
public class SuggesterPrefixQueryTest {
31+
32+
@Test
33+
public void testLength() {
34+
SuggesterPrefixQuery q = new SuggesterPrefixQuery(new Term("test", "prefix"));
35+
assertEquals("prefix".length(), q.length());
36+
}
37+
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opengrok.suggest.query;
24+
25+
import org.apache.lucene.util.BytesRef;
26+
import org.junit.Test;
27+
28+
import static org.junit.Assert.assertEquals;
29+
30+
public class SuggesterRangeQueryTest {
31+
32+
@Test
33+
public void testLengthLower() {
34+
SuggesterRangeQuery q = new SuggesterRangeQuery("test", new BytesRef("lowerTerm"), new BytesRef("upper"),
35+
true, false, SuggesterRangeQuery.SuggestPosition.LOWER);
36+
assertEquals("lowerTerm".length(), q.length());
37+
}
38+
39+
@Test
40+
public void testLengthUpper() {
41+
SuggesterRangeQuery q = new SuggesterRangeQuery("test", new BytesRef("l"), new BytesRef("upper"),
42+
true, false, SuggesterRangeQuery.SuggestPosition.UPPER);
43+
assertEquals("upper".length(), q.length());
44+
}
45+
46+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opengrok.suggest.query;
24+
25+
import org.apache.lucene.index.Term;
26+
import org.junit.Assert;
27+
import org.junit.Test;
28+
29+
public class SuggesterRegexpQueryTest {
30+
31+
@Test
32+
public void testLength() {
33+
SuggesterRegexpQuery q = new SuggesterRegexpQuery(new Term("test", ".*test"));
34+
Assert.assertEquals(".*test".length(), q.length());
35+
}
36+
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opengrok.suggest.query;
24+
25+
import org.apache.lucene.index.Term;
26+
import org.junit.Assert;
27+
import org.junit.Test;
28+
29+
public class SuggesterWildcardQueryTest {
30+
31+
@Test
32+
public void testLength() {
33+
SuggesterWildcardQuery q = new SuggesterWildcardQuery(new Term("test", "m?t"));
34+
Assert.assertEquals("m?t".length(), q.length());
35+
}
36+
37+
}

0 commit comments

Comments
 (0)