2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2019  Tech Mahindra
 
   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=========================================================
 
  21 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
 
  24 import static org.junit.Assert.assertEquals;
 
  25 import static org.mockito.ArgumentMatchers.any;
 
  26 import static org.mockito.ArgumentMatchers.eq;
 
  27 import static org.mockito.Mockito.doReturn;
 
  28 import static org.mockito.Mockito.doThrow;
 
  29 import static org.mockito.Mockito.when;
 
  30 import java.util.UUID;
 
  31 import org.camunda.bpm.engine.delegate.BpmnError;
 
  32 import org.junit.Before;
 
  33 import org.junit.Test;
 
  34 import org.mockito.ArgumentMatchers;
 
  35 import org.mockito.InjectMocks;
 
  36 import org.onap.so.bpmn.BaseTaskTest;
 
  37 import org.onap.so.bpmn.common.BuildingBlockExecution;
 
  38 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
 
  39 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
 
  40 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
 
  41 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
 
  42 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
 
  43 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
 
  44 import org.onap.so.client.exception.BBObjectNotFoundException;
 
  45 import org.onap.so.db.catalog.beans.BBNameSelectionReference;
 
  46 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
 
  49 public class ControllerExecutionTest extends BaseTaskTest {
 
  52     private ControllerExecution controllerExecution = new ControllerExecution();
 
  54     private static final String TEST_SCOPE = "vfModule";
 
  55     private static final String TEST_BBNAME = "ConfigurationScaleOut";
 
  56     private static final String TEST_ACTION = "configScaleOut";
 
  57     private static final String TEST_CONTROLLER_ACTOR = "APPC";
 
  59     private BuildingBlock buildingBlock = new BuildingBlock();
 
  60     VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
 
  61     private ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
 
  62     private GenericVnf genericVnf;
 
  63     private ServiceInstance serviceInstance;
 
  64     private RequestContext requestContext;
 
  65     private String msoRequestId;
 
  69     public void before() throws BBObjectNotFoundException {
 
  71         genericVnf = setGenericVnf();
 
  72         serviceInstance = setServiceInstance();
 
  73         msoRequestId = UUID.randomUUID().toString();
 
  74         requestContext = setRequestContext();
 
  75         requestContext.setMsoRequestId(msoRequestId);
 
  76         gBBInput.setRequestContext(requestContext);
 
  77         buildingBlock.setBpmnAction(TEST_ACTION);
 
  78         buildingBlock.setBpmnScope(TEST_SCOPE);
 
  79         executeBuildingBlock.setBuildingBlock(buildingBlock);
 
  80         execution.setVariable("buildingBlock", executeBuildingBlock);
 
  82         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
 
  83                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
 
  85         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
 
  86                 .thenReturn(genericVnf);
 
  87         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
 
  88                 .thenReturn(serviceInstance);
 
  94     public void testSetControllerActorScopeAction() throws Exception {
 
  97         doReturn(vnfResourceCustomization).when(catalogDbClient).getVnfResourceCustomizationByModelCustomizationUUID(
 
  98                 genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid());
 
  99         controllerExecution.setControllerActorScopeAction(execution);
 
 100         assertEquals(TEST_SCOPE, execution.getVariable("scope"));
 
 101         assertEquals(TEST_ACTION, execution.getVariable("action"));
 
 102         assertEquals(TEST_CONTROLLER_ACTOR, execution.getVariable("controllerActor"));
 
 108     public void testSelectBB() throws Exception {
 
 110         BBNameSelectionReference bbNameSelectionReference = new BBNameSelectionReference();
 
 111         bbNameSelectionReference.setBbName(TEST_BBNAME);
 
 112         bbNameSelectionReference.setAction(TEST_ACTION);
 
 113         bbNameSelectionReference.setControllerActor(TEST_CONTROLLER_ACTOR);
 
 114         bbNameSelectionReference.setScope(TEST_SCOPE);
 
 115         doReturn(bbNameSelectionReference).when(catalogDbClient).getBBNameSelectionReference(TEST_CONTROLLER_ACTOR,
 
 116                 TEST_SCOPE, TEST_ACTION);
 
 117         execution.setVariable("controllerActor", TEST_CONTROLLER_ACTOR);
 
 118         execution.setVariable("scope", TEST_SCOPE);
 
 119         execution.setVariable("action", TEST_ACTION);
 
 122         controllerExecution.selectBB(execution);
 
 124         assertEquals(TEST_BBNAME, execution.getVariable("bbName"));