aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-02-08 11:35:09 +0100
committerJon Bratseth <bratseth@gmail.com>2022-02-08 11:35:09 +0100
commitad3b8a05ccc2d0ece6f6cf93e9347fbaa84e1476 (patch)
tree5c579e641e3f9628c18c7222ca12000234882a19 /container-search/src/test/java/com/yahoo
parentfdae546b833532aac0a2f49400ccf15071549c6b (diff)
Revert "Revert "Bratseth/presentation format tensors""
This reverts commit 154c8837f1ca166816d289db82fed90baca72e54.
Diffstat (limited to 'container-search/src/test/java/com/yahoo')
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java7
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java1
-rw-r--r--container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java27
-rw-r--r--container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java29
4 files changed, 55 insertions, 9 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java
index 60b6c6dbe84..3ed044601f0 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/test/DumpToolTestCase.java
@@ -11,7 +11,7 @@ import static org.junit.Assert.assertTrue;
*/
public class DumpToolTestCase {
- private String profileDir = "src/test/java/com/yahoo/search/query/profile/config/test/multiprofile";
+ private final String profileDir = "src/test/java/com/yahoo/search/query/profile/config/test/multiprofile";
@Test
public void testNoParameters() {
@@ -25,12 +25,13 @@ public class DumpToolTestCase {
@Test
public void testNoDimensionValues() {
- assertTrue(new DumpTool().resolveAndDump("multiprofile1", profileDir).startsWith("a=general-a\n"));
+ System.out.println(new DumpTool().resolveAndDump("multiprofile1", profileDir));
+ assertTrue(new DumpTool().resolveAndDump("multiprofile1", profileDir).contains("a=general-a\n"));
}
@Test
public void testAllParametersSet() {
- assertTrue(new DumpTool().resolveAndDump("multiprofile1", profileDir, "").startsWith("a=general-a\n"));
+ assertTrue(new DumpTool().resolveAndDump("multiprofile1", profileDir, "").contains("a=general-a\n"));
}
@Test
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java
index 4b8edfdde73..fa7508ea5ac 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/NameTestCase.java
@@ -47,7 +47,6 @@ public class NameTestCase {
assertLegalFieldName("a/b");
assertLegalFieldName("/a/b");
assertLegalFieldName("/a/b/");
- assertIllegalFieldName("");
assertIllegalFieldName("aBc.dooEee.ce_d.-some-other.moreHere",
"Could not set 'aBc.dooEee.ce_d.-some-other.moreHere' to 'anyValue'",
"Illegal name '-some-other'");
diff --git a/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java b/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java
index f3a71af0b9e..95ef4ec3051 100644
--- a/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java
@@ -54,6 +54,7 @@ import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.TensorType;
import com.yahoo.tensor.serialization.TypedBinaryFormat;
import com.yahoo.text.Utf8;
+import com.yahoo.yolean.Exceptions;
import com.yahoo.yolean.trace.TraceNode;
import org.junit.Before;
import org.junit.Test;
@@ -69,6 +70,7 @@ import java.util.concurrent.ExecutionException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Functional testing of {@link JsonRenderer}.
@@ -165,11 +167,26 @@ public class JsonRendererTestCase {
h.setField("tensor_mixed", new TensorFieldValue(Tensor.from("tensor(x{},y[2]):{a:[1,2], b:[3,4]}")));
h.setField("summaryfeatures", summaryFeatures);
- Result r = new Result(new Query("/?format.tensors=short"));
- r.hits().add(h);
- r.setTotalHitCount(1L);
- String summary = render(r);
- assertEqualJson(expected, summary);
+ Result result1 = new Result(new Query("/?presentation.format.tensors=short"));
+ result1.hits().add(h);
+ result1.setTotalHitCount(1L);
+ String summary1 = render(result1);
+ assertEqualJson(expected, summary1);
+
+ Result result2 = new Result(new Query("/?format.tensors=short"));
+ result2.hits().add(h);
+ result2.setTotalHitCount(1L);
+ String summary2 = render(result2);
+ assertEqualJson(expected, summary2);
+
+ try {
+ render(new Result(new Query("/?presentation.format.tensors=unknown")));
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("Could not set 'presentation.format.tensors' to 'unknown': Value must be 'long' or 'short', not 'unknown'",
+ Exceptions.toMessageString(e));
+ }
}
@Test
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 312fe175270..3b0a0ad7972 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
@@ -1092,6 +1092,35 @@ public class QueryTestCase {
query.getSelect().getGrouping().toString());
}
+ /**
+ * Tests that the value presentation.format.tensors can be set in a query profile.
+ * This is special because presentation.format is a native query profile.
+ */
+ @Test
+ public void testSettingNativeQueryProfileValueInQueryProfile() {
+ {
+ QueryProfileRegistry registry = new QueryProfileRegistry();
+ QueryProfile profile = new QueryProfile("default");
+ profile.set("presentation.format.tensors", "short", Map.of(), registry);
+ registry.register(profile);
+ CompiledQueryProfileRegistry cRegistry = registry.compile();
+ Query query = new Query("?query=foo", cRegistry.findQueryProfile("default"));
+ assertTrue(query.getPresentation().getTensorShortForm());
+ }
+
+ { // Same as above but also set presentation.format
+ QueryProfileRegistry registry = new QueryProfileRegistry();
+ QueryProfile profile = new QueryProfile("default");
+ profile.set("presentation.format", "xml", Map.of(), registry);
+ profile.set("presentation.format.tensors", "short", Map.of(), registry);
+ registry.register(profile);
+ CompiledQueryProfileRegistry cRegistry = registry.compile();
+ Query query = new Query("?query=foo", cRegistry.findQueryProfile("default"));
+ assertEquals("xml", query.getPresentation().getFormat());
+ assertTrue(query.getPresentation().getTensorShortForm());
+ }
+ }
+
private void assertDetectionText(String expectedDetectionText, String queryString, String ... indexSpecs) {
Query q = new Query(httpEncode("/?query=" + queryString));
SearchDefinition sd = new SearchDefinition("testSearchDefinition");