summaryrefslogtreecommitdiffstats
path: root/vespa-feed-client/src/test/java/ai/vespa/feed/client/DocumentIdTest.java
blob: df7900563091cfcf6cb2ba80bbfa0093329c664a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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::"));
    }

}