1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.spi.config.support;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is;
20
21 import java.util.Arrays;
22 import java.util.List;
23
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import de.smartics.properties.api.config.domain.key.ApplicationId;
28 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
29 import de.smartics.properties.api.config.domain.key.EnvironmentId;
30 import de.smartics.testdoc.annotations.Uut;
31
32
33
34
35 public class KeySetBuilderTest
36 {
37
38
39
40
41 private static final String ENV_NAME = "test";
42
43 private static final String NODEN_AME = "test-node";
44
45 private static final String GROUP_ID = "test-group";
46
47 private static final String ARTIFACT_ID = "test-artifact";
48
49 private static final String VERSION = "1.0";
50
51
52
53 private static final EnvironmentId ENV_NAME_ONLY =
54 new EnvironmentId(ENV_NAME);
55
56 private static final EnvironmentId ENV_NAME_AND_NODE = new EnvironmentId(
57 ENV_NAME, NODEN_AME);
58
59 private static final ApplicationId APP_GROUP_ONLY = new ApplicationId(
60 GROUP_ID, null, null);
61
62 private static final ApplicationId APP_NO_VERSION = new ApplicationId(
63 GROUP_ID, ARTIFACT_ID, null);
64
65 private static final ApplicationId APP_ALL = new ApplicationId(GROUP_ID,
66 ARTIFACT_ID, VERSION);
67
68
69
70 private static final ConfigurationKey ANY = new ConfigurationKey(
71 EnvironmentId.ANY_ENV, ApplicationId.ANY_APP);
72
73 private static final ConfigurationKey E = new ConfigurationKey(ENV_NAME_ONLY,
74 ApplicationId.ANY_APP);
75
76 private static final ConfigurationKey EN = new ConfigurationKey(
77 ENV_NAME_AND_NODE, ApplicationId.ANY_APP);
78
79 private static final ConfigurationKey E_G = new ConfigurationKey(
80 ENV_NAME_ONLY, APP_GROUP_ONLY);
81
82 private static final ConfigurationKey EN_G = new ConfigurationKey(
83 ENV_NAME_AND_NODE, APP_GROUP_ONLY);
84
85 private static final ConfigurationKey E_GA = new ConfigurationKey(
86 ENV_NAME_ONLY, APP_NO_VERSION);
87
88 private static final ConfigurationKey EN_GA = new ConfigurationKey(
89 ENV_NAME_AND_NODE, APP_NO_VERSION);
90
91 private static final ConfigurationKey E_GAV = new ConfigurationKey(
92 ENV_NAME_ONLY, APP_ALL);
93
94 private static final ConfigurationKey EN_GAV = new ConfigurationKey(
95 ENV_NAME_AND_NODE, APP_ALL);
96
97 private static final ConfigurationKey ANY_G = new ConfigurationKey(
98 EnvironmentId.ANY_ENV, APP_GROUP_ONLY);
99
100 private static final ConfigurationKey ANY_GA = new ConfigurationKey(
101 EnvironmentId.ANY_ENV, APP_NO_VERSION);
102
103 private static final ConfigurationKey ANY_GAV = new ConfigurationKey(
104 EnvironmentId.ANY_ENV, APP_ALL);
105
106
107
108 @Uut
109 private KeySetBuilder uut;
110
111
112
113
114
115
116
117 @Before
118 public void setUp()
119 {
120 uut = new KeySetBuilder();
121 }
122
123
124
125
126
127 @Test
128 public void derivesFromKeyWithOnlyAnEnvironmentName()
129 {
130 final List<ConfigurationKey> keySet = uut.createKeySet(E);
131
132 assertThat(keySet, is(Arrays.asList(E, ANY)));
133 }
134
135 @Test
136 public void derivesFromKeyWithEnvironmentNameAndNode()
137 {
138 final List<ConfigurationKey> keySet = uut.createKeySet(EN);
139
140 assertThat(keySet, is(Arrays.asList(EN, E, ANY)));
141 }
142
143 @Test
144 public void derivesFromKeyWithFullEnvironmentNameOnlyAndGroup()
145 {
146 final List<ConfigurationKey> keySet = uut.createKeySet(E_G);
147
148 assertThat(keySet, is(Arrays.asList(E_G, E, ANY_G, ANY)));
149 }
150
151 @Test
152 public void derivesFromKeyWithFullEnvironmentAndGroup()
153 {
154 final List<ConfigurationKey> keySet = uut.createKeySet(EN_G);
155
156 assertThat(keySet, is(Arrays.asList(EN_G, EN, E, ANY_G, ANY)));
157 }
158
159 @Test
160 public void derivesFromKeyWithFullEnvironmentNameOnlyAndGA()
161 {
162 final List<ConfigurationKey> keySet = uut.createKeySet(E_GA);
163
164 assertThat(keySet, is(Arrays.asList(E_GA, E_G, E, ANY_GA, ANY_G, ANY)));
165 }
166
167 @Test
168 public void derivesFromKeyWithFullEnvironmentAndGA()
169 {
170 final List<ConfigurationKey> keySet = uut.createKeySet(EN_GA);
171
172 assertThat(keySet, is(Arrays.asList(EN_GA, EN_G, EN, E_G, E, ANY_GA, ANY_G, ANY)));
173 }
174
175 @Test
176 public void derivesFromKeyWithFullEnvironmentNameOnlyAndGAV()
177 {
178 final List<ConfigurationKey> keySet = uut.createKeySet(E_GAV);
179
180 assertThat(keySet,
181 is(Arrays.asList(E_GAV, E_GA, E_G, E, ANY_GAV, ANY_GA, ANY_G, ANY)));
182 }
183
184 @Test
185 public void derivesFromKeyWithFullEnvironmentAndGAV()
186 {
187 final List<ConfigurationKey> keySet = uut.createKeySet(EN_GAV);
188
189 assertThat(keySet, is(Arrays.asList(EN_GAV, EN_GA, EN_G, EN, E_GAV, E_GA,
190 E_G, E, ANY_GAV, ANY_GA, ANY_G, ANY)));
191 }
192 }