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.Mockito.doNothing;
24 import static org.mockito.Mockito.doReturn;
25 import static org.mockito.Mockito.times;
26 import static org.mockito.Mockito.verify;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
34 import java.util.Optional;
35 import java.util.UUID;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.onap.appc.client.lcm.model.Action;
40 import org.onap.so.bpmn.BaseTaskTest;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
43 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
44 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
45 import org.springframework.beans.factory.annotation.Autowired;
47 public class ConfigurationScaleOutTest extends BaseTaskTest {
50 private ConfigurationScaleOut configurationScaleOut;
52 private GenericVnf genericVnf;
53 private VfModule vfModule;
54 private RequestContext requestContext;
55 private String msoRequestId;
56 private List<Map<String, String>> configurationParameters = new ArrayList<>();
57 private Map<String, String> configParamsMap = new HashMap<>();
62 public void before() {
63 genericVnf = setGenericVnf();
64 vfModule = setVfModule();
65 msoRequestId = UUID.randomUUID().toString();
66 requestContext = setRequestContext();
67 requestContext.setMsoRequestId(msoRequestId);
68 configParamsMap.put("availability-zone", "$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]");
69 configParamsMap.put("vnf-id", "$.vnf-topology.vnf-topology-identifier-structure.vnf-id");
70 configurationParameters.add(configParamsMap);
71 requestContext.setConfigurationParameters(configurationParameters);
72 gBBInput.setRequestContext(requestContext);
76 public void setParamsForConfigurationScaleOutTest() throws Exception {
77 ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference();
78 controllerSelectionReference.setControllerName("testName");
79 controllerSelectionReference.setActionCategory("testAction");
80 controllerSelectionReference.setVnfType("testVnfType");
81 String sdncResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientGetResponse.json")));
82 String expectedPayload = "{\\\"request-parameters\\\":{\\\"vnf-host-ip-address\\\":\\\"10.222.22.2\\\","
83 + "\\\"vf-module-id\\\":\\\"testVfModuleId1\\\"},\\\"configuration-parameters\\\""
84 + ":{\\\"vnf-id\\\":\\\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\\\",\\\"availability-zone\\\":\\\"AZ-MN02\\\"}}";
85 execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncResponse);
87 doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.ConfigScaleOut.toString());
89 configurationScaleOut.setParamsForConfigurationScaleOut(execution);
91 assertEquals(genericVnf.getVnfId(), execution.getVariable("vnfId"));
92 assertEquals(genericVnf.getVnfName(), execution.getVariable("vnfName"));
93 assertEquals("ConfigScaleOut", execution.getVariable("action"));
94 assertEquals(requestContext.getMsoRequestId(), execution.getVariable("msoRequestId"));
95 assertEquals(controllerSelectionReference.getControllerName(), execution.getVariable("controllerType"));
96 assertEquals(vfModule.getVfModuleId(), execution.getVariable("vfModuleId"));
97 assertEquals(expectedPayload, execution.getVariable("payload"));
100 public void callAppcClientTest() throws Exception {
101 Action action = Action.ConfigScaleOut;
102 String vnfId = genericVnf.getVnfId();
103 String controllerType = "testType";
104 String payload = "{\\\"request-parameters\\\":{\\\"vnf-host-ip-address\\\":\\\"10.222.22.2\\\","
105 + "\\\"vf-module-id\\\":\\\"testVfModuleId1\\\"},\\\"configuration-parameters\\\""
106 + ":{\\\"vnf-id\\\":\\\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\\\",\\\"availability-zone\\\":\\\"AZ-MN02\\\"}}";
107 HashMap<String, String> payloadInfo = new HashMap<String, String>();
108 payloadInfo.put("vnfName", "testVnfName");
109 payloadInfo.put("vfModuleId", "testVfModuleId");
111 execution.setVariable("action", Action.ConfigScaleOut.toString());
112 execution.setVariable("msoRequestId", msoRequestId);
113 execution.setVariable("controllerType", controllerType);
114 execution.setVariable("vnfId", "testVnfId1");
115 execution.setVariable("vnfName", "testVnfName");
116 execution.setVariable("vfModuleId", "testVfModuleId");
117 execution.setVariable("payload", payload);
119 doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
121 configurationScaleOut.callAppcClient(execution);
122 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);