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
|
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;
import com.yahoo.config.provision.zone.ZoneId;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
/**
* @author hmusum
*/
public class ZoneIdTest {
private static final Environment environment = Environment.prod;
private static final RegionName region = RegionName.from("moon-dark-side-1");
private static final CloudName cloud = CloudName.from("aws");
private static final SystemName system = SystemName.Public;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testCreatingZoneId() {
ZoneId zoneId = ZoneId.from(environment, region);
assertEquals(region, zoneId.region());
assertEquals(environment, zoneId.environment());
assertEquals(CloudName.defaultName(), zoneId.cloud());
assertEquals(SystemName.defaultSystem(), zoneId.system());
ZoneId zoneIdWithSystem = ZoneId.from(system, environment, region);
assertEquals(region, zoneIdWithSystem.region());
assertEquals(environment, zoneIdWithSystem.environment());
assertEquals(CloudName.defaultName(), zoneIdWithSystem.cloud());
assertEquals(system, zoneIdWithSystem.system());
ZoneId zoneIdWithCloudAndSystem = ZoneId.from(environment, region, cloud, system);
assertEquals(region, zoneIdWithCloudAndSystem.region());
assertEquals(environment, zoneIdWithCloudAndSystem.environment());
assertEquals(cloud, zoneIdWithCloudAndSystem.cloud());
assertEquals(system, zoneIdWithCloudAndSystem.system());
}
@Test
public void testSerializingAndDeserializing() {
ZoneId zoneId = ZoneId.from(environment, region);
assertEquals(environment.value() + "." + region.value(), zoneId.value());
assertEquals(ZoneId.from(zoneId.value()), zoneId);
ZoneId zoneIdWithCloudAndSystem = ZoneId.from(environment, region, cloud, system);
assertEquals(environment.value() + "." + region.value(), zoneIdWithCloudAndSystem.value());
assertEquals(ZoneId.from(zoneIdWithCloudAndSystem.value()), zoneIdWithCloudAndSystem);
// TODO: Expect cloud and system to be part of deserialized value when the new format is supported everywhere
//assertEquals(cloud.value() + "." + system.name() + "." + environment.value() + "." + region.value() , zoneId.value());
String serializedZoneId = "some.illegal.value";
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Cannot deserialize zone id '" + serializedZoneId + "'");
ZoneId.from(serializedZoneId);
}
}
|