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
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.persistence;// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.athenz.api.AthenzDomain;
import com.yahoo.vespa.hosted.controller.api.identifiers.Property;
import com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId;
import com.yahoo.vespa.hosted.controller.tenant.AthenzTenant;
import com.yahoo.vespa.hosted.controller.tenant.Contact;
import com.yahoo.vespa.hosted.controller.tenant.UserTenant;
import org.junit.Test;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author mpolden
*/
public class TenantSerializerTest {
private static final TenantSerializer serializer = new TenantSerializer();
@Test
public void athenz_tenant() {
AthenzTenant tenant = AthenzTenant.create(TenantName.from("athenz-tenant"),
new AthenzDomain("domain1"),
new Property("property1"),
Optional.of(new PropertyId("1")));
AthenzTenant serialized = serializer.athenzTenantFrom(serializer.toSlime(tenant));
assertEquals(tenant.name(), serialized.name());
assertEquals(tenant.domain(), serialized.domain());
assertEquals(tenant.property(), serialized.property());
assertTrue(serialized.propertyId().isPresent());
assertEquals(tenant.propertyId(), serialized.propertyId());
}
@Test
public void athenz_tenant_without_property_id() {
AthenzTenant tenant = AthenzTenant.create(TenantName.from("athenz-tenant"),
new AthenzDomain("domain1"),
new Property("property1"),
Optional.empty());
AthenzTenant serialized = serializer.athenzTenantFrom(serializer.toSlime(tenant));
assertFalse(serialized.propertyId().isPresent());
assertEquals(tenant.propertyId(), serialized.propertyId());
}
@Test
public void athenz_tenant_with_contact() {
AthenzTenant tenant = new AthenzTenant(TenantName.from("athenz-tenant"),
new AthenzDomain("domain1"),
new Property("property1"),
Optional.of(new PropertyId("1")),
Optional.of(new Contact(
URI.create("http://contact1.test"),
URI.create("http://property1.test"),
URI.create("http://issue-tracker-1.test"),
Arrays.asList(
Collections.singletonList("person1"),
Collections.singletonList("person2")
)
)));
AthenzTenant serialized = serializer.athenzTenantFrom(serializer.toSlime(tenant));
assertEquals(tenant.contact(), serialized.contact());
}
@Test
public void user_tenant() {
UserTenant tenant = UserTenant.create("by-foo");
UserTenant serialized = serializer.userTenantFrom(serializer.toSlime(tenant));
assertEquals(tenant.name(), serialized.name());
}
}
|