9f0bb910e67ce816d4435344096009385ead3a42
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / GenericVnfHealthCheckTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
21
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;
27
28 import java.util.HashMap;
29 import java.util.Optional;
30 import java.util.UUID;
31
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.appc.client.lcm.model.Action;
35 import org.onap.so.bpmn.BaseTaskTest;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
37 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
38 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
39 import org.springframework.beans.factory.annotation.Autowired;
40
41 public class GenericVnfHealthCheckTest extends BaseTaskTest {
42         
43         @Autowired
44         private GenericVnfHealthCheck genericVnfHealthCheck;
45         
46         private GenericVnf genericVnf;
47         private RequestContext requestContext;
48         private String msoRequestId;
49
50         @Before
51         public void before() {
52                 genericVnf = setGenericVnf();
53                 msoRequestId = UUID.randomUUID().toString();
54                 requestContext = setRequestContext();
55                 requestContext.setMsoRequestId(msoRequestId);
56                 gBBInput.setRequestContext(requestContext);
57         }
58         
59         @Test
60         public void setParamsForGenericVnfHealthCheckTest() throws Exception {
61                 ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference();
62                 controllerSelectionReference.setControllerName("testName");
63                 controllerSelectionReference.setActionCategory("testAction");
64                 controllerSelectionReference.setVnfType("testVnfType");
65                 
66                 doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.HealthCheck.toString());
67                 
68                 genericVnfHealthCheck.setParamsForGenericVnfHealthCheck(execution);
69                 
70                 assertEquals(genericVnf.getVnfId(), execution.getVariable("vnfId"));
71                 assertEquals(genericVnf.getVnfName(), execution.getVariable("vnfName"));
72                 assertEquals(genericVnf.getIpv4OamAddress(), execution.getVariable("oamIpAddress"));
73                 assertEquals("HealthCheck", execution.getVariable("action"));
74                 assertEquals(requestContext.getMsoRequestId(), execution.getVariable("msoRequestId"));
75                 assertEquals(controllerSelectionReference.getControllerName(), execution.getVariable("controllerType"));
76         }
77         @Test
78         public void callAppcClientTest() throws Exception {
79                 Action action = Action.HealthCheck;
80                 String vnfId = genericVnf.getVnfId();
81                 String payload = "{\"testName\":\"testValue\",}";
82                 String controllerType = "testType";
83                 HashMap<String, String> payloadInfo = new HashMap<String, String>();
84                 payloadInfo.put("vnfName", "testVnfName");
85                 payloadInfo.put("vfModuleId", "testVfModuleId");
86                 payloadInfo.put("oamIpAddress", "testOamIpAddress");
87                 payloadInfo.put("vnfHostIpAddress", "testOamIpAddress");
88                 execution.setVariable("action", Action.HealthCheck.toString());
89                 execution.setVariable("msoRequestId", msoRequestId);
90                 execution.setVariable("controllerType", controllerType);
91                 execution.setVariable("vnfId", "testVnfId1");
92                 execution.setVariable("vnfName", "testVnfName");
93                 execution.setVariable("vfModuleId", "testVfModuleId");
94                 execution.setVariable("oamIpAddress", "testOamIpAddress");
95                 execution.setVariable("vnfHostIpAddress", "testOamIpAddress");
96                 execution.setVariable("payload", payload);
97                 
98                 doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
99                 
100                 genericVnfHealthCheck.callAppcClient(execution);
101                 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
102         }
103 }