aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java
blob: a48301f10b245e22ed5375d475e7efafc689ae87 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.identifiers;

import com.yahoo.config.provision.zone.ZoneId;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
 * @author smorgrav
 */
public class IdentifierTest {

    @Test
    void existing_tenant_id_not_empty() {
        assertThrows(IllegalArgumentException.class, () -> {
            new TenantId("");
        });
    }

    @Test
    void existing_tenant_id_must_check_pattern() {
        assertThrows(IllegalArgumentException.class, () -> {
            new TenantId("`");
        });
    }

    @Test
    void default_not_allowed_for_tenants() {
        assertThrows(IllegalArgumentException.class, () -> {
            new TenantId("default");
        });
    }

    @Test
    void existing_tenant_id_must_accept_valid_id() {
        new TenantId("msbe");
    }

    @Test
    void existing_tenant_id_cannot_be_uppercase() {
        assertThrows(IllegalArgumentException.class, () -> {
            new TenantId("MixedCaseTenant");
        });
    }

    @Test
    void existing_tenant_id_cannot_contain_dots() {
        assertThrows(IllegalArgumentException.class, () -> {
            new TenantId("tenant.with.dots");
        });
    }

    @Test
    void new_tenant_id_cannot_contain_underscore() {
        assertThrows(IllegalArgumentException.class, () -> {
            TenantId.validate("underscore_tenant");
        });
    }

    @Test
    void new_tenant_id_cannot_contain_dot() {
        assertThrows(IllegalArgumentException.class, () -> {
            TenantId.validate("tenant.with.dots");
        });
    }

    @Test
    void new_tenant_id_cannot_contain_uppercase() {
        assertThrows(IllegalArgumentException.class, () -> {
            TenantId.validate("UppercaseTenant");
        });
    }

    @Test
    void new_tenant_id_cannot_start_with_dash() {
        assertThrows(IllegalArgumentException.class, () -> {
            TenantId.validate("-tenant");
        });
    }

    @Test
    void new_tenant_id_cannot_end_with_dash() {
        assertThrows(IllegalArgumentException.class, () -> {
            TenantId.validate("tenant-");
        });
    }

    @Test
    void existing_application_id_cannot_be_uppercase() {
        assertThrows(IllegalArgumentException.class, () -> {
            new ApplicationId("MixedCaseApplication");
        });
    }

    @Test
    void existing_application_id_cannot_contain_dots() {
        assertThrows(IllegalArgumentException.class, () -> {
            new ApplicationId("application.with.dots");
        });
    }

    @Test
    void new_application_id_cannot_contain_underscore() {
        assertThrows(IllegalArgumentException.class, () -> {
            ApplicationId.validate("underscore_application");
        });
    }

    @Test
    void new_application_id_cannot_contain_dot() {
        assertThrows(IllegalArgumentException.class, () -> {
            ApplicationId.validate("application.with.dots");
        });
    }

    @Test
    void new_application_id_cannot_contain_uppercase() {
        assertThrows(IllegalArgumentException.class, () -> {
            ApplicationId.validate("UppercaseApplication");
        });
    }

    @Test
    void new_application_id_cannot_start_with_dash() {
        assertThrows(IllegalArgumentException.class, () -> {
            ApplicationId.validate("-application");
        });
    }

    @Test
    void new_application_id_cannot_end_with_dash() {
        assertThrows(IllegalArgumentException.class, () -> {
            ApplicationId.validate("application-");
        });
    }

    @Test
    void instance_id_cannot_be_uppercase() {
        assertThrows(IllegalArgumentException.class, () -> {
            new InstanceId("MixedCaseInstance");
        });
    }

    @Test
    void dns_names_has_no_underscore() {
        assertEquals("a-b-c", new ApplicationId("a_b_c").toDns());
    }

    @Test
    void identifiers_cannot_be_named_api() {
        assertThrows(IllegalArgumentException.class, () -> {
            new ApplicationId("api");
        });
    }

    @Test
    void application_instance_id_dotted_string_is_subindentifers_concatinated_with_dots() {
        DeploymentId id = new DeploymentId(com.yahoo.config.provision.ApplicationId.from("tenant", "application", "instance"),
                ZoneId.from("prod", "region"));
        assertEquals("tenant.application.prod.region.instance", id.dottedString());
    }

    @Test
    void revision_id_can_contain_application_version_number() {
        new RevisionId("1.0.1078-24825d1f6");
    }
}