2 * ============LICENSE_START=======================================================
3 * SPARKY (AAI UI service)
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.openecomp.sparky.dal.aai.config;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.assertNull;
32 import static org.junit.Assert.assertTrue;
34 import java.util.ArrayList;
35 import java.util.List;
36 import java.util.Properties;
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.openecomp.sparky.dal.aai.enums.RestAuthenticationMode;
43 public class ActiveInventoryRestConfigTest {
46 * Test case initialization
48 * @throws Exception the exception
51 public void init() throws Exception {}
53 private Properties buildExpectedPropertyDefinition() throws Exception {
55 Properties props = new Properties();
57 props.put("aai.rest.resourceBasePath", "/aai/v9");
58 props.put("aai.rest.host", "1.2.3.4");
59 props.put("aai.rest.port", "4321");
60 props.put("aai.rest.numRequestRetries", "100");
61 props.put("aai.rest.numResolverWorkers", "50");
62 props.put("aai.rest.maxConcurrentWorkers", "50");
63 props.put("aai.rest.connectTimeoutInMs", "1000");
64 props.put("aai.rest.readTimeoutInMs", "1500");
65 props.put("aai.rest.shallowEntities", "a,b,c,d");
66 props.put("aai.rest.authenticationMode", "HTTP_NOAUTH");
68 props.put("aai.rest.cache.enabled", "true");
69 props.put("aai.rest.cache.storageFolderOverride", "folderOverride");
70 props.put("aai.rest.cache.cacheFailures", "true");
71 props.put("aai.rest.cache.useCacheOnly", "true");
72 props.put("aai.rest.cache.numWorkers", "50");
73 props.put("aai.rest.cache.maxTimeToLiveInMs", "500");
80 * Success path initialization and validation of accessors
85 public void successfulInitialization() throws Exception {
87 ActiveInventoryRestConfig config =
88 new ActiveInventoryRestConfig(buildExpectedPropertyDefinition());
91 * Now verify that all the internal members have been set to default values
94 assertEquals(config.getResourceBasePath(), "/aai/v9");
95 assertEquals(config.getHost(), "1.2.3.4");
96 assertEquals(config.getPort(), "4321");
97 assertEquals(config.getNumRequestRetries(), 100);
98 assertEquals(config.getNumResolverWorkers(), 50);
99 assertEquals(config.getConnectTimeoutInMs(), 1000);
100 assertEquals(config.getReadTimeoutInMs(), 1500);
102 List<String> expectedEntities = new ArrayList<String>();
103 expectedEntities.add("a");
104 expectedEntities.add("b");
105 expectedEntities.add("c");
106 expectedEntities.add("d");
108 assertEquals(config.getShallowEntities().size(), 4);
109 assertTrue(config.getShallowEntities().containsAll(expectedEntities));
110 assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.HTTP_NOAUTH);
112 assertTrue(config.isCacheEnabled());
113 assertEquals(config.getStorageFolderOverride(), "folderOverride");
114 assertTrue(config.shouldCacheFailures());
115 assertTrue(config.isUseCacheOnly());
116 assertEquals(config.getNumCacheWorkers(), 50);
117 assertEquals(config.getMaxTimeToLiveInMs(), 500);
123 * Failed path initialization
128 public void validateInitializationWithNullProperties() throws Exception {
131 * Setup encryptor expectations
134 ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(null);
137 * Now verify that all the internal members have been set to default values
140 assertNull(config.getResourceBasePath());
141 assertNull(config.getHost());
142 assertNull(config.getPort());
143 assertEquals(config.getNumRequestRetries(), 0);
144 assertEquals(config.getNumResolverWorkers(), 0);
145 assertEquals(config.getConnectTimeoutInMs(), 0);
146 assertEquals(config.getReadTimeoutInMs(), 0);
148 assertNull(config.getShallowEntities());
149 assertNull(config.getAuthenticationMode());
151 assertFalse(config.isCacheEnabled());
152 assertNull(config.getStorageFolderOverride());
153 assertFalse(config.shouldCacheFailures());
154 assertFalse(config.isUseCacheOnly());
155 assertEquals(config.getNumCacheWorkers(), 0);
156 assertEquals(config.getMaxTimeToLiveInMs(), 0);
161 * Failed path initialization
166 public void validateInitializationWithInvalidProperties() throws Exception {
169 * Setup encryptor expectations
172 ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(new Properties());
175 * Now verify that all the internal members have been set to default values
178 assertEquals(config.getResourceBasePath(), "/aai/v7");
179 assertEquals(config.getHost(), "localhost");
180 assertEquals(config.getPort(), "8443");
181 assertEquals(config.getNumRequestRetries(), 5);
182 assertEquals(config.getNumResolverWorkers(), 15);
183 assertEquals(config.getConnectTimeoutInMs(), 5000);
184 assertEquals(config.getReadTimeoutInMs(), 10000);
186 assertEquals(config.getShallowEntities().size(), 1);
187 assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.SSL_CERT);
189 assertFalse(config.isCacheEnabled());
190 assertNull(config.getStorageFolderOverride());
191 assertFalse(config.shouldCacheFailures());
192 assertFalse(config.isUseCacheOnly());
193 assertEquals(config.getNumCacheWorkers(), 5);
194 assertEquals(config.getMaxTimeToLiveInMs(), -1);
199 * Class accessor validator
204 public void validateClassAccessors() throws Exception {
207 * Setup encryptor expectations
210 ActiveInventoryRestConfig config =
211 new ActiveInventoryRestConfig(buildExpectedPropertyDefinition());
214 * Now verify that all the internal members have been set to default values
217 config.setAuthenticationMode(RestAuthenticationMode.SSL_BASIC);
218 config.setCacheEnabled(true);
219 config.setConnectTimeoutInMs(1000);
220 config.setHost("myhost");
221 config.setMaxTimeToLiveInMs(1234);
222 config.setNumCacheWorkers(1000);
223 config.setNumRequestRetries(1500);
224 config.setNumResolverWorkers(150);
225 config.setPort("11223344");
226 config.setReadTimeoutInMs(54321);
227 config.setResourceBasePath("/aai/v21");
228 config.setStorageFolderOverride("override");
229 config.setUseCacheOnly(true);
230 config.setShouldCacheFailures(true);
232 assertEquals(config.getResourceBasePath(), "/aai/v21");
233 assertEquals(config.getHost(), "myhost");
234 assertEquals(config.getPort(), "11223344");
235 assertEquals(config.getNumRequestRetries(), 1500);
236 assertEquals(config.getNumResolverWorkers(), 150);
237 assertEquals(config.getConnectTimeoutInMs(), 1000);
238 assertEquals(config.getReadTimeoutInMs(), 54321);
239 assertTrue(config.shouldCacheFailures());
241 List<String> expectedEntities = new ArrayList<String>();
242 expectedEntities.add("a");
243 expectedEntities.add("b");
244 expectedEntities.add("c");
245 expectedEntities.add("d");
247 assertEquals(config.getShallowEntities().size(), 4);
248 assertTrue(config.getShallowEntities().containsAll(expectedEntities));
249 assertTrue(config.isShallowEntity("b"));
250 assertFalse(config.isShallowEntity("f"));
251 assertFalse(config.isShallowEntity(null));
252 assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.SSL_BASIC);
254 assertTrue(config.isCacheEnabled());
255 assertEquals(config.getStorageFolderOverride(), "override");
256 assertTrue(config.shouldCacheFailures());
257 assertTrue(config.isUseCacheOnly());
258 assertEquals(config.getNumCacheWorkers(), 1000);
259 assertEquals(config.getMaxTimeToLiveInMs(), 1234);
261 assertTrue(config.toString().contains("ActiveInventoryRestConfig"));
267 * Validate auth mode edge cases
272 public void validateUnknownAuthModeDefaultsToSslCert() throws Exception {
275 * Setup encryptor expectations
278 Properties props = buildExpectedPropertyDefinition();
279 props.setProperty("aai.rest.authenticationMode", "invalid mode");
280 props.setProperty("aai.rest.storageFolderOverride", "");
282 ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(props);
285 * Now verify that all the internal members have been set to default values
288 assertNotNull(config.getShallowEntities());
289 assertEquals(RestAuthenticationMode.SSL_CERT, config.getAuthenticationMode());