summaryrefslogtreecommitdiffstats
path: root/vespa-feed-client/src/test/java/ai/vespa/feed/client/DocumentIdTest.java
diff options
context:
space:
mode:
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::"));
+ }
+
+}