Renaming openecomp to onap
[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.util.Properties;
10
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;
18
19 public class ActiveInventoryConfigTest {
20
21   /**
22    * Test case initialization
23    * 
24    * @throws Exception the exception
25    */
26   @Before
27   public void init() throws Exception {}
28
29   @Test
30   public void validateBasicConstruction_emptyProperties() throws Exception {
31
32     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
33
34     assertNotNull(config);
35
36   }
37   
38   private Properties getTestProperties() {
39     
40     Properties props = new Properties();
41     
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");
49     
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");
56     
57     props.put("aai.rest.shallowEntities","cloud-region,complex,vnf-image,image");
58     
59     props.put("aai.ssl.truststore.filename","synchronizer.jks");
60     props.put("aai.ssl.truststore.type","jks");
61     
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");
65     
66     props.put("aai.ssl.enableDebug","false");
67     props.put("aai.ssl.validateServerHostName","false");
68     props.put("aai.ssl.validateServerCertificateChain","false");
69
70     props.put("aai.rest.authenticationMode","SSL_CERT");
71     props.put("aai.ssl.basicAuth.username","");
72     props.put("aai.ssl.basicAuth.password","");
73     
74     props.put("aai.taskProcessor.maxConcurrentWorkers","5");
75     
76     props.put("aai.taskProcessor.transactionRateControllerEnabled","false");
77     props.put("aai.taskProcessor.numSamplesPerThreadForRunningAverage","100");
78     props.put("aai.taskProcessor.targetTPS","100");
79     
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");
84     
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");
89     
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");
94     
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");
99     
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");
104     
105     
106     return props;
107     
108     
109   }
110
111   @Test
112   public void validateAccessors() throws Exception {
113     
114     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
115
116     ActiveInventoryRestConfig airc = config.getAaiRestConfig();
117     ActiveInventorySslConfig sslConfig = config.getAaiSslConfig();
118     TaskProcessorConfig tpc = config.getTaskProcessorConfig();
119
120     assertNotNull(airc);
121     assertNotNull(sslConfig);
122     assertNotNull(tpc);
123
124     assertEquals("https://aai-host:8443/aai/v10", config.getBaseUri().toString());
125
126     assertTrue(config.toString().contains("ActiveInventoryConfig"));
127
128     config.setAaiRestConfig(null);
129     config.setAaiSslConfig(null);
130     config.setTaskProcessorConfig(null);
131
132     assertNull(config.getAaiRestConfig());
133     assertNull(config.getAaiSslConfig());
134     assertNull(config.getTaskProcessorConfig());
135
136     config.setAaiRestConfig(airc);
137     config.setAaiSslConfig(sslConfig);
138     config.setTaskProcessorConfig(tpc);
139
140
141   }
142
143   @Test
144   public void validateRepairSelfLink_nullLink() throws Exception {
145
146     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
147
148     ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
149
150     restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);
151     restConfig.setHost("aai-host");
152     restConfig.setPort("9191");
153
154     assertNull(config.repairSelfLink(null));
155   }
156
157   @Test
158   public void validateRepairSelfLink_emptyString() throws Exception {
159
160     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
161
162     ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
163
164     restConfig.setAuthenticationMode(RestAuthenticationMode.UNKNOWN_MODE);
165     restConfig.setHost("aai-host");
166     restConfig.setPort("9191");
167
168     assertEquals("http://aai-host:9191", config.repairSelfLink(""));
169   }
170
171   @Test
172   public void validateRepairSelfLink_withResourceUrl() throws Exception {
173
174     ActiveInventoryConfig config = new ActiveInventoryConfig(getTestProperties());
175
176     ActiveInventoryRestConfig restConfig = config.getAaiRestConfig();
177
178     restConfig.setAuthenticationMode(RestAuthenticationMode.SSL_CERT);
179     restConfig.setHost("aai-host");
180     restConfig.setPort("9191");
181
182     assertEquals("https://aai-host:9191/aai/v10/business/customers/customer/1234",
183         config.repairSelfLink("/aai/v10/business/customers/customer/1234"));
184   }
185   
186   @Test
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"));
191
192     // https without API version
193     assertEquals("/business/customers/customer/1234", ActiveInventoryConfig
194         .extractResourcePath("https://aai-host:9191/business/customers/customer/1234"));
195
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"));
199
200     // http without API verison
201     assertEquals("/business/customers/customer/1234", ActiveInventoryConfig
202         .extractResourcePath("http://aai-host:9191/business/customers/customer/1234"));
203
204     // no scheme, host, or port
205     assertEquals("business/customers/customer/1234", ActiveInventoryConfig
206         .extractResourcePath("business/customers/customer/1234"));
207
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"));
211
212     // no scheme, host, or port with API version
213     assertEquals("", ActiveInventoryConfig
214         .extractResourcePath(""));
215   }
216 }