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.util.HashMap;
33 import java.util.Optional;
34 import java.util.UUID;
36 import org.camunda.bpm.engine.delegate.BpmnError;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.mockito.ArgumentMatchers;
40 import org.mockito.InjectMocks;
41 import org.onap.appc.client.lcm.model.Action;
42 import org.onap.so.bpmn.BaseTaskTest;
43 import org.onap.so.bpmn.common.BuildingBlockExecution;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
45 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
46 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
47 import org.onap.so.client.exception.BBObjectNotFoundException;
48 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
50 public class GenericVnfHealthCheckTest extends BaseTaskTest {
53 private GenericVnfHealthCheck genericVnfHealthCheck = new GenericVnfHealthCheck();
55 private GenericVnf genericVnf;
56 private RequestContext requestContext;
57 private String msoRequestId;
60 public void before() throws BBObjectNotFoundException {
61 genericVnf = setGenericVnf();
62 msoRequestId = UUID.randomUUID().toString();
63 requestContext = setRequestContext();
64 requestContext.setMsoRequestId(msoRequestId);
65 gBBInput.setRequestContext(requestContext);
67 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
68 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
72 public void setParamsForGenericVnfHealthCheckTest() throws Exception {
73 ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference();
74 controllerSelectionReference.setControllerName("testName");
75 controllerSelectionReference.setActionCategory("testAction");
76 controllerSelectionReference.setVnfType("testVnfType");
78 doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.HealthCheck.toString());
80 genericVnfHealthCheck.setParamsForGenericVnfHealthCheck(execution);
82 assertEquals(genericVnf.getVnfId(), execution.getVariable("vnfId"));
83 assertEquals(genericVnf.getVnfName(), execution.getVariable("vnfName"));
84 assertEquals(genericVnf.getIpv4OamAddress(), execution.getVariable("oamIpAddress"));
85 assertEquals("HealthCheck", execution.getVariable("action"));
86 assertEquals(requestContext.getMsoRequestId(), execution.getVariable("msoRequestId"));
87 assertEquals(controllerSelectionReference.getControllerName(), execution.getVariable("controllerType"));
90 public void callAppcClientTest() throws Exception {
91 Action action = Action.HealthCheck;
92 String vnfId = genericVnf.getVnfId();
93 String payload = "{\"testName\":\"testValue\",}";
94 String controllerType = "testType";
95 HashMap<String, String> payloadInfo = new HashMap<String, String>();
96 payloadInfo.put("vnfName", "testVnfName");
97 payloadInfo.put("vfModuleId", "testVfModuleId");
98 payloadInfo.put("oamIpAddress", "testOamIpAddress");
99 payloadInfo.put("vnfHostIpAddress", "testOamIpAddress");
100 execution.setVariable("action", Action.HealthCheck.toString());
101 execution.setVariable("msoRequestId", msoRequestId);
102 execution.setVariable("controllerType", controllerType);
103 execution.setVariable("vnfId", "testVnfId1");
104 execution.setVariable("vnfName", "testVnfName");
105 execution.setVariable("vfModuleId", "testVfModuleId");
106 execution.setVariable("oamIpAddress", "testOamIpAddress");
107 execution.setVariable("vnfHostIpAddress", "testOamIpAddress");
108 execution.setVariable("payload", payload);
110 doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
112 genericVnfHealthCheck.callAppcClient(execution);
113 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
117 public void callAppcClientExceptionTest() throws Exception {
118 expectedException.expect(BpmnError.class);
119 Action action = Action.HealthCheck;
120 String vnfId = genericVnf.getVnfId();
121 String payload = "{\"testName\":\"testValue\",}";
122 String controllerType = "testType";
123 HashMap<String, String> payloadInfo = new HashMap<String, String>();
124 payloadInfo.put("vnfName", "testVnfName");
125 payloadInfo.put("vfModuleId", "testVfModuleId");
126 payloadInfo.put("oamIpAddress", "testOamIpAddress");
127 payloadInfo.put("vnfHostIpAddress", "testOamIpAddress");
128 execution.setVariable("action", Action.HealthCheck.toString());
129 execution.setVariable("msoRequestId", msoRequestId);
130 execution.setVariable("controllerType", controllerType);
131 execution.setVariable("vnfId", "testVnfId1");
132 execution.setVariable("vnfName", "testVnfName");
133 execution.setVariable("vfModuleId", "testVfModuleId");
134 execution.setVariable("oamIpAddress", "testOamIpAddress");
135 execution.setVariable("vnfHostIpAddress", "testOamIpAddress");
136 execution.setVariable("payload", payload);
138 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1002), eq("APPC Client Failed"));
139 doThrow(new RuntimeException("APPC Client Failed")).when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
142 genericVnfHealthCheck.callAppcClient(execution);
143 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);