aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/test
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-04-14 16:54:44 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-04-14 16:54:44 +0000
commit9125d1651742481bdd359b7288a171c57e7b6b54 (patch)
treeeea4a2d09f8f17154eddebe6386773a5a30590b9 /document/src/test
parentd8298478feb34ba096ee1452270a92f29f178439 (diff)
Ensure that documentid is legal.
Diffstat (limited to 'document/src/test')
-rw-r--r--document/src/test/java/com/yahoo/document/IdIdStringTest.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/document/src/test/java/com/yahoo/document/IdIdStringTest.java b/document/src/test/java/com/yahoo/document/IdIdStringTest.java
index 88b5f38ec0c..b321d91e6e9 100644
--- a/document/src/test/java/com/yahoo/document/IdIdStringTest.java
+++ b/document/src/test/java/com/yahoo/document/IdIdStringTest.java
@@ -2,9 +2,11 @@
package com.yahoo.document;
import com.yahoo.document.idstring.IdIdString;
+import com.yahoo.document.idstring.IdString;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
@@ -50,6 +52,7 @@ public class IdIdStringTest {
new IdIdString("namespace", "type", "illegal=key", "foo");
fail();
} catch (IllegalArgumentException e) {
+ assertEquals("Illegal key 'illegal'", e.getMessage());
}
}
@@ -59,6 +62,35 @@ public class IdIdStringTest {
new IdIdString("namespace", "type", "illegal-pair", "foo");
fail();
} catch (IllegalArgumentException e) {
+ assertEquals("Illegal key-value pair 'illegal-pair'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void requireThatTooLongPreNamspaceSpecificThrowsWhileParsing() throws Exception {
+ StringBuilder builder = new StringBuilder("id:");
+ for (int i = 0; i < 0x10000; i++) {
+ builder.append('n');
+ }
+ builder.append(":type::namespacespecificpart_01");
+ try {
+ IdString.createIdString(builder.toString());
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertEquals("Document id prior to the namespace specific part, 65545, is longer than 65534", e.getMessage().substring(0, 77));
+ }
+ }
+ @Test
+ public void requireThatTooLongPreNamspaceSpecificThrowsOnConstruction() {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 0x10000; i++) {
+ builder.append('n');
+ }
+ try {
+ new IdIdString(builder.toString(), "type", "", "namespacespecificpart_01");
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertEquals("Length of namespace(65536) + doctype(4) + key/values(0), is longer than 65529", e.getMessage());
}
}