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.onap.aai.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.onap.aai.sparky.dal.aai.config.ActiveInventoryRestConfig;
41 import org.onap.aai.sparky.dal.aai.enums.RestAuthenticationMode;
44 public class ActiveInventoryRestConfigTest {
47 * Test case initialization
49 * @throws Exception the exception
52 public void init() throws Exception {}
54 private Properties buildExpectedPropertyDefinition() throws Exception {
56 Properties props = new Properties();
58 props.put("aai.rest.resourceBasePath", "/aai/v9");
59 props.put("aai.rest.host", "1.2.3.4");
60 props.put("aai.rest.port", "4321");
61 props.put("aai.rest.numRequestRetries", "100");
62 props.put("aai.rest.numResolverWorkers", "50");
63 props.put("aai.rest.maxConcurrentWorkers", "50");
64 props.put("aai.rest.connectTimeoutInMs", "1000");
65 props.put("aai.rest.readTimeoutInMs", "1500");
66 props.put("aai.rest.shallowEntities", "a,b,c,d");
67 props.put("aai.rest.authenticationMode", "HTTP_NOAUTH");
69 props.put("aai.rest.cache.enabled", "true");
70 props.put("aai.rest.cache.storageFolderOverride", "folderOverride");
71 props.put("aai.rest.cache.cacheFailures", "true");
72 props.put("aai.rest.cache.useCacheOnly", "true");
73 props.put("aai.rest.cache.numWorkers", "50");
74 props.put("aai.rest.cache.maxTimeToLiveInMs", "500");
81 * Success path initialization and validation of accessors
86 public void successfulInitialization() throws Exception {
88 ActiveInventoryRestConfig config =
89 new ActiveInventoryRestConfig(buildExpectedPropertyDefinition());
92 * Now verify that all the internal members have been set to default values
95 assertEquals(config.getResourceBasePath(), "/aai/v9");
96 assertEquals(config.getHost(), "1.2.3.4");
97 assertEquals(config.getPort(), "4321");
98 assertEquals(config.getNumRequestRetries(), 100);
99 assertEquals(config.getNumResolverWorkers(), 50);
100 assertEquals(config.getConnectTimeoutInMs(), 1000);
101 assertEquals(config.getReadTimeoutInMs(), 1500);
103 List<String> expectedEntities = new ArrayList<String>();
104 expectedEntities.add("a");
105 expectedEntities.add("b");
106 expectedEntities.add("c");
107 expectedEntities.add("d");
109 assertEquals(config.getShallowEntities().size(), 4);
110 assertTrue(config.getShallowEntities().containsAll(expectedEntities));
111 assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.HTTP_NOAUTH);
113 assertTrue(config.isCacheEnabled());
114 assertEquals(config.getStorageFolderOverride(), "folderOverride");
115 assertTrue(config.shouldCacheFailures());
116 assertTrue(config.isUseCacheOnly());
117 assertEquals(config.getNumCacheWorkers(), 50);
118 assertEquals(config.getMaxTimeToLiveInMs(), 500);
124 * Failed path initialization
129 public void validateInitializationWithNullProperties() throws Exception {
132 * Setup encryptor expectations
135 ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(null);
138 * Now verify that all the internal members have been set to default values
141 assertNull(config.getResourceBasePath());
142 assertNull(config.getHost());
143 assertNull(config.getPort());
144 assertEquals(config.getNumRequestRetries(), 0);
145 assertEquals(config.getNumResolverWorkers(), 0);
146 assertEquals(config.getConnectTimeoutInMs(), 0);
147 assertEquals(config.getReadTimeoutInMs(), 0);
149 assertNull(config.getShallowEntities());
150 assertNull(config.getAuthenticationMode());
152 assertFalse(config.isCacheEnabled());
153 assertNull(config.getStorageFolderOverride());
154 assertFalse(config.shouldCacheFailures());
155 assertFalse(config.isUseCacheOnly());
156 assertEquals(config.getNumCacheWorkers(), 0);
157 assertEquals(config.getMaxTimeToLiveInMs(), 0);
162 * Failed path initialization
167 public void validateInitializationWithInvalidProperties() throws Exception {
170 * Setup encryptor expectations
173 ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(new Properties());
176 * Now verify that all the internal members have been set to default values
179 assertEquals(config.getResourceBasePath(), "/aai/v7");
180 assertEquals(config.getHost(), "localhost");
181 assertEquals(config.getPort(), "8443");
182 assertEquals(config.getNumRequestRetries(), 5);
183 assertEquals(config.getNumResolverWorkers(), 15);
184 assertEquals(config.getConnectTimeoutInMs(), 5000);
185 assertEquals(config.getReadTimeoutInMs(), 10000);
187 assertEquals(config.getShallowEntities().size(), 1);
188 assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.SSL_CERT);
190 assertFalse(config.isCacheEnabled());
191 assertNull(config.getStorageFolderOverride());
192 assertFalse(config.shouldCacheFailures());
193 assertFalse(config.isUseCacheOnly());
194 assertEquals(config.getNumCacheWorkers(), 5);
195 assertEquals(config.getMaxTimeToLiveInMs(), -1);
200 * Class accessor validator
205 public void validateClassAccessors() throws Exception {
208 * Setup encryptor expectations
211 ActiveInventoryRestConfig config =
212 new ActiveInventoryRestConfig(buildExpectedPropertyDefinition());
215 * Now verify that all the internal members have been set to default values
218 config.setAuthenticationMode(RestAuthenticationMode.SSL_BASIC);
219 config.setCacheEnabled(true);
220 config.setConnectTimeoutInMs(1000);
221 config.setHost("myhost");
222 config.setMaxTimeToLiveInMs(1234);
223 config.setNumCacheWorkers(1000);
224 config.setNumRequestRetries(1500);
225 config.setNumResolverWorkers(150);
226 config.setPort("11223344");
227 config.setReadTimeoutInMs(54321);
228 config.setResourceBasePath("/aai/v21");
229 config.setStorageFolderOverride("override");
230 config.setUseCacheOnly(true);
231 config.setShouldCacheFailures(true);
233 assertEquals(config.getResourceBasePath(), "/aai/v21");
234 assertEquals(config.getHost(), "myhost");
235 assertEquals(config.getPort(), "11223344");
236 assertEquals(config.getNumRequestRetries(), 1500);
237 assertEquals(config.getNumResolverWorkers(), 150);
238 assertEquals(config.getConnectTimeoutInMs(), 1000);
239 assertEquals(config.getReadTimeoutInMs(), 54321);
240 assertTrue(config.shouldCacheFailures());
242 List<String> expectedEntities = new ArrayList<String>();
243 expectedEntities.add("a");
244 expectedEntities.add("b");
245 expectedEntities.add("c");
246 expectedEntities.add("d");
248 assertEquals(config.getShallowEntities().size(), 4);
249 assertTrue(config.getShallowEntities().containsAll(expectedEntities));
250 assertTrue(config.isShallowEntity("b"));
251 assertFalse(config.isShallowEntity("f"));
252 assertFalse(config.isShallowEntity(null));
253 assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.SSL_BASIC);
255 assertTrue(config.isCacheEnabled());
256 assertEquals(config.getStorageFolderOverride(), "override");
257 assertTrue(config.shouldCacheFailures());
258 assertTrue(config.isUseCacheOnly());
259 assertEquals(config.getNumCacheWorkers(), 1000);
260 assertEquals(config.getMaxTimeToLiveInMs(), 1234);
262 assertTrue(config.toString().contains("ActiveInventoryRestConfig"));
268 * Validate auth mode edge cases
273 public void validateUnknownAuthModeDefaultsToSslCert() throws Exception {
276 * Setup encryptor expectations
279 Properties props = buildExpectedPropertyDefinition();
280 props.setProperty("aai.rest.authenticationMode", "invalid mode");
281 props.setProperty("aai.rest.storageFolderOverride", "");
283 ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(props);
286 * Now verify that all the internal members have been set to default values
289 assertNotNull(config.getShallowEntities());
290 assertEquals(RestAuthenticationMode.SSL_CERT, config.getAuthenticationMode());