1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.properties.spi.config.definition;
17
18 import static de.smartics.properties.api.config.domain.key.EnvironmentId.ANY_ENV;
19 import static org.hamcrest.MatcherAssert.assertThat;
20 import static org.hamcrest.Matchers.equalTo;
21 import static org.hamcrest.Matchers.is;
22
23 import java.util.HashSet;
24 import java.util.Set;
25
26 import org.junit.Test;
27
28 import de.smartics.properties.api.config.domain.key.ApplicationId;
29 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
30 import de.smartics.properties.api.config.domain.key.EnvironmentId;
31 import de.smartics.properties.impl.config.domain.key.envapp.EnvAppConfigurationKey;
32 import de.smartics.properties.impl.config.domain.key.envapp.EnvAppDefinitionKeyHelper;
33 import de.smartics.properties.impl.config.domain.key.envapp.EnvAppPropertiesDefinitionContext;
34 import de.smartics.testdoc.annotations.Uut;
35 import de.smartics.util.lang.NullArgumentException;
36
37
38
39
40
41 @Uut(type = EnvAppDefinitionKeyHelper.class)
42 public class DefinitionKeyHelperRegisteredTest
43 {
44
45
46
47
48 private static final String COM_GROUP = "com.smartics.test.one";
49
50 private static final String DEFAULT_GROUP = "de.smartics.test.one";
51
52 private static final String NON_STANDARD_GROUP = "nonstandard";
53
54 private static final String NON_STANDARD_TLD = "xxx";
55
56 private static final String NON_STANDARD_GROUP_TLD = NON_STANDARD_TLD
57 + ".example.test";
58
59
60
61 private static final EnvironmentId ENV_PRODUCTION = new EnvironmentId(
62 "production");
63
64 private static final EnvironmentId ENV_PRODUCTION_A = new EnvironmentId(
65 "production", DEFAULT_GROUP);
66
67 private static final EnvironmentId ENV_PRODUCTION_XX = new EnvironmentId(
68 DEFAULT_GROUP);
69
70
71
72 private static final ApplicationId APP_ANY_IN_GROUP_ONE = new ApplicationId(
73 COM_GROUP, null, null);
74
75 private static final ApplicationId APP_WITH_NON_STANDARD_GROUP =
76 new ApplicationId(NON_STANDARD_GROUP, null, null);
77
78 private static final ApplicationId APP_WITH_NON_STANDARD_TLD =
79 new ApplicationId(NON_STANDARD_GROUP_TLD, null, null);
80
81
82
83
84
85
86
87
88
89
90
91 private void runTest(final EnvAppDefinitionKeyHelper uut,
92 final EnvironmentId envId, final ApplicationId appId)
93 throws IllegalArgumentException, NullArgumentException
94 {
95 final String path =
96 envId.toPath() + (envId != ANY_ENV ? "/" : "") + appId.toPath();
97 runTest(uut, path, envId, appId);
98 }
99
100 @SuppressWarnings("rawtypes")
101 private void runTest(final EnvAppDefinitionKeyHelper uut, final String path,
102 final EnvironmentId envId, final ApplicationId appId)
103 throws IllegalArgumentException, NullArgumentException
104 {
105 final ConfigurationKey key = uut.parse(path);
106
107 final ConfigurationKey expectedKey =
108 new EnvAppConfigurationKey(envId, appId);
109 assertThat(key, is(equalTo(expectedKey)));
110 }
111
112
113
114 @Test
115 public void identifiesRegisteredEnvironments()
116 {
117 final Set<String> envs = new HashSet<String>();
118 envs.add(DEFAULT_GROUP);
119
120 final EnvAppPropertiesDefinitionContext context =
121 new EnvAppPropertiesDefinitionContext(envs, null, null);
122
123 final EnvAppDefinitionKeyHelper uut =
124 new EnvAppDefinitionKeyHelper(context);
125 runTest(uut, ENV_PRODUCTION_XX, APP_ANY_IN_GROUP_ONE);
126 }
127
128 @Test
129 public void identifiesRegisteredNodes()
130 {
131 final Set<String> nodes = new HashSet<String>();
132 nodes.add(DEFAULT_GROUP);
133
134 final EnvAppPropertiesDefinitionContext context =
135 new EnvAppPropertiesDefinitionContext(null, nodes, null);
136
137 final EnvAppDefinitionKeyHelper uut =
138 new EnvAppDefinitionKeyHelper(context);
139 runTest(uut, ENV_PRODUCTION_A, APP_ANY_IN_GROUP_ONE);
140 }
141
142 @Test
143 public void identifiesRegisteredGroups()
144 {
145 final Set<String> groups = new HashSet<String>();
146 groups.add(NON_STANDARD_GROUP);
147
148 final EnvAppPropertiesDefinitionContext context =
149 new EnvAppPropertiesDefinitionContext(null, null, groups);
150
151 final EnvAppDefinitionKeyHelper uut =
152 new EnvAppDefinitionKeyHelper(context);
153 runTest(uut, ENV_PRODUCTION, APP_WITH_NON_STANDARD_GROUP);
154 }
155
156 @Test
157 public void identifiesGroupByRegisteredTlds()
158 {
159 final Set<String> tlds = new HashSet<String>();
160 tlds.add(NON_STANDARD_TLD);
161
162 final EnvAppPropertiesDefinitionContext context =
163 new EnvAppPropertiesDefinitionContext(tlds, null, null, null, null);
164
165 final EnvAppDefinitionKeyHelper uut =
166 new EnvAppDefinitionKeyHelper(context);
167 runTest(uut, ENV_PRODUCTION, APP_WITH_NON_STANDARD_TLD);
168 }
169 }