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;
9 import java.util.Properties;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
14 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryRestConfig;
15 import org.onap.aai.sparky.dal.aai.config.ActiveInventorySslConfig;
16 import org.onap.aai.sparky.dal.aai.enums.RestAuthenticationMode;
17 import org.onap.aai.sparky.synchronizer.config.TaskProcessorConfig;
19 public class ActiveInventoryConfigTest {
22 * Test case initialization
24 * @throws Exception the exception
27 public void init() throws Exception {}
30 public void validateBasicConstruction_emptyProperties() throws Exception {
32 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
34 assertNotNull(config);
38 private Properties getTestProperties() {
40 Properties props = new Properties();
42 props.put("aai.rest.host","aai-host");
43 props.put("aai.rest.port","8443");
44 props.put("aai.rest.resourceBasePath","/aai/v10");
45 props.put("aai.rest.connectTimeoutInMs","30000");
46 props.put("aai.rest.readTimeoutInMs","60000");
47 props.put("aai.rest.numRequestRetries","5");
48 props.put("aai.rest.numResolverWorkers","15");
50 props.put("aai.rest.cache.enabled","false");
51 props.put("aai.rest.cache.numWorkers","10");
52 props.put("aai.rest.cache.cacheFailures","false");
53 props.put("aai.rest.cache.useCacheOnly","false");
54 props.put("aai.rest.cache.storageFolderOverride","");
55 props.put("aai.rest.cache.maxTimeToLiveInMs","-1");
57 props.put("aai.rest.shallowEntities","cloud-region,complex,vnf-image,image");
59 props.put("aai.ssl.truststore.filename","synchronizer.jks");
60 props.put("aai.ssl.truststore.type","jks");
62 props.put("aai.ssl.keystore.filename","aai-client-cert.p12");
63 props.put("aai.ssl.keystore.pass","70c87528c88dcd9f9c2558d30e817868");
64 props.put("aai.ssl.keystore.type","pkcs12");
66 props.put("aai.ssl.enableDebug","false");
67 props.put("aai.ssl.validateServerHostName","false");
68 props.put("aai.ssl.validateServerCertificateChain","false");
70 props.put("aai.rest.authenticationMode","SSL_CERT");
71 props.put("aai.ssl.basicAuth.username","");
72 props.put("aai.ssl.basicAuth.password","");
74 props.put("aai.taskProcessor.maxConcurrentWorkers","5");
76 props.put("aai.taskProcessor.transactionRateControllerEnabled","false");
77 props.put("aai.taskProcessor.numSamplesPerThreadForRunningAverage","100");
78 props.put("aai.taskProcessor.targetTPS","100");
80 props.put("aai.taskProcessor.bytesHistogramLabel","[Response Size In Bytes]");
81 props.put("aai.taskProcessor.bytesHistogramMaxYAxis","1000000");
82 props.put("aai.taskProcessor.bytesHistogramNumBins","20");
83 props.put("aai.taskProcessor.bytesHistogramNumDecimalPoints","2");
85 props.put("aai.taskProcessor.queueLengthHistogramLabel","[Queue Item Length]");
86 props.put("aai.taskProcessor.queueLengthHistogramMaxYAxis","20000");
87 props.put("aai.taskProcessor.queueLengthHistogramNumBins","20");
88 props.put("aai.taskProcessor.queueLengthHistogramNumDecimalPoints","2");
90 props.put("aai.taskProcessor.taskAgeHistogramLabel","[Task Age In Ms]");
91 props.put("aai.taskProcessor.taskAgeHistogramMaxYAxis","600000");
92 props.put("aai.taskProcessor.taskAgeHistogramNumBins","20");
93 props.put("aai.taskProcessor.taskAgeHistogramNumDecimalPoints","2");
95 props.put("aai.taskProcessor.responseTimeHistogramLabel","[Response Time In Ms]");
96 props.put("aai.taskProcessor.responseTimeHistogramMaxYAxis","10000");
97 props.put("aai.taskProcessor.responseTimeHistogramNumBins","20");
98 props.put("aai.taskProcessor.responseTimeHistogramNumDecimalPoints","2");
100 props.put("aai.taskProcessor.tpsHistogramLabel","[Transactions Per Second]");
101 props.put("aai.taskProcessor.tpsHistogramMaxYAxis","100");
102 props.put("aai.taskProcessor.tpsHistogramNumBins","20");
103 props.put("aai.taskProcessor.tpsHistogramNumDecimalPoints","2");
112 public void validateAccessors() throws Exception {
114 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
116 ActiveInventoryRestConfig airc = config.getAaiRestConfig();
117 ActiveInventorySslConfig sslConfig = config.getAaiSslConfig();
118 TaskProcessorConfig tpc = config.getTaskProcessorConfig();
121 assertNotNull(sslConfig);
124 assertEquals("https://aai-host:8443/aai/v10", config.getBaseUri().toString());
126 assertTrue(config.toString().contains("ActiveInventoryConfig"));
128 config.setAaiRestConfig(null);
129 config.setAaiSslConfig(null);
130 config.setTaskProcessorConfig(null);
132 assertNull(config.getAaiRestConfig());
133 assertNull(config.getAaiSslConfig());
134 assertNull(config.getTaskProcessorConfig());
136 config.setAaiRestConfig(airc);
137 config.setAaiSslConfig(sslConfig);
138 config.setTaskProcessorConfig(tpc);
144 public void validateRepairSelfLink_nullLink() throws Exception {
146 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
148 ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
150 restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);
151 restConfig.setHost("aai-host");
152 restConfig.setPort("9191");
154 assertNull(config.repairSelfLink(null));
158 public void validateRepairSelfLink_emptyString() throws Exception {
160 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
162 ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
164 restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);
165 restConfig.setHost("aai-host");
166 restConfig.setPort("9191");
168 assertEquals("http://aai-host:9191", config.repairSelfLink(""));
172 public void validateRepairSelfLink_withResourceUrl() throws Exception {
174 ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
176 ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
178 restConfig.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);
179 restConfig.setHost("aai-host");
180 restConfig.setPort("9191");
182 assertEquals("https://aai-host:9191/aai/v10/business/customers/customer/1234",
183 config.repairSelfLink("/aai/v10/business/customers/customer/1234"));
187 public void validateResourcePathExtraction() throws Exception {
188 // https with API version
189 assertEquals("/aai/v10/business/customers/customer/1234", ActiveInventoryConfig
190 .extractResourcePath("https://aai-host:9191/aai/v10/business/customers/customer/1234"));
192 // https without API version
193 assertEquals("/business/customers/customer/1234", ActiveInventoryConfig
194 .extractResourcePath("https://aai-host:9191/business/customers/customer/1234"));
196 // http with API version
197 assertEquals("/aai/v10/business/customers/customer/1234", ActiveInventoryConfig
198 .extractResourcePath("http://aai-host:9191/aai/v10/business/customers/customer/1234"));
200 // http without API verison
201 assertEquals("/business/customers/customer/1234", ActiveInventoryConfig
202 .extractResourcePath("http://aai-host:9191/business/customers/customer/1234"));
204 // no scheme, host, or port
205 assertEquals("business/customers/customer/1234", ActiveInventoryConfig
206 .extractResourcePath("business/customers/customer/1234"));
208 // no scheme, host, or port with API version
209 assertEquals("/aai/v10/business/customers/customer/1234", ActiveInventoryConfig
210 .extractResourcePath("/aai/v10/business/customers/customer/1234"));
212 // no scheme, host, or port with API version
213 assertEquals("", ActiveInventoryConfig
214 .extractResourcePath(""));