View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.impl.config.domain.key.envapp;
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  import de.smartics.util.lang.StaticAnalysis;
32  
33  /**
34   * Tests {@link EnvAppKeyListBuilder}.
35   */
36  public class EnvAppKeyListBuilderTest
37  {
38    // ********************************* Fields *********************************
39  
40    // --- constants ------------------------------------------------------------
41  
42    private static final String ENV_NAME = "test";
43  
44    private static final String NODEN_AME = "test-node";
45  
46    private static final String GROUP_ID = "test-group";
47  
48    private static final String ARTIFACT_ID = "test-artifact";
49  
50    private static final String VERSION = "1.0";
51  
52    // ... key parts ............................................................
53  
54    private static final EnvironmentId ENV_NAME_ONLY =
55        new EnvironmentId(ENV_NAME);
56  
57    private static final EnvironmentId ENV_NAME_AND_NODE = new EnvironmentId(
58        ENV_NAME, NODEN_AME);
59  
60    private static final ApplicationId APP_GROUP_ONLY = new ApplicationId(
61        GROUP_ID, null, null);
62  
63    private static final ApplicationId APP_NO_VERSION = new ApplicationId(
64        GROUP_ID, ARTIFACT_ID, null);
65  
66    private static final ApplicationId APP_ALL = new ApplicationId(GROUP_ID,
67        ARTIFACT_ID, VERSION);
68  
69    // ... keys .................................................................
70  
71    private static final ConfigurationKey<?> ANY = new EnvAppConfigurationKey(
72        EnvironmentId.ANY_ENV, ApplicationId.ANY_APP);
73  
74    private static final ConfigurationKey<?> E = new EnvAppConfigurationKey(
75        ENV_NAME_ONLY, ApplicationId.ANY_APP);
76  
77    private static final ConfigurationKey<?> EN = new EnvAppConfigurationKey(
78        ENV_NAME_AND_NODE, ApplicationId.ANY_APP);
79  
80    private static final ConfigurationKey<?> E_G = new EnvAppConfigurationKey(
81        ENV_NAME_ONLY, APP_GROUP_ONLY);
82  
83    private static final ConfigurationKey<?> EN_G = new EnvAppConfigurationKey(
84        ENV_NAME_AND_NODE, APP_GROUP_ONLY);
85  
86    private static final ConfigurationKey<?> E_GA = new EnvAppConfigurationKey(
87        ENV_NAME_ONLY, APP_NO_VERSION);
88  
89    private static final ConfigurationKey<?> EN_GA = new EnvAppConfigurationKey(
90        ENV_NAME_AND_NODE, APP_NO_VERSION);
91  
92    private static final ConfigurationKey<?> E_GAV = new EnvAppConfigurationKey(
93        ENV_NAME_ONLY, APP_ALL);
94  
95    private static final ConfigurationKey<?> EN_GAV = new EnvAppConfigurationKey(
96        ENV_NAME_AND_NODE, APP_ALL);
97  
98    private static final ConfigurationKey<?> ANY_G = new EnvAppConfigurationKey(
99        EnvironmentId.ANY_ENV, APP_GROUP_ONLY);
100 
101   private static final ConfigurationKey<?> ANY_GA = new EnvAppConfigurationKey(
102       EnvironmentId.ANY_ENV, APP_NO_VERSION);
103 
104   private static final ConfigurationKey<?> ANY_GAV =
105       new EnvAppConfigurationKey(EnvironmentId.ANY_ENV, APP_ALL);
106 
107   // --- members --------------------------------------------------------------
108 
109   @Uut
110   private EnvAppKeyListBuilder uut;
111 
112   // ****************************** Inner Classes *****************************
113 
114   // ********************************* Methods ********************************
115 
116   // --- prepare --------------------------------------------------------------
117 
118   @Before
119   public void setUp()
120   {
121     uut = new EnvAppKeyListBuilder();
122   }
123 
124   // --- helper ---------------------------------------------------------------
125 
126   // --- tests ----------------------------------------------------------------
127 
128   @Test
129   @SuppressWarnings(StaticAnalysis.UNCHECKED)
130   public void derivesFromKeyWithOnlyAnEnvironmentName()
131   {
132     final List<ConfigurationKey<?>> keySet = uut.createKeyList(E);
133 
134     assertThat(keySet, is(Arrays.asList(E, ANY)));
135   }
136 
137   @Test
138   @SuppressWarnings(StaticAnalysis.UNCHECKED)
139   public void derivesFromKeyWithEnvironmentNameAndNode()
140   {
141     final List<ConfigurationKey<?>> keySet = uut.createKeyList(EN);
142 
143     assertThat(keySet, is(Arrays.asList(EN, E, ANY)));
144   }
145 
146   @Test
147   @SuppressWarnings(StaticAnalysis.UNCHECKED)
148   public void derivesFromKeyWithFullEnvironmentNameOnlyAndGroup()
149   {
150     final List<ConfigurationKey<?>> keySet = uut.createKeyList(E_G);
151 
152     assertThat(keySet, is(Arrays.asList(E_G, E, ANY_G, ANY)));
153   }
154 
155   @Test
156   @SuppressWarnings(StaticAnalysis.UNCHECKED)
157   public void derivesFromKeyWithFullEnvironmentAndGroup()
158   {
159     final List<ConfigurationKey<?>> keySet = uut.createKeyList(EN_G);
160 
161     assertThat(keySet, is(Arrays.asList(EN_G, EN, E, ANY_G, ANY)));
162   }
163 
164   @Test
165   @SuppressWarnings(StaticAnalysis.UNCHECKED)
166   public void derivesFromKeyWithFullEnvironmentNameOnlyAndGA()
167   {
168     final List<ConfigurationKey<?>> keySet = uut.createKeyList(E_GA);
169 
170     assertThat(keySet, is(Arrays.asList(E_GA, E_G, E, ANY_GA, ANY_G, ANY)));
171   }
172 
173   @Test
174   @SuppressWarnings(StaticAnalysis.UNCHECKED)
175   public void derivesFromKeyWithFullEnvironmentAndGA()
176   {
177     final List<ConfigurationKey<?>> keySet = uut.createKeyList(EN_GA);
178 
179     assertThat(keySet,
180         is(Arrays.asList(EN_GA, EN_G, EN, E_G, E, ANY_GA, ANY_G, ANY)));
181   }
182 
183   @Test
184   @SuppressWarnings(StaticAnalysis.UNCHECKED)
185   public void derivesFromKeyWithFullEnvironmentNameOnlyAndGAV()
186   {
187     final List<ConfigurationKey<?>> keySet = uut.createKeyList(E_GAV);
188 
189     assertThat(keySet,
190         is(Arrays.asList(E_GAV, E_GA, E_G, E, ANY_GAV, ANY_GA, ANY_G, ANY)));
191   }
192 
193   @Test
194   @SuppressWarnings(StaticAnalysis.UNCHECKED)
195   public void derivesFromKeyWithFullEnvironmentAndGAV()
196   {
197     final List<ConfigurationKey<?>> keySet = uut.createKeyList(EN_GAV);
198 
199     assertThat(keySet, is(Arrays.asList(EN_GAV, EN_GA, EN_G, EN, E_GAV, E_GA,
200         E_G, E, ANY_GAV, ANY_GA, ANY_G, ANY)));
201   }
202 }