summaryrefslogtreecommitdiffstats
path: root/vespa-feed-client/src/test/java/ai/vespa/feed/client/DocumentIdTest.java
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2021-10-11 22:19:12 +0200
committerGitHub <noreply@github.com>2021-10-11 22:19:12 +0200
commitf3e402cd0928a00e017bac1a38708debced7a4eb (patch)
tree9e157f3d1847392b0d1330a786811598267f5cf1 /vespa-feed-client/src/test/java/ai/vespa/feed/client/DocumentIdTest.java
parentf889f5f3df5411901f549f1a7144ad0845e01103 (diff)
parent6587de95f2d732f9d3259b2baac60d7edf0fd965 (diff)
Merge pull request #19509 from vespa-engine/jonmv/fix-docid-parse-bugv7.481.18
Fix document id parse bug in feed client
Diffstat (limited to 'vespa-feed-client/src/test/java/ai/vespa/feed/client/DocumentIdTest.java')
-rw-r--r--vespa-feed-client/src/test/java/ai/vespa/feed/client/DocumentIdTest.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/vespa-feed-client/src/test/java/ai/vespa/feed/client/DocumentIdTest.java b/vespa-feed-client/src/test/java/ai/vespa/feed/client/DocumentIdTest.java
new file mode 100644
index 00000000000..df790056309
--- /dev/null
+++ b/vespa-feed-client/src/test/java/ai/vespa/feed/client/DocumentIdTest.java
@@ -0,0 +1,54 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.feed.client;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * @author jonmv
+ */
+class DocumentIdTest {
+
+ @Test
+ void testParsing() {
+ assertEquals("id:ns:type::user",
+ DocumentId.of("id:ns:type::user").toString());
+
+ assertEquals("id:ns:type:n=123:user",
+ DocumentId.of("id:ns:type:n=123:user").toString());
+
+ assertEquals("id:ns:type:g=foo:user",
+ DocumentId.of("id:ns:type:g=foo:user").toString());
+
+ assertEquals("id:ns:type::user::specific",
+ DocumentId.of("id:ns:type::user::specific").toString());
+
+ assertEquals("id:ns:type:::",
+ DocumentId.of("id:ns:type:::").toString());
+
+ assertThrows(IllegalArgumentException.class,
+ () -> DocumentId.of("idd:ns:type:user"));
+
+ assertThrows(IllegalArgumentException.class,
+ () -> DocumentId.of("id:ns::user"));
+
+ assertThrows(IllegalArgumentException.class,
+ () -> DocumentId.of("id::type:user"));
+
+ assertThrows(IllegalArgumentException.class,
+ () -> DocumentId.of("id:ns:type:g=:user"));
+
+ assertThrows(IllegalArgumentException.class,
+ () -> DocumentId.of("id:ns:type:n=:user"));
+
+ assertThrows(NumberFormatException.class,
+ () -> DocumentId.of("id:ns:type:n=foo:user"));
+
+ assertThrows(IllegalArgumentException.class,
+ () -> DocumentId.of("id:ns:type::"));
+ }
+
+}