2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
22 import static org.junit.Assert.assertEquals;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.doThrow;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
32 import java.nio.file.Files;
33 import java.nio.file.Paths;
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.List;
38 import java.util.Optional;
39 import java.util.UUID;
41 import org.camunda.bpm.engine.delegate.BpmnError;
42 import org.junit.Before;
43 import org.junit.Test;
44 import org.mockito.ArgumentMatchers;
45 import org.mockito.InjectMocks;
46 import org.onap.appc.client.lcm.model.Action;
47 import org.onap.so.bpmn.BaseTaskTest;
48 import org.onap.so.bpmn.common.BuildingBlockExecution;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
51 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
52 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
53 import org.onap.so.client.exception.BBObjectNotFoundException;
54 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
56 public class ConfigurationScaleOutTest extends BaseTaskTest {
59 private ConfigurationScaleOut configurationScaleOut = new ConfigurationScaleOut();
61 private GenericVnf genericVnf;
62 private VfModule vfModule;
63 private RequestContext requestContext;
64 private String msoRequestId;
65 private List<Map<String, String>> configurationParameters = new ArrayList<>();
66 private Map<String, String> configParamsMap = new HashMap<>();
71 public void before() throws BBObjectNotFoundException {
72 genericVnf = setGenericVnf();
73 vfModule = setVfModule();
74 msoRequestId = UUID.randomUUID().toString();
75 requestContext = setRequestContext();
76 requestContext.setMsoRequestId(msoRequestId);
77 configParamsMap.put("availability-zone", "$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]");
78 configParamsMap.put("vnf-id", "$.vnf-topology.vnf-topology-identifier-structure.vnf-id");
79 configurationParameters.add(configParamsMap);
80 requestContext.setConfigurationParameters(configurationParameters);
81 gBBInput.setRequestContext(requestContext);
83 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
84 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
85 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
90 public void setParamsForConfigurationScaleOutTest() throws Exception {
91 ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference();
92 controllerSelectionReference.setControllerName("testName");
93 controllerSelectionReference.setActionCategory("testAction");
94 controllerSelectionReference.setVnfType("testVnfType");
95 String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientGetResponse.json")));
96 String expectedPayload = "{\\\"request-parameters\\\":{\\\"vnf-host-ip-address\\\":\\\"10.222.22.2\\\","
97 + "\\\"vf-module-id\\\":\\\"testVfModuleId1\\\"},\\\"configuration-parameters\\\""
98 + ":{\\\"vnf-id\\\":\\\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\\\",\\\"availability-zone\\\":\\\"AZ-MN02\\\"}}";
99 execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncResponse);
101 doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.ConfigScaleOut.toString());
103 configurationScaleOut.setParamsForConfigurationScaleOut(execution);
105 assertEquals(genericVnf.getVnfId(), execution.getVariable("vnfId"));
106 assertEquals(genericVnf.getVnfName(), execution.getVariable("vnfName"));
107 assertEquals("ConfigScaleOut", execution.getVariable("action"));
108 assertEquals(requestContext.getMsoRequestId(), execution.getVariable("msoRequestId"));
109 assertEquals(controllerSelectionReference.getControllerName(), execution.getVariable("controllerType"));
110 assertEquals(vfModule.getVfModuleId(), execution.getVariable("vfModuleId"));
111 assertEquals(expectedPayload, execution.getVariable("payload"));
114 public void callAppcClientTest() throws Exception {
115 Action action = Action.ConfigScaleOut;
116 String vnfId = genericVnf.getVnfId();
117 String controllerType = "testType";
118 String payload = "{\\\"request-parameters\\\":{\\\"vnf-host-ip-address\\\":\\\"10.222.22.2\\\","
119 + "\\\"vf-module-id\\\":\\\"testVfModuleId1\\\"},\\\"configuration-parameters\\\""
120 + ":{\\\"vnf-id\\\":\\\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\\\",\\\"availability-zone\\\":\\\"AZ-MN02\\\"}}";
121 HashMap<String, String> payloadInfo = new HashMap<String, String>();
122 payloadInfo.put("vnfName", "testVnfName");
123 payloadInfo.put("vfModuleId", "testVfModuleId");
125 execution.setVariable("action", Action.ConfigScaleOut.toString());
126 execution.setVariable("msoRequestId", msoRequestId);
127 execution.setVariable("controllerType", controllerType);
128 execution.setVariable("vnfId", "testVnfId1");
129 execution.setVariable("vnfName", "testVnfName");
130 execution.setVariable("vfModuleId", "testVfModuleId");
131 execution.setVariable("payload", payload);
133 doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
135 configurationScaleOut.callAppcClient(execution);
136 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);