Adding back-end support for UI filters
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / dal / aai / config / ActiveInventoryConfigTest.java
1 package org.onap.aai.sparky.dal.aai.config;
2
3
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;
8
9 import java.io.File;
10 import java.util.Properties;
11
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;
20
21 public class ActiveInventoryConfigTest {
22
23   /**
24    * Test case initialization
25    * 
26    * @throws Exception the exception
27    */
28   @Before
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;
35   }
36
37   @Test
38   public void validateBasicConstruction_emptyProperties() throws Exception {
39
40     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
41
42     assertNotNull(config);
43
44   }
45
46   private Properties getTestProperties() {
47
48     Properties props = new Properties();
49
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");
57
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");
64
65     props.put("aai.rest.shallowEntities", "cloud-region,complex,vnf-image,image");
66
67     props.put("aai.ssl.truststore.filename", "synchronizer.jks");
68     props.put("aai.ssl.truststore.type", "jks");
69
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");
73
74     props.put("aai.ssl.enableDebug", "false");
75     props.put("aai.ssl.validateServerHostName", "false");
76     props.put("aai.ssl.validateServerCertificateChain", "false");
77
78     props.put("aai.rest.authenticationMode", "SSL_CERT");
79     props.put("aai.ssl.basicAuth.username", "");
80     props.put("aai.ssl.basicAuth.password", "");
81
82     props.put("aai.taskProcessor.maxConcurrentWorkers", "5");
83
84     props.put("aai.taskProcessor.transactionRateControllerEnabled", "false");
85     props.put("aai.taskProcessor.numSamplesPerThreadForRunningAverage", "100");
86     props.put("aai.taskProcessor.targetTPS", "100");
87
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");
92
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");
97
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");
102
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");
107
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");
112
113
114     return props;
115
116
117   }
118
119   @Test
120   public void validateAccessors() throws Exception {
121
122     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
123
124     ActiveInventoryRestConfig airc = config.getAaiRestConfig();
125     ActiveInventorySslConfig sslConfig = config.getAaiSslConfig();
126     TaskProcessorConfig tpc = config.getTaskProcessorConfig();
127
128     assertNotNull(airc);
129     assertNotNull(sslConfig);
130     assertNotNull(tpc);
131
132     assertEquals("https://aai-host:8443/aai/v10", config.getBaseUri().toString());
133
134     assertTrue(config.toString().contains("ActiveInventoryConfig"));
135
136     config.setAaiRestConfig(null);
137     config.setAaiSslConfig(null);
138     config.setTaskProcessorConfig(null);
139
140     assertNull(config.getAaiRestConfig());
141     assertNull(config.getAaiSslConfig());
142     assertNull(config.getTaskProcessorConfig());
143
144     config.setAaiRestConfig(airc);
145     config.setAaiSslConfig(sslConfig);
146     config.setTaskProcessorConfig(tpc);
147
148
149   }
150
151   @Test
152   public void validateRepairSelfLink_nullLink() throws Exception {
153
154     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
155
156     ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
157
158     restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);
159     restConfig.setHost("aai-host");
160     restConfig.setPort("9191");
161
162     assertNull(config.repairSelfLink(null));
163   }
164
165   @Test
166   public void validateRepairSelfLink_emptyString() throws Exception {
167
168     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
169
170     ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
171
172     restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);
173     restConfig.setHost("aai-host");
174     restConfig.setPort("9191");
175
176     assertEquals("http://aai-host:9191", config.repairSelfLink(""));
177   }
178
179   @Test
180   public void validateRepairSelfLink_withResourceUrl() throws Exception {
181
182     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
183
184     ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
185
186     restConfig.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);
187     restConfig.setHost("aai-host");
188     restConfig.setPort("9191");
189
190     assertEquals("https://aai-host:9191/aai/v10/business/customers/customer/1234",
191         config.repairSelfLink("/aai/v10/business/customers/customer/1234"));
192   }
193
194   @Test
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"));
199
200     // https without API version
201     assertEquals("/business/customers/customer/1234", ActiveInventoryConfig
202         .extractResourcePath("https://aai-host:9191/business/customers/customer/1234"));
203
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"));
207
208     // http without API verison
209     assertEquals("/business/customers/customer/1234", ActiveInventoryConfig
210         .extractResourcePath("http://aai-host:9191/business/customers/customer/1234"));
211
212     // no scheme, host, or port
213     assertEquals("business/customers/customer/1234",
214         ActiveInventoryConfig.extractResourcePath("business/customers/customer/1234"));
215
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"));
219
220     // no scheme, host, or port with API version
221     assertEquals("", ActiveInventoryConfig.extractResourcePath(""));
222   }
223 }