1 package org.onap.aai.sparky.dal.aai.config;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertNull;
7 import static org.junit.Assert.assertTrue;
10 import java.util.Properties;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
15 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryRestConfig;
16 import org.onap.aai.sparky.dal.aai.config.ActiveInventorySslConfig;
17 import org.onap.aai.sparky.dal.aai.enums.RestAuthenticationMode;
18 import org.onap.aai.sparky.synchronizer.config.TaskProcessorConfig;
19 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;
21 public class ActiveInventoryConfigTest {
24 * Test case initialization
26 * @throws Exception the exception
29 public void init() throws Exception {
30 String configHomePath =
31 (new File(".").getCanonicalPath() + "/src/test/resources/appconfig/").replace('\\', '/');
32 TierSupportUiConstants.AJSC_HOME = configHomePath;
33 TierSupportUiConstants.CONFIG_HOME = configHomePath;
34 TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION = configHomePath;
38 public void validateBasicConstruction_emptyProperties() throws Exception {
40 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
42 assertNotNull(config);
46 private Properties getTestProperties() {
48 Properties props = new Properties();
50 props.put("aai.rest.host", "aai-host");
51 props.put("aai.rest.port", "8443");
52 props.put("aai.rest.resourceBasePath", "/aai/v10");
53 props.put("aai.rest.connectTimeoutInMs", "30000");
54 props.put("aai.rest.readTimeoutInMs", "60000");
55 props.put("aai.rest.numRequestRetries", "5");
56 props.put("aai.rest.numResolverWorkers", "15");
58 props.put("aai.rest.cache.enabled", "false");
59 props.put("aai.rest.cache.numWorkers", "10");
60 props.put("aai.rest.cache.cacheFailures", "false");
61 props.put("aai.rest.cache.useCacheOnly", "false");
62 props.put("aai.rest.cache.storageFolderOverride", "");
63 props.put("aai.rest.cache.maxTimeToLiveInMs", "-1");
65 props.put("aai.rest.shallowEntities", "cloud-region,complex,vnf-image,image");
67 props.put("aai.ssl.truststore.filename", "synchronizer.jks");
68 props.put("aai.ssl.truststore.type", "jks");
70 props.put("aai.ssl.keystore.filename", "aai-client-cert.p12");
71 props.put("aai.ssl.keystore.pass", "70c87528c88dcd9f9c2558d30e817868");
72 props.put("aai.ssl.keystore.type", "pkcs12");
74 props.put("aai.ssl.enableDebug", "false");
75 props.put("aai.ssl.validateServerHostName", "false");
76 props.put("aai.ssl.validateServerCertificateChain", "false");
78 props.put("aai.rest.authenticationMode", "SSL_CERT");
79 props.put("aai.ssl.basicAuth.username", "");
80 props.put("aai.ssl.basicAuth.password", "");
82 props.put("aai.taskProcessor.maxConcurrentWorkers", "5");
84 props.put("aai.taskProcessor.transactionRateControllerEnabled", "false");
85 props.put("aai.taskProcessor.numSamplesPerThreadForRunningAverage", "100");
86 props.put("aai.taskProcessor.targetTPS", "100");
88 props.put("aai.taskProcessor.bytesHistogramLabel", "[Response Size In Bytes]");
89 props.put("aai.taskProcessor.bytesHistogramMaxYAxis", "1000000");
90 props.put("aai.taskProcessor.bytesHistogramNumBins", "20");
91 props.put("aai.taskProcessor.bytesHistogramNumDecimalPoints", "2");
93 props.put("aai.taskProcessor.queueLengthHistogramLabel", "[Queue Item Length]");
94 props.put("aai.taskProcessor.queueLengthHistogramMaxYAxis", "20000");
95 props.put("aai.taskProcessor.queueLengthHistogramNumBins", "20");
96 props.put("aai.taskProcessor.queueLengthHistogramNumDecimalPoints", "2");
98 props.put("aai.taskProcessor.taskAgeHistogramLabel", "[Task Age In Ms]");
99 props.put("aai.taskProcessor.taskAgeHistogramMaxYAxis", "600000");
100 props.put("aai.taskProcessor.taskAgeHistogramNumBins", "20");
101 props.put("aai.taskProcessor.taskAgeHistogramNumDecimalPoints", "2");
103 props.put("aai.taskProcessor.responseTimeHistogramLabel", "[Response Time In Ms]");
104 props.put("aai.taskProcessor.responseTimeHistogramMaxYAxis", "10000");
105 props.put("aai.taskProcessor.responseTimeHistogramNumBins", "20");
106 props.put("aai.taskProcessor.responseTimeHistogramNumDecimalPoints", "2");
108 props.put("aai.taskProcessor.tpsHistogramLabel", "[Transactions Per Second]");
109 props.put("aai.taskProcessor.tpsHistogramMaxYAxis", "100");
110 props.put("aai.taskProcessor.tpsHistogramNumBins", "20");
111 props.put("aai.taskProcessor.tpsHistogramNumDecimalPoints", "2");
120 public void validateAccessors() throws Exception {
122 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
124 ActiveInventoryRestConfig airc = config.getAaiRestConfig();
125 ActiveInventorySslConfig sslConfig = config.getAaiSslConfig();
126 TaskProcessorConfig tpc = config.getTaskProcessorConfig();
129 assertNotNull(sslConfig);
132 assertEquals("https://aai-host:8443/aai/v10", config.getBaseUri().toString());
134 assertTrue(config.toString().contains("ActiveInventoryConfig"));
136 config.setAaiRestConfig(null);
137 config.setAaiSslConfig(null);
138 config.setTaskProcessorConfig(null);
140 assertNull(config.getAaiRestConfig());
141 assertNull(config.getAaiSslConfig());
142 assertNull(config.getTaskProcessorConfig());
144 config.setAaiRestConfig(airc);
145 config.setAaiSslConfig(sslConfig);
146 config.setTaskProcessorConfig(tpc);
152 public void validateRepairSelfLink_nullLink() throws Exception {
154 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
156 ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
158 restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);
159 restConfig.setHost("aai-host");
160 restConfig.setPort("9191");
162 assertNull(config.repairSelfLink(null));
166 public void validateRepairSelfLink_emptyString() throws Exception {
168 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
170 ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
172 restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);
173 restConfig.setHost("aai-host");
174 restConfig.setPort("9191");
176 assertEquals("http://aai-host:9191", config.repairSelfLink(""));
180 public void validateRepairSelfLink_withResourceUrl() throws Exception {
182 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
184 ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
186 restConfig.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);
187 restConfig.setHost("aai-host");
188 restConfig.setPort("9191");
190 assertEquals("https://aai-host:9191/aai/v10/business/customers/customer/1234",
191 config.repairSelfLink("/aai/v10/business/customers/customer/1234"));
195 public void validateResourcePathExtraction() throws Exception {
196 // https with API version
197 assertEquals("/aai/v10/business/customers/customer/1234", ActiveInventoryConfig
198 .extractResourcePath("https://aai-host:9191/aai/v10/business/customers/customer/1234"));
200 // https without API version
201 assertEquals("/business/customers/customer/1234", ActiveInventoryConfig
202 .extractResourcePath("https://aai-host:9191/business/customers/customer/1234"));
204 // http with API version
205 assertEquals("/aai/v10/business/customers/customer/1234", ActiveInventoryConfig
206 .extractResourcePath("http://aai-host:9191/aai/v10/business/customers/customer/1234"));
208 // http without API verison
209 assertEquals("/business/customers/customer/1234", ActiveInventoryConfig
210 .extractResourcePath("http://aai-host:9191/business/customers/customer/1234"));
212 // no scheme, host, or port
213 assertEquals("business/customers/customer/1234",
214 ActiveInventoryConfig.extractResourcePath("business/customers/customer/1234"));
216 // no scheme, host, or port with API version
217 assertEquals("/aai/v10/business/customers/customer/1234",
218 ActiveInventoryConfig.extractResourcePath("/aai/v10/business/customers/customer/1234"));
220 // no scheme, host, or port with API version
221 assertEquals("", ActiveInventoryConfig.extractResourcePath(""));