summaryrefslogtreecommitdiffstats
path: root/documentgen-test
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2023-10-10 14:11:15 +0200
committerjonmv <venstad@gmail.com>2023-10-10 14:11:15 +0200
commitc4face9aeb327f059dc1613b416713a275d807c9 (patch)
treefaf8284c3286b61801c696869eb76496e7c17e17 /documentgen-test
parentd61c151211024dbb5e9a5d71ac921217ae00f34b (diff)
Validate string, uri and reference fields when set in concrete documents
Diffstat (limited to 'documentgen-test')
-rw-r--r--documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java b/documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java
index bd2b057835c..b3e78f1e2a8 100644
--- a/documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java
+++ b/documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java
@@ -79,6 +79,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
/**
@@ -500,6 +501,29 @@ public class DocumentGenPluginTest {
assertEquals(book.getFieldValue("isbn"), new StringFieldValue("ISBN YEP"));
}
+ @Test
+ public void testSetterValidation() {
+ Book book = new Book(new DocumentId("id:book:book::0"));
+
+ book.setAuthor("Herman Melville");
+ assertEquals("The string field value contains illegal code point 0x16",
+ assertThrows(IllegalArgumentException.class,
+ () -> book.setAuthor("He\u0016rman Malville")).getMessage());
+
+ book.setRef(new DocumentId("id:ns:parent::foo"));
+ assertEquals("Can't assign document ID 'id:ns:common::bar' (of type 'common') to reference of document type 'parent'",
+ assertThrows(IllegalArgumentException.class,
+ () -> book.setRef(new DocumentId("id:ns:common::bar"))).getMessage());
+
+ book.setStringmap(Map.of("foo", "bar"));
+ assertEquals("The string field value contains illegal code point 0x16",
+ assertThrows(IllegalArgumentException.class,
+ () -> book.setStringmap(Map.of("foo", "bar\u0016"))).getMessage());
+ assertEquals("The string field value contains illegal code point 0x16",
+ assertThrows(IllegalArgumentException.class,
+ () -> book.setStringmap(Map.of("bar\u0016", "foo"))).getMessage());
+ }
+
public static class BookProcessor extends DocumentProcessor {
public Progress process(Processing processing) {