c46161f2c4990e9e9fc1aa3aa52a7fc4fdb1cb3c
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / viewandinspect / task / PerformNodeSelfLinkProcessingTaskTest.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 package org.onap.aai.sparky.viewandinspect.task;
27
28 import java.util.Properties;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.onap.aai.cl.mdc.MdcContext;
34 import org.onap.aai.sparky.dal.aai.ActiveInventoryDataProvider;
35 import org.onap.aai.sparky.dal.aai.config.ActiveInventoryConfig;
36 import org.onap.aai.sparky.util.NodeUtils;
37 import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode;
38 import org.onap.aai.sparky.viewandinspect.entity.NodeProcessingTransaction;
39 import org.onap.aai.sparky.viewandinspect.task.PerformNodeSelfLinkProcessingTask;
40
41
42 public class PerformNodeSelfLinkProcessingTaskTest {
43
44   private NodeProcessingTransaction mockTransaction;
45   private ActiveInventoryDataProvider mockAaiProvider;
46   private ActiveInventoryNode mockActiveInventoryNode;
47   private ActiveInventoryConfig aaiConfig;
48   PerformNodeSelfLinkProcessingTask testTask;
49
50   private Properties getTestProperties() {
51
52     Properties props = new Properties();
53
54     props.put("aai.rest.host", "aai-host");
55     props.put("aai.rest.port", "8443");
56     props.put("aai.rest.resourceBasePath", "/aai/v10");
57     props.put("aai.rest.connectTimeoutInMs", "30000");
58     props.put("aai.rest.readTimeoutInMs", "60000");
59     props.put("aai.rest.numRequestRetries", "5");
60     props.put("aai.rest.numResolverWorkers", "15");
61
62     props.put("aai.rest.cache.enabled", "false");
63     props.put("aai.rest.cache.numWorkers", "10");
64     props.put("aai.rest.cache.cacheFailures", "false");
65     props.put("aai.rest.cache.useCacheOnly", "false");
66     props.put("aai.rest.cache.storageFolderOverride", "");
67     props.put("aai.rest.cache.maxTimeToLiveInMs", "-1");
68
69     props.put("aai.rest.shallowEntities", "cloud-region,complex,vnf-image,att-aic,image");
70
71     props.put("aai.ssl.truststore.filename", "synchronizer.jks");
72     props.put("aai.ssl.truststore.type", "jks");
73
74     props.put("aai.ssl.keystore.filename", "aai-client-cert.p12");
75     props.put("aai.ssl.keystore.pass", "70c87528c88dcd9f9c2558d30e817868");
76     props.put("aai.ssl.keystore.type", "pkcs12");
77
78     props.put("aai.ssl.enableDebug", "false");
79     props.put("aai.ssl.validateServerHostName", "false");
80     props.put("aai.ssl.validateServerCertificateChain", "false");
81
82     props.put("aai.rest.authenticationMode", "SSL_CERT");
83     props.put("aai.ssl.basicAuth.username", "");
84     props.put("aai.ssl.basicAuth.password", "");
85
86     props.put("aai.taskProcessor.maxConcurrentWorkers", "5");
87
88     props.put("aai.taskProcessor.transactionRateControllerEnabled", "false");
89     props.put("aai.taskProcessor.numSamplesPerThreadForRunningAverage", "100");
90     props.put("aai.taskProcessor.targetTPS", "100");
91
92     props.put("aai.taskProcessor.bytesHistogramLabel", "[Response Size In Bytes]");
93     props.put("aai.taskProcessor.bytesHistogramMaxYAxis", "1000000");
94     props.put("aai.taskProcessor.bytesHistogramNumBins", "20");
95     props.put("aai.taskProcessor.bytesHistogramNumDecimalPoints", "2");
96
97     props.put("aai.taskProcessor.queueLengthHistogramLabel", "[Queue Item Length]");
98     props.put("aai.taskProcessor.queueLengthHistogramMaxYAxis", "20000");
99     props.put("aai.taskProcessor.queueLengthHistogramNumBins", "20");
100     props.put("aai.taskProcessor.queueLengthHistogramNumDecimalPoints", "2");
101
102     props.put("aai.taskProcessor.taskAgeHistogramLabel", "[Task Age In Ms]");
103     props.put("aai.taskProcessor.taskAgeHistogramMaxYAxis", "600000");
104     props.put("aai.taskProcessor.taskAgeHistogramNumBins", "20");
105     props.put("aai.taskProcessor.taskAgeHistogramNumDecimalPoints", "2");
106
107     props.put("aai.taskProcessor.responseTimeHistogramLabel", "[Response Time In Ms]");
108     props.put("aai.taskProcessor.responseTimeHistogramMaxYAxis", "10000");
109     props.put("aai.taskProcessor.responseTimeHistogramNumBins", "20");
110     props.put("aai.taskProcessor.responseTimeHistogramNumDecimalPoints", "2");
111
112     props.put("aai.taskProcessor.tpsHistogramLabel", "[Transactions Per Second]");
113     props.put("aai.taskProcessor.tpsHistogramMaxYAxis", "100");
114     props.put("aai.taskProcessor.tpsHistogramNumBins", "20");
115     props.put("aai.taskProcessor.tpsHistogramNumDecimalPoints", "2");
116
117
118     return props;
119
120   }
121
122   @Before
123   public void init() throws Exception {
124
125     mockTransaction = Mockito.mock(NodeProcessingTransaction.class);
126     mockAaiProvider = Mockito.mock(ActiveInventoryDataProvider.class);
127     mockActiveInventoryNode = Mockito.mock(ActiveInventoryNode.class);
128
129     String txnID = NodeUtils.getRandomTxnId();
130     String partnerName = "Browser";
131
132     MdcContext.initialize(txnID, "AAI-UI", "", partnerName, "localhost");
133
134     aaiConfig = new ActiveInventoryConfig(getTestProperties());
135
136   }
137
138
139   @Test
140   public void validateDefaultConstructor() {
141
142     /*
143      * ArgumentCaptor<String> linkCaptor = ArgumentCaptor.forClass(String.class);
144      * 
145      * Mockito.when( mockActiveInventoryNode.getEntityType()).thenReturn("logical-link");
146      * Mockito.when( mockTransaction.getProcessingNode() ).thenReturn(mockActiveInventoryNode);
147      * Mockito.when( mockTransaction.getRequestParameters()).thenReturn("?p1=v1&p2=v2&p3=v3");
148      * Mockito.when( mockTransaction.getSelfLink()).thenReturn(
149      * "/aai/v10/network/logical-links/logical-link/alrga392ve2%20-%20xe-%2010%2F3%2F2.270%7Car4ga01pbg"
150      * );
151      * 
152      * String requestParameters = "";
153      * 
154      * // test method testTask.get();
155      * 
156      * assertEquals(
157      * "https://aai-host:8443/aai/v10/network/logical-links/logical-link/alrga392ve2%20-%20xe-%2010%2F3%2F2.270%7Car4ga01pbg?p1=v1&p2=v2&p3=v3",
158      * linkCaptor.getValue());
159      */
160
161   }
162
163   @Test
164   public void validateLinkEncoding_withoutParameters() {
165
166     /*
167      * ArgumentCaptor<String> linkCaptor = ArgumentCaptor.forClass(String.class);
168      * 
169      * Mockito.when( mockActiveInventoryNode.getEntityType()).thenReturn("logical-link");
170      * Mockito.when( mockTransaction.getProcessingNode() ).thenReturn(mockActiveInventoryNode);
171      * Mockito.when( mockTransaction.getSelfLink()).thenReturn(
172      * "/aai/v10/network/logical-links/logical-link/alrga392ve2%20-%20xe-%2010%2F3%2F2.270%7Car4ga01pbg"
173      * );
174      * 
175      * String requestParameters = "";
176      * 
177      * // test method testTask.get();
178      * 
179      * assertEquals(
180      * "https://aai-host:8443/aai/v10/network/logical-links/logical-link/alrga392ve2%20-%20xe-%2010%2F3%2F2.270%7Car4ga01pbg",
181      * linkCaptor.getValue());
182      */
183
184   }
185
186   @Test
187   public void validateLinkEncoding_nullLink() {
188
189     /*
190      * ArgumentCaptor<OperationResult> opResultCaptor =
191      * ArgumentCaptor.forClass(OperationResult.class);
192      * 
193      * Mockito.when( mockActiveInventoryNode.getEntityType()).thenReturn("logical-link");
194      * Mockito.when( mockTransaction.getProcessingNode() ).thenReturn(mockActiveInventoryNode);
195      * Mockito.when( mockTransaction.getSelfLink()).thenReturn(null);
196      * 
197      * String requestParameters = "";
198      * 
199      * // test method testTask.get();
200      * 
201      * Mockito.verify(mockTransaction, Mockito.atLeast(1)).setOpResult(opResultCaptor.capture());
202      * 
203      * assertNotNull(opResultCaptor.getValue()); assertEquals(500,
204      * opResultCaptor.getValue().getResultCode());
205      */
206
207   }
208
209   @Test
210   public void validateLinkEncoding_withoutParameters_and_providerSuccess() {
211
212     /*
213      * ArgumentCaptor<String> linkCaptor = ArgumentCaptor.forClass(String.class);
214      * 
215      * Mockito.when( mockActiveInventoryNode.getEntityType()).thenReturn("logical-link");
216      * Mockito.when( mockTransaction.getProcessingNode() ).thenReturn(mockActiveInventoryNode);
217      * Mockito.when( mockTransaction.getSelfLink()).thenReturn(
218      * "/aai/v10/network/logical-links/logical-link/alrga392ve2%20-%20xe-%2010%2F3%2F2.270%7Car4ga01pbg"
219      * ); Mockito.when( mockAaiProvider.queryActiveInventoryWithRetries(anyString(), anyString(),
220      * anyInt())).thenReturn(new OperationResult(200,"OK"));
221      * 
222      * String requestParameters = "";
223      * 
224      * // test method testTask.get();
225      * 
226      * assertEquals(
227      * "https://aai-host:8443/aai/v10/network/logical-links/logical-link/alrga392ve2%20-%20xe-%2010%2F3%2F2.270%7Car4ga01pbg",
228      * linkCaptor.getValue());
229      */
230   }
231
232 }