2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.onap.aai.sparky.viewandinspect.task;
28 import java.util.Properties;
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;
42 public class PerformNodeSelfLinkProcessingTaskTest {
44 private NodeProcessingTransaction mockTransaction;
45 private ActiveInventoryDataProvider mockAaiProvider;
46 private ActiveInventoryNode mockActiveInventoryNode;
47 private ActiveInventoryConfig aaiConfig;
48 PerformNodeSelfLinkProcessingTask testTask;
50 private Properties getTestProperties() {
52 Properties props = new Properties();
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");
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");
69 props.put("aai.rest.shallowEntities", "cloud-region,complex,vnf-image,att-aic,image");
71 props.put("aai.ssl.truststore.filename", "synchronizer.jks");
72 props.put("aai.ssl.truststore.type", "jks");
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");
78 props.put("aai.ssl.enableDebug", "false");
79 props.put("aai.ssl.validateServerHostName", "false");
80 props.put("aai.ssl.validateServerCertificateChain", "false");
82 props.put("aai.rest.authenticationMode", "SSL_CERT");
83 props.put("aai.ssl.basicAuth.username", "");
84 props.put("aai.ssl.basicAuth.password", "");
86 props.put("aai.taskProcessor.maxConcurrentWorkers", "5");
88 props.put("aai.taskProcessor.transactionRateControllerEnabled", "false");
89 props.put("aai.taskProcessor.numSamplesPerThreadForRunningAverage", "100");
90 props.put("aai.taskProcessor.targetTPS", "100");
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");
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");
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");
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");
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");
123 public void init() throws Exception {
125 mockTransaction = Mockito.mock(NodeProcessingTransaction.class);
126 mockAaiProvider = Mockito.mock(ActiveInventoryDataProvider.class);
127 mockActiveInventoryNode = Mockito.mock(ActiveInventoryNode.class);
129 String txnID = NodeUtils.getRandomTxnId();
130 String partnerName = "Browser";
132 MdcContext.initialize(txnID, "AAI-UI", "", partnerName, "localhost");
134 aaiConfig = new ActiveInventoryConfig(getTestProperties());
140 public void validateDefaultConstructor() {
143 * ArgumentCaptor<String> linkCaptor = ArgumentCaptor.forClass(String.class);
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"
152 * String requestParameters = "";
154 * // test method testTask.get();
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());
164 public void validateLinkEncoding_withoutParameters() {
167 * ArgumentCaptor<String> linkCaptor = ArgumentCaptor.forClass(String.class);
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"
175 * String requestParameters = "";
177 * // test method testTask.get();
180 * "https://aai-host:8443/aai/v10/network/logical-links/logical-link/alrga392ve2%20-%20xe-%2010%2F3%2F2.270%7Car4ga01pbg",
181 * linkCaptor.getValue());
187 public void validateLinkEncoding_nullLink() {
190 * ArgumentCaptor<OperationResult> opResultCaptor =
191 * ArgumentCaptor.forClass(OperationResult.class);
193 * Mockito.when( mockActiveInventoryNode.getEntityType()).thenReturn("logical-link");
194 * Mockito.when( mockTransaction.getProcessingNode() ).thenReturn(mockActiveInventoryNode);
195 * Mockito.when( mockTransaction.getSelfLink()).thenReturn(null);
197 * String requestParameters = "";
199 * // test method testTask.get();
201 * Mockito.verify(mockTransaction, Mockito.atLeast(1)).setOpResult(opResultCaptor.capture());
203 * assertNotNull(opResultCaptor.getValue()); assertEquals(500,
204 * opResultCaptor.getValue().getResultCode());
210 public void validateLinkEncoding_withoutParameters_and_providerSuccess() {
213 * ArgumentCaptor<String> linkCaptor = ArgumentCaptor.forClass(String.class);
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"));
222 * String requestParameters = "";
224 * // test method testTask.get();
227 * "https://aai-host:8443/aai/v10/network/logical-links/logical-link/alrga392ve2%20-%20xe-%2010%2F3%2F2.270%7Car4ga01pbg",
228 * linkCaptor.getValue());