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.util.HashMap;
 
  29 import java.util.Optional;
 
  30 import java.util.UUID;
 
  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;
 
  41 public class GenericVnfHealthCheckTest extends BaseTaskTest {
 
  44         private GenericVnfHealthCheck genericVnfHealthCheck;
 
  46         private GenericVnf genericVnf;
 
  47         private RequestContext requestContext;
 
  48         private String msoRequestId;
 
  51         public void before() {
 
  52                 genericVnf = setGenericVnf();
 
  53                 msoRequestId = UUID.randomUUID().toString();
 
  54                 requestContext = setRequestContext();
 
  55                 requestContext.setMsoRequestId(msoRequestId);
 
  56                 gBBInput.setRequestContext(requestContext);
 
  60         public void setParamsForGenericVnfHealthCheckTest() throws Exception {
 
  61                 ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference();
 
  62                 controllerSelectionReference.setControllerName("testName");
 
  63                 controllerSelectionReference.setActionCategory("testAction");
 
  64                 controllerSelectionReference.setVnfType("testVnfType");
 
  66                 doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.HealthCheck.toString());
 
  68                 genericVnfHealthCheck.setParamsForGenericVnfHealthCheck(execution);
 
  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"));
 
  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);
 
  98                 doNothing().when(appCClient).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
 
 100                 genericVnfHealthCheck.callAppcClient(execution);
 
 101                 verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);