aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
diff options
context:
space:
mode:
authorLester Solbakken <lesters@oath.com>2021-09-02 15:59:15 +0200
committerLester Solbakken <lesters@oath.com>2021-09-02 15:59:15 +0200
commit691ddac6701fb0d45b0ef2bbd49e5ab99bcc6c17 (patch)
treec2982328f7351182e4d7451f4c326563f0b24ca7 /document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
parent045321f2a1b2d00d33ccf7c64c2708b6e2c94667 (diff)
Disallow feeding empty indexed tensors
Diffstat (limited to 'document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java')
-rw-r--r--document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
index e50fd9734f7..7f4b420cf9a 100644
--- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
+++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java
@@ -1282,6 +1282,22 @@ public class JsonReaderTestCase {
}
@Test
+ public void testDisallowedDenseTensorShortFormWithoutValues() {
+ assertCreatePutFails(inputJson("{ 'values': [] }"), "dense_tensor",
+ "The 'values' array does not contain any values");
+ assertCreatePutFails(inputJson("{ 'values': '' }"), "dense_tensor",
+ "The 'values' string does not contain any values");
+ }
+
+ @Test
+ public void testDisallowedMixedTensorShortFormWithoutValues() {
+ assertCreatePutFails(inputJson("{\"blocks\":{ \"a\": [] } }"),
+ "mixed_tensor", "Expected 3 values, but got 0");
+ assertCreatePutFails(inputJson("{\"blocks\":[ {\"address\":{\"x\":\"a\"}, \"values\": [] } ] }"),
+ "mixed_tensor", "Expected 3 values, but got 0");
+ }
+
+ @Test
public void testParsingOfSparseTensorWithCells() {
Tensor tensor = assertSparseTensorField("{{x:a,y:b}:2.0,{x:c,y:b}:3.0}}",
createPutWithSparseTensor(inputJson("{",
@@ -2029,4 +2045,13 @@ public class JsonReaderTestCase {
new JsonReader(types, jsonToInputStream(jsonData), parserFactory).next();
}
+ private void assertCreatePutFails(String tensor, String name, String msg) {
+ try {
+ createPutWithTensor(inputJson(tensor), name);
+ fail("Expected exception");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains(msg));
+ }
+ }
+
}