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.Ignore;
39 import org.junit.Test;
40 import org.mockito.ArgumentMatchers;
41 import org.mockito.InjectMocks;
42 import org.onap.appc.client.lcm.model.Action;
43 import org.onap.so.bpmn.BaseTaskTest;
44 import org.onap.so.bpmn.common.BuildingBlockExecution;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
46 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
47 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
48 import org.onap.so.client.exception.BBObjectNotFoundException;
49 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
51 public class GenericVnfHealthCheckTest extends BaseTaskTest {
54 private GenericVnfHealthCheck genericVnfHealthCheck = new GenericVnfHealthCheck();
56 private GenericVnf genericVnf;
57 private RequestContext requestContext;
58 private String msoRequestId;
61 public void before() throws BBObjectNotFoundException {
62 genericVnf = setGenericVnf();
63 msoRequestId = UUID.randomUUID().toString();
64 requestContext = setRequestContext();
65 requestContext.setMsoRequestId(msoRequestId);
66 gBBInput.setRequestContext(requestContext);
68 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
69 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
73 public void setParamsForGenericVnfHealthCheckTest() throws Exception {
74 ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference();
75 controllerSelectionReference.setControllerName("testName");
76 controllerSelectionReference.setActionCategory("testAction");
77 controllerSelectionReference.setVnfType("testVnfType");
79 doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.HealthCheck.toString());
81 genericVnfHealthCheck.setParamsForGenericVnfHealthCheck(execution);
83 assertEquals(genericVnf.getVnfId(), execution.getVariable("vnfId"));
84 assertEquals(genericVnf.getVnfName(), execution.getVariable("vnfName"));
85 assertEquals(genericVnf.getIpv4OamAddress(), execution.getVariable("oamIpAddress"));
86 assertEquals("HealthCheck", execution.getVariable("action"));
87 assertEquals(requestContext.getMsoRequestId(), execution.getVariable("msoRequestId"));
88 assertEquals(controllerSelectionReference.getControllerName(), execution.getVariable("controllerType"));
91 public void callAppcClientTest() throws Exception {
92 Action action = Action.HealthCheck;
93 String vnfId = genericVnf.getVnfId();
94 String payload = "{\"testName\":\"testValue\",}";
95 String controllerType = "testType";
96 HashMap<String, String> payloadInfo = new HashMap<String, String>();
97 payloadInfo.put("vnfName", "testVnfName");
98 payloadInfo.put("vfModuleId", "testVfModuleId");
99 payloadInfo.put("oamIpAddress", "testOamIpAddress");
100 payloadInfo.put("vnfHostIpAddress", "testOamIpAddress");
101 execution.setVariable("action", Action.HealthCheck.toString());
102 execution.setVariable("msoRequestId", msoRequestId);
103 execution.setVariable("controllerType", controllerType);
104 execution.setVariable("vnfId", "testVnfId1");
105 execution.setVariable("vnfName", "testVnfName");
106 execution.setVariable("vfModuleId", "testVfModuleId");
107 execution.setVariable("oamIpAddress", "testOamIpAddress");
108 execution.setVariable("vnfHostIpAddress", "testOamIpAddress");
109 execution.setVariable("payload", payload);
111 doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
113 genericVnfHealthCheck.callAppcClient(execution);
114 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
118 public void callAppcClientExceptionTest() throws Exception {
119 expectedException.expect(BpmnError.class);
120 Action action = Action.HealthCheck;
121 String vnfId = genericVnf.getVnfId();
122 String payload = "{\"testName\":\"testValue\",}";
123 String controllerType = "testType";
124 HashMap<String, String> payloadInfo = new HashMap<String, String>();
125 payloadInfo.put("vnfName", "testVnfName");
126 payloadInfo.put("vfModuleId", "testVfModuleId");
127 payloadInfo.put("oamIpAddress", "testOamIpAddress");
128 payloadInfo.put("vnfHostIpAddress", "testOamIpAddress");
129 execution.setVariable("action", Action.HealthCheck.toString());
130 execution.setVariable("msoRequestId", msoRequestId);
131 execution.setVariable("controllerType", controllerType);
132 execution.setVariable("vnfId", "testVnfId1");
133 execution.setVariable("vnfName", "testVnfName");
134 execution.setVariable("vfModuleId", "testVfModuleId");
135 execution.setVariable("oamIpAddress", "testOamIpAddress");
136 execution.setVariable("vnfHostIpAddress", "testOamIpAddress");
137 execution.setVariable("payload", payload);
139 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1002), eq("APPC Client Failed"));
140 doThrow(new RuntimeException("APPC Client Failed")).when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
143 genericVnfHealthCheck.callAppcClient(execution);
144 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
148 @Ignore //The runAppCCommand method in not capable of throwing this exception
149 public void callAppcClientTimeOutExceptionTest() {
150 expectedException.expect(java.util.concurrent.TimeoutException.class);
151 Action action = Action.HealthCheck;
152 String vnfId = genericVnf.getVnfId();
153 String payload = "{\"testName\":\"testValue\",}";
154 String controllerType = "testType";
155 HashMap<String, String> payloadInfo = new HashMap<String, String>();
156 payloadInfo.put("vnfName", "testVnfName");
157 payloadInfo.put("vfModuleId", "testVfModuleId");
158 payloadInfo.put("oamIpAddress", "testOamIpAddress");
159 payloadInfo.put("vnfHostIpAddress", "testOamIpAddress");
160 execution.setVariable("action", Action.HealthCheck.toString());
161 execution.setVariable("msoRequestId", msoRequestId);
162 execution.setVariable("controllerType", controllerType);
163 execution.setVariable("vnfId", "testVnfId1");
164 execution.setVariable("vnfName", "testVnfName");
165 execution.setVariable("vfModuleId", "testVfModuleId");
166 execution.setVariable("oamIpAddress", "testOamIpAddress");
167 execution.setVariable("vnfHostIpAddress", "testOamIpAddress");
168 execution.setVariable("payload", payload);
170 doThrow(java.util.concurrent.TimeoutException.class).when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
173 genericVnfHealthCheck.callAppcClient(execution);
174 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);