diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-10-11 12:35:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 12:35:13 +0200 |
commit | 9e5c9398c8141d59d3c07aba9198fa3dc43b56a0 (patch) | |
tree | f674f7ac06fca2bba8faebaa3cdf098e73fbc0c2 /documentgen-test/src | |
parent | c5415130877801316c9c380330c644f3b9f615c8 (diff) | |
parent | 9922b8c1681a817d9a9c84d3a967a5120e8c0599 (diff) |
Merge pull request #28850 from vespa-engine/jonmv/concrete-document-field-validation
Jonmv/concrete document field validation
Diffstat (limited to 'documentgen-test/src')
-rw-r--r-- | documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java | 24 |
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 8c49ec9ba29..cae11d66d13 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) { |