2 * ============LICENSE_START=================================================== SPARKY (AAI UI
3 * service) ============================================================================ Copyright ©
4 * 2017 AT&T Intellectual Property. Copyright © 2017 Amdocs All rights reserved.
5 * ============================================================================ Licensed under the
6 * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License
12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing permissions and limitations under
14 * the License. ============LICENSE_END=====================================================
16 * ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property.
19 package org.onap.aai.sparky.dal.aai.config;
21 * import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import
22 * static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static
23 * org.junit.Assert.assertTrue;
25 * import java.util.ArrayList; import java.util.List; import java.util.Properties;
27 * import org.junit.Before; import org.junit.Test; import
28 * org.onap.aai.sparky.dal.aai.config.ActiveInventoryRestConfig; import
29 * org.onap.aai.sparky.dal.aai.enums.RestAuthenticationMode;
32 * public class ActiveInventoryRestConfigTest {
34 * /** Test case initialization
36 * @throws Exception the exception
38 * @Before public void init() throws Exception {}
40 * private Properties buildExpectedPropertyDefinition() throws Exception {
42 * Properties props = new Properties();
44 * props.put("aai.rest.resourceBasePath", "/aai/v9"); props.put("aai.rest.host", "1.2.3.4");
45 * props.put("aai.rest.port", "4321"); props.put("aai.rest.numRequestRetries", "100");
46 * props.put("aai.rest.numResolverWorkers", "50"); props.put("aai.rest.maxConcurrentWorkers", "50");
47 * props.put("aai.rest.connectTimeoutInMs", "1000"); props.put("aai.rest.readTimeoutInMs", "1500");
48 * props.put("aai.rest.shallowEntities", "a,b,c,d"); props.put("aai.rest.authenticationMode",
51 * props.put("aai.rest.cache.enabled", "true"); props.put("aai.rest.cache.storageFolderOverride",
52 * "folderOverride"); props.put("aai.rest.cache.cacheFailures", "true");
53 * props.put("aai.rest.cache.useCacheOnly", "true"); props.put("aai.rest.cache.numWorkers", "50");
54 * props.put("aai.rest.cache.maxTimeToLiveInMs", "500");
59 * /** Success path initialization and validation of accessors
63 * @Test public void successfulInitialization() throws Exception {
65 * ActiveInventoryRestConfig config = new
66 * ActiveInventoryRestConfig(buildExpectedPropertyDefinition());
68 * /* Now verify that all the internal members have been set to default values
71 * assertEquals(config.getHost(), "1.2.3.4"); assertEquals(config.getPort(), "4321");
72 * assertEquals(config.getNumRequestRetries(), 100); assertEquals(config.getNumResolverWorkers(),
73 * 50); assertEquals(config.getConnectTimeoutInMs(), 1000);
74 * assertEquals(config.getReadTimeoutInMs(), 1500);
76 * List<String> expectedEntities = new ArrayList<String>(); expectedEntities.add("a");
77 * expectedEntities.add("b"); expectedEntities.add("c"); expectedEntities.add("d");
79 * assertEquals(config.getShallowEntities().size(), 4);
80 * assertTrue(config.getShallowEntities().containsAll(expectedEntities));
81 * assertEquals(config.getAuthenticationMode(), RestAuthenticationMode.HTTP_NOAUTH);
85 * /** Failed path initialization
89 * @Test public void validateInitializationWithNullProperties() throws Exception {
91 * /* Setup encryptor expectations
94 * ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(null);
96 * /* Now verify that all the internal members have been set to default values
99 * assertNull(config.getHost()); assertNull(config.getPort());
100 * assertEquals(config.getNumRequestRetries(), 0); assertEquals(config.getNumResolverWorkers(), 0);
101 * assertEquals(config.getConnectTimeoutInMs(), 0); assertEquals(config.getReadTimeoutInMs(), 0);
103 * assertNull(config.getShallowEntities()); assertNull(config.getAuthenticationMode());
107 * /** Failed path initialization
111 * @Test public void validateInitializationWithInvalidProperties() throws Exception {
113 * /* Setup encryptor expectations
116 * ActiveInventoryRestConfig config = new
117 * ActiveInventoryRestConfig(ActiveInventoryConfigUtil.getinvalidTestProperties());
119 * /* Now verify that all the internal members have been set to default values
122 * assertEquals(config.getHost(), "localhost"); assertEquals(config.getPort(), "8443");
123 * assertEquals(config.getNumRequestRetries(), 5); assertEquals(config.getNumResolverWorkers(), 15);
124 * assertEquals(config.getConnectTimeoutInMs(), 5000); assertEquals(config.getReadTimeoutInMs(),
127 * assertEquals(config.getShallowEntities().size(), 1); assertEquals(config.getAuthenticationMode(),
128 * RestAuthenticationMode.SSL_CERT);
132 * /** Class accessor validator
136 * @Test public void validateClassAccessors() throws Exception {
138 * /* Setup encryptor expectations
141 * ActiveInventoryRestConfig config = new
142 * ActiveInventoryRestConfig(buildExpectedPropertyDefinition());
144 * /* Now verify that all the internal members have been set to default values
147 * config.setAuthenticationMode(RestAuthenticationMode.SSL_BASIC);
148 * config.setConnectTimeoutInMs(1000); config.setHost("myhost"); config.setNumRequestRetries(1500);
149 * config.setNumResolverWorkers(150); config.setPort("11223344"); config.setReadTimeoutInMs(54321);
151 * assertEquals(config.getHost(), "myhost"); assertEquals(config.getPort(), "11223344");
152 * assertEquals(config.getNumRequestRetries(), 1500); assertEquals(config.getNumResolverWorkers(),
153 * 150); assertEquals(config.getConnectTimeoutInMs(), 1000);
154 * assertEquals(config.getReadTimeoutInMs(), 54321);
156 * List<String> expectedEntities = new ArrayList<String>(); expectedEntities.add("a");
157 * expectedEntities.add("b"); expectedEntities.add("c"); expectedEntities.add("d");
159 * assertEquals(config.getShallowEntities().size(), 4);
160 * assertTrue(config.getShallowEntities().containsAll(expectedEntities));
161 * assertTrue(config.isShallowEntity("b")); assertFalse(config.isShallowEntity("f"));
162 * assertFalse(config.isShallowEntity(null)); assertEquals(config.getAuthenticationMode(),
163 * RestAuthenticationMode.SSL_BASIC);
165 * assertTrue(config.toString().contains("ActiveInventoryRestConfig"));
170 * /** Validate auth mode edge cases
174 * @Test public void validateUnknownAuthModeDefaultsToSslCert() throws Exception {
176 * /* Setup encryptor expectations
179 * Properties props = buildExpectedPropertyDefinition();
180 * props.setProperty("aai.rest.authenticationMode", "invalid mode");
181 * props.setProperty("aai.rest.storageFolderOverride", "");
183 * ActiveInventoryRestConfig config = new ActiveInventoryRestConfig(props);
185 * /* Now verify that all the internal members have been set to default values
188 * assertNotNull(config.getShallowEntities()); assertEquals(RestAuthenticationMode.SSL_CERT,
189 * config.getAuthenticationMode());