diff options
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java | 341 |
1 files changed, 167 insertions, 174 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index 7cd7e20b76f..f8a77445a40 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -45,8 +45,8 @@ import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; import com.yahoo.yolean.Exceptions; import org.json.JSONObject; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -59,14 +59,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * @author bratseth @@ -74,10 +67,10 @@ import static org.junit.Assert.fail; public class QueryTestCase { @Test - public void testIt() throws Exception { + void testIt() throws Exception { JSONObject newroot = new JSONObject("{\"key\": 3}"); var hit = new FastHit(); - hit.setField("data", (JsonProducer)s -> s.append(newroot)); + hit.setField("data", (JsonProducer) s -> s.append(newroot)); var field = hit.getField("data"); if (field instanceof JsonProducer) { System.out.println((((JsonProducer) field).toJson())); @@ -85,7 +78,7 @@ public class QueryTestCase { } @Test - public void testSimpleFunctionality() { + void testSimpleFunctionality() { Query q = new Query(QueryTestCase.httpEncode("/sdfsd.html?query=this is a simple query&aParameter")); assertEquals("this is a simple query", q.getModel().getQueryString()); assertNotNull(q.getModel().getQueryTree()); @@ -105,23 +98,23 @@ public class QueryTestCase { } // TODO: YQL work in progress (jon) - @Ignore + @Disabled @Test - public void testSimpleProgram() { + void testSimpleProgram() { Query q = new Query(httpEncode("?program=select * from * where myfield contains(word)")); assertEquals("", q.getModel().getQueryTree().toString()); } // TODO: YQL work in progress (jon) - @Ignore + @Disabled @Test - public void testSimpleProgramParameterAlias() { + void testSimpleProgramParameterAlias() { Query q = new Query(httpEncode("/sdfsd.html?yql=select * from source where myfield contains(word)")); assertEquals("", q.getModel().getQueryTree().toString()); } @Test - public void testClone() { + void testClone() { Query q = new Query(httpEncode("/sdfsd.html?query=this+is+a+simple+query&aParameter")); q.getPresentation().setHighlight(new Highlight()); Query p = q.clone(); @@ -157,10 +150,10 @@ public class QueryTestCase { } @Test - public void testCloneWithConnectivity() { + void testCloneWithConnectivity() { List<String> l = List.of("a", "b", "c", "a"); printIt(l.stream().filter(i -> isA(i)).collect(Collectors.toList())); - printIt(l.stream().filter(i -> ! isA(i)).collect(Collectors.toList())); + printIt(l.stream().filter(i -> !isA(i)).collect(Collectors.toList())); Query q = new Query(); WordItem a = new WordItem("a"); @@ -200,18 +193,18 @@ public class QueryTestCase { Query qClone = q.clone(); assertEquals(q, qClone); - RankItem rankClone = (RankItem)qClone.getModel().getQueryTree().getRoot(); - AndItem and1Clone = (AndItem)rankClone.getItem(0); - AndItem and2Clone = (AndItem)rankClone.getItem(1); - OrItem orClone = (OrItem)and1Clone.getItem(2); + RankItem rankClone = (RankItem) qClone.getModel().getQueryTree().getRoot(); + AndItem and1Clone = (AndItem) rankClone.getItem(0); + AndItem and2Clone = (AndItem) rankClone.getItem(1); + OrItem orClone = (OrItem) and1Clone.getItem(2); - WordItem aClone = (WordItem)and1Clone.getItem(0); - WordItem bClone = (WordItem)and1Clone.getItem(1); - WordItem cClone = (WordItem)orClone.getItem(0); - WordItem dClone = (WordItem)orClone.getItem(1); - WordItem eClone = (WordItem)and1Clone.getItem(3); - WordItem fClone = (WordItem)and2Clone.getItem(0); - WordItem gClone = (WordItem)and2Clone.getItem(1); + WordItem aClone = (WordItem) and1Clone.getItem(0); + WordItem bClone = (WordItem) and1Clone.getItem(1); + WordItem cClone = (WordItem) orClone.getItem(0); + WordItem dClone = (WordItem) orClone.getItem(1); + WordItem eClone = (WordItem) and1Clone.getItem(3); + WordItem fClone = (WordItem) and2Clone.getItem(0); + WordItem gClone = (WordItem) and2Clone.getItem(1); assertTrue(rankClone != rank); assertTrue(and1Clone != and1); @@ -226,12 +219,12 @@ public class QueryTestCase { assertTrue(fClone != f); assertTrue(gClone != g); - assertTrue(aClone.getConnectedItem() == bClone); - assertTrue(bClone.getConnectedItem() == cClone); - assertTrue(cClone.getConnectedItem() == dClone); - assertTrue(dClone.getConnectedItem() == eClone); - assertTrue(eClone.getConnectedItem() == fClone); - assertTrue(fClone.getConnectedItem() == gClone); + assertEquals(aClone.getConnectedItem(), bClone); + assertEquals(bClone.getConnectedItem(), cClone); + assertEquals(cClone.getConnectedItem(), dClone); + assertEquals(dClone.getConnectedItem(), eClone); + assertEquals(eClone.getConnectedItem(), fClone); + assertEquals(fClone.getConnectedItem(), gClone); double delta = 0.0000001; assertEquals(0.1, aClone.getConnectivity(), delta); @@ -243,7 +236,7 @@ public class QueryTestCase { } @Test - public void test_that_cloning_preserves_timeout() { + void test_that_cloning_preserves_timeout() { Query original = new Query(); original.setTimeout(9876L); @@ -252,7 +245,7 @@ public class QueryTestCase { } @Test - public void testTimeout() { + void testTimeout() { // yes, this test depends on numbers which have exact IEEE representations Query q = new Query(httpEncode("/search?timeout=500")); assertEquals(500000L, q.getTimeout()); @@ -283,20 +276,20 @@ public class QueryTestCase { assertEquals(42000, q.getTimeout()); assertEquals(0, q.errors().size()); - q=new Query(); + q = new Query(); q.setTimeout(53L); assertEquals(53L, q.properties().get("timeout")); assertEquals(53L, q.getTimeout()); // This is the unfortunate consequence of this legacy: - q=new Query(); + q = new Query(); q.properties().set("timeout", 53L); assertEquals(53L * 1000, q.properties().get("timeout")); assertEquals(53L * 1000, q.getTimeout()); } @Test - public void testUnparseableTimeout() { + void testUnparseableTimeout() { try { new Query(httpEncode("/search?timeout=nalle")); fail("Above statement should throw"); @@ -307,7 +300,7 @@ public class QueryTestCase { } @Test - public void testCloneTimeout() { + void testCloneTimeout() { Query q = new Query(httpEncode("/search?timeout=300ms")); assertEquals(300, q.getTimeout()); Query clonedQ = q.clone(); @@ -315,7 +308,7 @@ public class QueryTestCase { } @Test - public void testQueryProfileSubstitution1() { + void testQueryProfileSubstitution1() { QueryProfile profile = new QueryProfile("myProfile"); profile.set("myField", "Profile: %{queryProfile}", null); Query q = new Query(QueryTestCase.httpEncode("/search?queryProfile=myProfile"), profile.compile(null)); @@ -323,7 +316,7 @@ public class QueryTestCase { } @Test - public void testQueryProfileSourceAccess() { + void testQueryProfileSourceAccess() { QueryProfile profile = new QueryProfile("myProfile"); profile.set("myField", "Profile: %{queryProfile}", null); Query query = new Query(QueryTestCase.httpEncode("/search?queryProfile=myProfile"), profile.compile(null)); @@ -333,7 +326,7 @@ public class QueryTestCase { } @Test - public void testBooleanParameter() { + void testBooleanParameter() { QueryProfile profile = new QueryProfile("myProfile"); Query query = new Query("/?query=something&ranking.softtimeout.enable=false", profile.compile(null)); assertFalse(query.properties().getBoolean("ranking.softtimeout.enable")); @@ -341,7 +334,7 @@ public class QueryTestCase { } @Test - public void testQueryProfileSubstitution2() { + void testQueryProfileSubstitution2() { QueryProfile profile = new QueryProfile("myProfile"); profile.set("model.language", "en-US", null); profile.set("myField", "Language: %{lang}", null); @@ -350,7 +343,7 @@ public class QueryTestCase { } @Test - public void testQueryProfileSubstitution3() { + void testQueryProfileSubstitution3() { QueryProfile profile = new QueryProfile("myProfile"); profile.set("model.locale", "en-US", null); profile.set("myField", "Language: %{lang}, locale: %{locale}", null); @@ -359,7 +352,7 @@ public class QueryTestCase { } @Test - public void testTimeoutInRequestOverridesQueryProfile() { + void testTimeoutInRequestOverridesQueryProfile() { QueryProfile profile = new QueryProfile("test"); profile.set("timeout", 318, null); Query q = new Query(QueryTestCase.httpEncode("/search?timeout=500"), profile.compile(null)); @@ -367,7 +360,7 @@ public class QueryTestCase { } @Test - public void testQueryProfileClearAndSet() { + void testQueryProfileClearAndSet() { QueryProfile profile = new QueryProfile("myProfile"); profile.set("b", "b-value", null); Query q = new Query(QueryTestCase.httpEncode("/search?queryProfile=myProfile"), profile.compile(null)); @@ -375,7 +368,7 @@ public class QueryTestCase { assertContains(q.properties().listProperties("b"), "b-value"); q.properties().set("b", null, null); - assertContains(q.properties().listProperties("b"), (Object)null); + assertContains(q.properties().listProperties("b"), (Object) null); q.properties().set("b", "b-value", null); assertEquals("b-value", q.properties().get("b")); @@ -383,7 +376,7 @@ public class QueryTestCase { } @Test - public void testQueryProfileClearValue() { + void testQueryProfileClearValue() { QueryProfile profile = new QueryProfile("myProfile"); profile.set("a", "a-value", null); profile.set("b", "b-value", null); @@ -397,10 +390,10 @@ public class QueryTestCase { assertContains(q.properties().listProperties("b"), "b-value", "b.c-value", "b.d-value"); q.properties().set("a", null, null); - assertEquals(null, q.properties().get("a")); + assertNull(q.properties().get("a")); q.properties().set("b", null, null); - assertEquals(null, q.properties().get("b")); + assertNull(q.properties().get("b")); assertEquals("b.c-value", q.properties().get("b.c")); assertEquals("b.d-value", q.properties().get("b.d")); assertContains(q.properties().listProperties("b"), null, "b.c-value", "b.d-value"); @@ -413,67 +406,67 @@ public class QueryTestCase { assertContains(q.properties().listProperties("b"), "b-value", "b.c-value", "b.d-value", "b.e-value", "b.f-value"); q.properties().clearAll("b"); - assertEquals(null, q.properties().get("b")); - assertEquals(null, q.properties().get("b.c")); - assertEquals(null, q.properties().get("b.d")); - assertEquals(null, q.properties().get("b.e")); - assertEquals(null, q.properties().get("b.f")); - assertContains(q.properties().listProperties("b"), (Object)null); + assertNull(q.properties().get("b")); + assertNull(q.properties().get("b.c")); + assertNull(q.properties().get("b.d")); + assertNull(q.properties().get("b.e")); + assertNull(q.properties().get("b.f")); + assertContains(q.properties().listProperties("b"), (Object) null); } @Test - public void testNotEqual() { + void testNotEqual() { Query q = new Query("/?query=something+test&nocache"); Query p = new Query("/?query=something+test"); - assertEquals(q,p); - assertEquals(q.hashCode(),p.hashCode()); + assertEquals(q, p); + assertEquals(q.hashCode(), p.hashCode()); Query r = new Query("?query=something+test&hits=5"); - assertNotSame(q,r); - assertNotSame(q.hashCode(),r.hashCode()); + assertNotSame(q, r); + assertNotSame(q.hashCode(), r.hashCode()); } @Test - public void testEqual() { - assertEquals(new Query("?query=12").hashCode(),new Query("?query=12").hashCode()); - assertEquals(new Query("?query=12"),new Query("?query=12")); + void testEqual() { + assertEquals(new Query("?query=12").hashCode(), new Query("?query=12").hashCode()); + assertEquals(new Query("?query=12"), new Query("?query=12")); } @Test - public void testUtf8Decoding() { + void testUtf8Decoding() { Query q = new Query("/?query=beyonc%C3%A9"); assertEquals("WEAKAND(100) beyonc\u00e9", q.getModel().getQueryTree().toString()); } @Test - public void testQueryProfileInSubstitution() { + void testQueryProfileInSubstitution() { QueryProfile testProfile = new QueryProfile("test"); testProfile.setOverridable("u", false, DimensionValues.empty); - testProfile.set("d","e", null); - testProfile.set("u","11", null); + testProfile.set("d", "e", null); + testProfile.set("u", "11", null); testProfile.set("foo.bar", "wiz", null); Query q = new Query(QueryTestCase.httpEncode("?query=a:>5&a=b&traceLevel=5&sources=a,b&u=12&foo.bar2=wiz2&c.d=foo&queryProfile=test"), - testProfile.compile(null)); + testProfile.compile(null)); String trace = q.getContext(false).getTrace().toString(); String[] traceLines = trace.split("\n"); } @Test - public void testDefaultIndex() { + void testDefaultIndex() { Query q = new Query("?query=hi%20hello%20keyword:kanoo%20" + - "default:munkz%20%22phrases+too%22&default-index=def"); + "default:munkz%20%22phrases+too%22&default-index=def"); assertEquals("WEAKAND(100) def:hi def:hello keyword:kanoo default:munkz def:\"phrases too\"", - q.getModel().getQueryTree().toString()); + q.getModel().getQueryTree().toString()); } @Test - public void testHashCode() { + void testHashCode() { Query p = new Query("?query=foo&type=any"); Query q = new Query("?query=foo&type=all"); assertTrue(p.hashCode() != q.hashCode()); } @Test - public void testSimpleQueryParsing() { + void testSimpleQueryParsing() { Query q = new Query("/search?query=foobar&offset=10&hits=20"); assertEquals("WEAKAND(100) foobar", q.getModel().getQueryTree().toString()); assertEquals(10, q.getOffset()); @@ -482,15 +475,15 @@ public class QueryTestCase { /** "input.*" is an alias for "ranking.feature.*", but just "input" is not */ @Test - public void testPrefixAlias() { + void testPrefixAlias() { Query q = new Query("/search?query=foobar&input=foo", - new QueryProfile("test").compile(null)); + new QueryProfile("test").compile(null)); assertEquals("foo", q.properties().get("input")); } /** Test that GET parameter names are case in-sensitive */ @Test - public void testGETParametersCase() { + void testGETParametersCase() { Query q = new Query("?QUERY=testing&hits=10&oFfSeT=10"); assertEquals("testing", q.getModel().getQueryString()); assertEquals(10, q.getHits()); @@ -499,19 +492,19 @@ public class QueryTestCase { /** Test that we get the last value if a parameter is assigned multiple times */ @Test - public void testRepeatedParameter() { + void testRepeatedParameter() { Query q = new Query("?query=test&hits=5&hits=10"); assertEquals(10, q.getHits()); } @Test - public void testNoCache() { + void testNoCache() { Query q = new Query("search?query=foobar&nocache"); assertTrue(q.getNoCache()); } @Test - public void testSessionCache() { + void testSessionCache() { Query q = new Query("search?query=foobar&groupingSessionCache"); assertTrue(q.getGroupingSessionCache()); q = new Query("search?query=foobar"); @@ -531,7 +524,7 @@ public class QueryTestCase { } @Test - public void testSetting() { + void testSetting() { Query q = new Query(); q.properties().set("test", "test"); assertEquals(q.properties().get("test"), "test"); @@ -544,21 +537,21 @@ public class QueryTestCase { } @Test - public void testAlias() { + void testAlias() { Query q = new Query("search?query=testing&language=en"); assertEquals(q.getModel().getLanguage(), q.properties().get("model.language")); } @Test - public void testTracing() { + void testTracing() { Query q = new Query("?query=foo&type=all&traceLevel=2"); assertEquals(2, q.getTrace().getLevel()); q.trace(true, 1, "trace1"); - q.trace(false,2, "trace2"); + q.trace(false, 2, "trace2"); q.trace(true, 3, "Ignored"); q.trace(true, 2, "trace3-1", ", ", "trace3-2"); - q.trace(false,1, "trace4-1", ", ", "trace4-2"); - q.trace(false,3, "Ignored-1", "Ignored-2"); + q.trace(false, 1, "trace4-1", ", ", "trace4-2"); + q.trace(false, 3, "Ignored-1", "Ignored-2"); Set<String> traces = new HashSet<>(); for (String trace : q.getContext(true).getTrace().traceNode().descendants(String.class)) traces.add(trace); @@ -569,10 +562,10 @@ public class QueryTestCase { } @Test - public void testNullTracing() { + void testNullTracing() { Query q = new Query("?query=foo&traceLevel=2"); assertEquals(2, q.getTrace().getLevel()); - q.trace(false,2, "trace2 ", null); + q.trace(false, 2, "trace2 ", null); Set<String> traces = new HashSet<>(); for (String trace : q.getContext(true).getTrace().traceNode().descendants(String.class)) traces.add(trace); @@ -580,20 +573,20 @@ public class QueryTestCase { } @Test - public void testExplain() { + void testExplain() { Query q = new Query("?query=foo&explainLevel=2"); assertEquals(2, q.getTrace().getExplainLevel()); assertEquals(0, q.getTrace().getLevel()); } @Test - public void testQueryPropertyResolveTracing() { + void testQueryPropertyResolveTracing() { QueryProfile testProfile = new QueryProfile("test"); testProfile.setOverridable("u", false, DimensionValues.empty); - testProfile.set("d","e", null); - testProfile.set("u","11", null); + testProfile.set("d", "e", null); + testProfile.set("u", "11", null); testProfile.set("foo.bar", "wiz", null); - Query q = new Query(QueryTestCase.httpEncode("?query=a:>5&a=b&traceLevel=5&sources=a,b&u=12&foo.bar2=wiz2&c.d=foo&queryProfile=test"),testProfile.compile(null)); + Query q = new Query(QueryTestCase.httpEncode("?query=a:>5&a=b&traceLevel=5&sources=a,b&u=12&foo.bar2=wiz2&c.d=foo&queryProfile=test"), testProfile.compile(null)); String trace = q.getContext(false).getTrace().toString(); String[] traceLines = trace.split("\n"); assertTrue(contains("query: a:>5 (from request)", traceLines)); @@ -605,7 +598,7 @@ public class QueryTestCase { } @Test - public void testNonleafInRequestDoesNotOverrideProfile() { + void testNonleafInRequestDoesNotOverrideProfile() { QueryProfile testProfile = new QueryProfile("test"); testProfile.set("a.b", "foo", null); testProfile.freeze(); @@ -622,7 +615,7 @@ public class QueryTestCase { } @Test - public void testQueryPropertyResolveTracing2() { + void testQueryPropertyResolveTracing2() { QueryProfile defaultProfile = new QueryProfile("default"); defaultProfile.freeze(); Query q = new Query(QueryTestCase.httpEncode("?query=dvd&a.b=foo&tracelevel=9"), defaultProfile.compile(null)); @@ -633,7 +626,7 @@ public class QueryTestCase { } @Test - public void testNativeProperties() { + void testNativeProperties() { Set<String> nativeProperties = Query.nativeProperties.stream().map(CompoundName::toString).collect(Collectors.toSet()); // Sample the content assertTrue(nativeProperties.contains("hits")); @@ -642,16 +635,16 @@ public class QueryTestCase { } @Test - public void testQueryPropertyListingAndTrace() { + void testQueryPropertyListingAndTrace() { QueryProfile defaultProfile = new QueryProfile("default"); defaultProfile.setDimensions(new String[]{"x"}); - defaultProfile.set("a.b","a.b-x1-value", new String[] {"x1"}, null); + defaultProfile.set("a.b", "a.b-x1-value", new String[]{"x1"}, null); defaultProfile.set("a.b", "a.b-x2-value", new String[]{"x2"}, null); defaultProfile.freeze(); { - Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"),defaultProfile.compile(null)); - Map<String,Object> propertyList = q.properties().listProperties(); + Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null)); + Map<String, Object> propertyList = q.properties().listProperties(); assertEquals("a.b-x1-value", propertyList.get("a.b")); String trace = q.getContext(false).getTrace().toString(); String[] traceLines = trace.split("\n"); @@ -660,14 +653,14 @@ public class QueryTestCase { { Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null)); - Map<String,Object> propertyList = q.properties().listProperties("a"); + Map<String, Object> propertyList = q.properties().listProperties("a"); assertEquals(1, propertyList.size()); assertEquals("a.b-x1-value", propertyList.get("b")); } { - Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x2"),defaultProfile.compile(null)); - Map<String,Object> propertyList = q.properties().listProperties(); + Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x2"), defaultProfile.compile(null)); + Map<String, Object> propertyList = q.properties().listProperties(); assertEquals("a.b-x2-value", propertyList.get("a.b")); String trace = q.getContext(false).getTrace().toString(); String[] traceLines = trace.split("\n"); @@ -676,45 +669,45 @@ public class QueryTestCase { } @Test - public void testQueryPropertyListingThreeLevel() { + void testQueryPropertyListingThreeLevel() { QueryProfile defaultProfile = new QueryProfile("default"); - defaultProfile.setDimensions(new String[] {"x"}); + defaultProfile.setDimensions(new String[]{"x"}); defaultProfile.set("a.b.c", "a.b.c-x1-value", new String[]{"x1"}, null); defaultProfile.set("a.b.c", "a.b.c-x2-value", new String[]{"x2"}, null); defaultProfile.freeze(); { - Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"),defaultProfile.compile(null)); - Map<String,Object> propertyList = q.properties().listProperties(); + Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null)); + Map<String, Object> propertyList = q.properties().listProperties(); assertEquals("a.b.c-x1-value", propertyList.get("a.b.c")); } { - Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"),defaultProfile.compile(null)); - Map<String,Object> propertyList = q.properties().listProperties("a"); + Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null)); + Map<String, Object> propertyList = q.properties().listProperties("a"); assertEquals(1, propertyList.size()); assertEquals("a.b.c-x1-value", propertyList.get("b.c")); } { - Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"),defaultProfile.compile(null)); - Map<String,Object> propertyList = q.properties().listProperties("a.b"); + Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x1"), defaultProfile.compile(null)); + Map<String, Object> propertyList = q.properties().listProperties("a.b"); assertEquals(1, propertyList.size()); assertEquals("a.b.c-x1-value", propertyList.get("c")); } { - Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x2"),defaultProfile.compile(null)); - Map<String,Object> propertyList = q.properties().listProperties(); + Query q = new Query(QueryTestCase.httpEncode("?tracelevel=9&x=x2"), defaultProfile.compile(null)); + Map<String, Object> propertyList = q.properties().listProperties(); assertEquals("a.b.c-x2-value", propertyList.get("a.b.c")); } } @Test - public void testQueryPropertyReplacement() { + void testQueryPropertyReplacement() { QueryProfile defaultProfile = new QueryProfile("default"); - defaultProfile.set("model.queryString","myquery", null); - defaultProfile.set("queryUrl","http://provider:80?query=%{model.queryString}", null); + defaultProfile.set("model.queryString", "myquery", null); + defaultProfile.set("queryUrl", "http://provider:80?query=%{model.queryString}", null); defaultProfile.freeze(); Query q1 = new Query(QueryTestCase.httpEncode(""), defaultProfile.compile(null)); @@ -725,17 +718,17 @@ public class QueryTestCase { assertEquals("foo", q2.getModel().getQueryString()); assertEquals("http://provider:80?query=foo", q2.properties().get("queryUrl")); - Query q3 = new Query(QueryTestCase.httpEncode("?query=foo"),defaultProfile.compile(null)); - assertEquals("foo",q3.getModel().getQueryString()); - assertEquals("http://provider:80?query=foo",q3.properties().get("queryUrl")); + Query q3 = new Query(QueryTestCase.httpEncode("?query=foo"), defaultProfile.compile(null)); + assertEquals("foo", q3.getModel().getQueryString()); + assertEquals("http://provider:80?query=foo", q3.properties().get("queryUrl")); - Query q4 = new Query(QueryTestCase.httpEncode("?query=foo"),defaultProfile.compile(null)); + Query q4 = new Query(QueryTestCase.httpEncode("?query=foo"), defaultProfile.compile(null)); q4.getModel().setQueryString("bar"); - assertEquals("http://provider:80?query=bar",q4.properties().get("queryUrl")); + assertEquals("http://provider:80?query=bar", q4.properties().get("queryUrl")); } @Test - public void testNoQueryString() { + void testNoQueryString() { Query q = new Query(httpEncode("?tracelevel=1")); Chain<Searcher> chain = new Chain<>(new RandomSearcher()); new Execution(chain, Execution.Context.createContextStub()).search(q); @@ -743,7 +736,7 @@ public class QueryTestCase { } @Test - public void testSetCollapseField() { + void testSetCollapseField() { Query q = new Query(httpEncode("?collapsefield=foo&presentation.format=tiled")); assertEquals("foo", q.properties().get("collapsefield")); assertEquals("tiled", q.properties().get("presentation.format")); @@ -751,44 +744,44 @@ public class QueryTestCase { } @Test - public void testSetNullProperty() { + void testSetNullProperty() { QueryProfile profile = new QueryProfile("test"); - profile.set("property","initialValue", null); + profile.set("property", "initialValue", null); Query query = new Query(httpEncode("?query=test"), profile.compile(null)); - assertEquals("initialValue",query.properties().get("property")); + assertEquals("initialValue", query.properties().get("property")); query.properties().set("property", null); assertNull(query.properties().get("property")); } @Test - public void testSetNullPropertyNoQueryProfile() { + void testSetNullPropertyNoQueryProfile() { Query query = new Query(); query.properties().set("a", null); assertNull(query.properties().get("a")); } @Test - public void testMissingParameter() { + void testMissingParameter() { Query q = new Query("?query=foo&hits="); assertEquals(0, q.errors().size()); } @Test - public void testModelProperties() { + void testModelProperties() { { Query query = new Query(); query.properties().set("model.searchPath", "foo"); - assertEquals("Set dynamic get dynamic works","foo", query.properties().get("model.searchPath")); - assertEquals("Set dynamic get static works","foo", query.getModel().getSearchPath()); + assertEquals("foo", query.properties().get("model.searchPath"), "Set dynamic get dynamic works"); + assertEquals("foo", query.getModel().getSearchPath(), "Set dynamic get static works"); Map<String, Object> properties = query.properties().listProperties(); - assertEquals("Listing built-in properties works", "foo", properties.get("model.searchPath")); + assertEquals("foo", properties.get("model.searchPath"), "Listing built-in properties works"); } { Query query = new Query(); query.getModel().setSearchPath("foo"); - assertEquals("Set static get dynamic works","foo", query.properties().get("model.searchPath")); - assertEquals("Set static get static works","foo", query.getModel().getSearchPath()); + assertEquals("foo", query.properties().get("model.searchPath"), "Set static get dynamic works"); + assertEquals("foo", query.getModel().getSearchPath(), "Set static get static works"); } { @@ -801,7 +794,7 @@ public class QueryTestCase { } @Test - public void testThatSessionIdIsUniquePerQuery() { + void testThatSessionIdIsUniquePerQuery() { Query q = new Query(); assertNull(q.getSessionId()); assertNull(q.getSessionId()); @@ -816,8 +809,9 @@ public class QueryTestCase { assertNotEquals(q.getSessionId(), q2.getSessionId("node-0")); assertNotEquals(q.getSessionId().toString(), q2.getSessionId("node-0").toString()); } + @Test - public void testThatCloneGetANewSessionId() { + void testThatCloneGetANewSessionId() { Query q = new Query(); q.getSessionId("node-0"); Query clonedQ = q.clone(); @@ -826,7 +820,7 @@ public class QueryTestCase { } @Test - public void testThatSessionIdIsUniquePerRankProfilePerQuery() { + void testThatSessionIdIsUniquePerRankProfilePerQuery() { Query q = new Query(); SessionId s1 = q.getSessionId("node-0"); q.getRanking().setProfile("my-profile"); @@ -835,7 +829,7 @@ public class QueryTestCase { } @Test - public void testThatSessionIdIsNotSharedIfCreatedAfterClone() { + void testThatSessionIdIsNotSharedIfCreatedAfterClone() { Query q = new Query(); Query q2 = q.clone(); assertNull(q.getSessionId()); @@ -849,7 +843,7 @@ public class QueryTestCase { } @Test - public void testPositiveTerms() { + void testPositiveTerms() { Query q = new Query(httpEncode("/?query=-a \"b c\" d e")); Item i = q.getModel().getQueryTree().getRoot(); List<IndexedItem> l = QueryTree.getPositiveTerms(i); @@ -857,18 +851,18 @@ public class QueryTestCase { } @Test - public void testHeuristicLanguageDetectionTextExtraction() { + void testHeuristicLanguageDetectionTextExtraction() { assertDetectionText("b ", "a:b", "text:a", "text:default"); assertDetectionText("b ", "b", "text:default"); - assertDetectionText("b ", "b","text:b", "text:default"); - assertDetectionText("a b ", "a:b","text:b", "text:default"); - assertDetectionText("foo bar fuz ", "foo a:bar --() fuz","text:a", "text:default"); - assertDetectionText(" 彭 博士 觀 風向 彭 博士 觀 風向 彭 博士 觀 風向 ","headline:\"彭 博士 觀 風向\" content:\"彭 博士 觀 風向\" description:\"彭 博士 觀 風向\" sddocname:contentindexing!0 embargo:<1484665288753!0 expires:>1484665288753!0", - "text:headline", "text:content", "text:description", "text:default", "nontext:tags", "nontext:sddocname", "nontext:embargo", "nontext:expires"); + assertDetectionText("b ", "b", "text:b", "text:default"); + assertDetectionText("a b ", "a:b", "text:b", "text:default"); + assertDetectionText("foo bar fuz ", "foo a:bar --() fuz", "text:a", "text:default"); + assertDetectionText(" 彭 博士 觀 風向 彭 博士 觀 風向 彭 博士 觀 風向 ", "headline:\"彭 博士 觀 風向\" content:\"彭 博士 觀 風向\" description:\"彭 博士 觀 風向\" sddocname:contentindexing!0 embargo:<1484665288753!0 expires:>1484665288753!0", + "text:headline", "text:content", "text:description", "text:default", "nontext:tags", "nontext:sddocname", "nontext:embargo", "nontext:expires"); } @Test - public void testCompositeChildVerification() { + void testCompositeChildVerification() { CompositeItem root = new AndItem(); try { root.addItem(null); @@ -908,7 +902,7 @@ public class QueryTestCase { } @Test - public void queryLanguageAlternatives() { + void queryLanguageAlternatives() { // Given: // Person = { // Name: 'Joe', @@ -967,13 +961,13 @@ public class QueryTestCase { } @Test - public void testImplicitPhraseIsDefault() { + void testImplicitPhraseIsDefault() { Query query = new Query(httpEncode("?query=it's fine")); assertEquals("WEAKAND(100) (SAND it s) fine", query.getModel().getQueryTree().toString()); } @Test - public void testImplicitPhrase() { + void testImplicitPhrase() { Query query = new Query(httpEncode("?query=myfield:it's myfield:a.b myfield:c&type=all")); SearchDefinition test = new SearchDefinition("test"); @@ -988,7 +982,7 @@ public class QueryTestCase { } @Test - public void testImplicitAnd() { + void testImplicitAnd() { Query query = new Query(httpEncode("?query=myfield:it's myfield:a.b myfield:c")); SearchDefinition test = new SearchDefinition("test"); @@ -1001,18 +995,18 @@ public class QueryTestCase { assertEquals("WEAKAND(100) (SAND myfield:it myfield:s) (AND myfield:a myfield:b) myfield:c", query.getModel().getQueryTree().toString()); // 'it' and 's' should have connectivity 1 - WeakAndItem root = (WeakAndItem)query.getModel().getQueryTree().getRoot(); - AndSegmentItem sand = (AndSegmentItem)root.getItem(0); - WordItem it = (WordItem)sand.getItem(0); + WeakAndItem root = (WeakAndItem) query.getModel().getQueryTree().getRoot(); + AndSegmentItem sand = (AndSegmentItem) root.getItem(0); + WordItem it = (WordItem) sand.getItem(0); assertEquals("it", it.getWord()); - WordItem s = (WordItem)sand.getItem(1); + WordItem s = (WordItem) sand.getItem(1); assertEquals("s", s.getWord()); assertEquals(s, it.getConnectedItem()); assertEquals(1.0, it.getConnectivity(), 0.00000001); } @Test - public void testImplicitAndConnectivity() { + void testImplicitAndConnectivity() { SearchDefinition test = new SearchDefinition("test"); Index myField = new Index("myfield"); myField.addCommand("phrase-segmenting false"); @@ -1024,7 +1018,7 @@ public class QueryTestCase { query.getModel().setExecution(new Execution(Execution.Context.createContextStub(new IndexFacts(indexModel)))); assertEquals("WEAKAND(100) (AND myfield:b myfield:c myfield:d)", query.getModel().getQueryTree().toString()); WeakAndItem root = (WeakAndItem) query.getModel().getQueryTree().getRoot(); - AndItem and = (AndItem)root.getItem(0); + AndItem and = (AndItem) root.getItem(0); WordItem b = (WordItem) and.getItem(0); WordItem c = (WordItem) and.getItem(1); WordItem d = (WordItem) and.getItem(2); @@ -1040,7 +1034,7 @@ public class QueryTestCase { assertEquals("WEAKAND(100) myfield:a (AND myfield:b myfield:c myfield:d) myfield:e", query.getModel().getQueryTree().toString()); WeakAndItem root = (WeakAndItem) query.getModel().getQueryTree().getRoot(); WordItem a = (WordItem) root.getItem(0); - AndItem and = (AndItem)root.getItem(1); + AndItem and = (AndItem) root.getItem(1); WordItem b = (WordItem) and.getItem(0); WordItem c = (WordItem) and.getItem(1); WordItem d = (WordItem) and.getItem(2); @@ -1056,7 +1050,7 @@ public class QueryTestCase { } @Test - public void testImplicitAndInPhrase() { + void testImplicitAndInPhrase() { Query query = new Query(httpEncode("?query=myfield:\"it's fine\"")); SearchDefinition test = new SearchDefinition("test"); @@ -1071,7 +1065,7 @@ public class QueryTestCase { } @Test - public void testOldStyleSelect() { + void testOldStyleSelect() { // The same as testOldStyleSelectAndNativeQueryProfileType but not inheriting native QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfileType type = new QueryProfileType("mytype"); @@ -1081,15 +1075,15 @@ public class QueryTestCase { registry.getTypeRegistry().register(type); CompiledQueryProfileRegistry cRegistry = registry.compile(); Query query = new Query(httpEncode("?query=sddocname:sentence&select=all(group(context_id) max(10) each(each(output(summary()))))"), - cRegistry.findQueryProfile("default")); + cRegistry.findQueryProfile("default")); GroupingQueryParser parser = new GroupingQueryParser(); parser.search(query, new Execution(parser, Execution.Context.createContextStub())); assertEquals("[all(group(context_id) max(10) each(each(output(summary())))), all(group(context_id) max(10) each(each(output(summary()))))]", - query.getSelect().getGrouping().toString()); + query.getSelect().getGrouping().toString()); } @Test - public void testOldStyleSelectAndNativeQueryProfileType() { + void testOldStyleSelectAndNativeQueryProfileType() { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfileType type = new QueryProfileType("mytype"); type.inherited().add(registry.getType("native")); @@ -1099,11 +1093,11 @@ public class QueryTestCase { registry.getTypeRegistry().register(type); CompiledQueryProfileRegistry cRegistry = registry.compile(); Query query = new Query(httpEncode("?query=sddocname:sentence&select=all(group(context_id) max(10) each(each(output(summary()))))"), - cRegistry.findQueryProfile("default")); + cRegistry.findQueryProfile("default")); GroupingQueryParser parser = new GroupingQueryParser(); parser.search(query, new Execution(parser, Execution.Context.createContextStub())); assertEquals("[all(group(context_id) max(10) each(each(output(summary())))), all(group(context_id) max(10) each(each(output(summary()))))]", - query.getSelect().getGrouping().toString()); + query.getSelect().getGrouping().toString()); } /** @@ -1111,7 +1105,7 @@ public class QueryTestCase { * This is special because presentation.format is a native query profile. */ @Test - public void testSettingNativeQueryProfileValueInQueryProfile() { + void testSettingNativeQueryProfileValueInQueryProfile() { { QueryProfileRegistry registry = new QueryProfileRegistry(); QueryProfile profile = new QueryProfile("default"); @@ -1140,7 +1134,7 @@ public class QueryTestCase { type.inherited().add(registry.getType("native")); registry.getTypeRegistry().register(type); type.addField(new FieldDescription("ranking.features.query(embedding)", "tensor(x[5])"), - registry.getTypeRegistry()); + registry.getTypeRegistry()); QueryProfile profile = new QueryProfile("default"); profile.setType(type); registry.register(profile); @@ -1169,13 +1163,12 @@ public class QueryTestCase { private void assertContains(Map<String, Object> properties, Object ... expectedValues) { if (expectedValues == null) { assertEquals(1, properties.size()); - assertTrue("Contains value null", properties.containsValue(null)); + assertTrue(properties.containsValue(null), "Contains value null"); } else { - assertEquals(properties + " contains values " + Arrays.toString(expectedValues), - expectedValues.length, properties.size()); + assertEquals(expectedValues.length, properties.size(), properties + " contains values " + Arrays.toString(expectedValues)); for (Object expectedValue : expectedValues) - assertTrue("Contains value " + expectedValue, properties.containsValue(expectedValue)); + assertTrue(properties.containsValue(expectedValue), "Contains value " + expectedValue); } } |