2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 - 2019 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=========================================================
 
  21 package org.onap.so.bpmn.infrastructure.workflow.tasks.listeners;
 
  23 import static org.junit.Assert.assertEquals;
 
  24 import static org.junit.Assert.assertFalse;
 
  25 import static org.junit.Assert.assertTrue;
 
  26 import static org.mockito.ArgumentMatchers.eq;
 
  27 import static org.mockito.Mockito.when;
 
  28 import java.util.ArrayList;
 
  29 import java.util.List;
 
  30 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
 
  31 import org.junit.Test;
 
  32 import org.junit.runner.RunWith;
 
  33 import org.mockito.InjectMocks;
 
  34 import org.mockito.Mock;
 
  35 import org.mockito.junit.MockitoJUnitRunner;
 
  36 import org.onap.so.bpmn.common.BBConstants;
 
  37 import org.onap.so.bpmn.common.BuildingBlockExecution;
 
  38 import org.onap.so.bpmn.common.DelegateExecutionImpl;
 
  39 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
 
  40 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
 
  41 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
 
  42 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
 
  43 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
 
  44 import org.onap.so.db.catalog.client.CatalogDbClient;
 
  45 import org.onap.so.db.request.beans.InfraActiveRequests;
 
  47 @RunWith(MockitoJUnitRunner.class)
 
  48 public class MultiStageSkipListenerTest {
 
  51     private CatalogDbClient catalogDbClient;
 
  54     private BBInputSetupUtils bbInputSetupUtils;
 
  57     private MultiStageSkipListener multiStageSkipListener;
 
  60     public void testTrigger() {
 
  61         BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
 
  62         execution.setVariable(BBConstants.G_ALACARTE, true);
 
  64         assertTrue("should be triggered", multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution));
 
  66         execution.setVariable(BBConstants.G_ALACARTE, false);
 
  67         assertFalse("should not be triggered",
 
  68                 multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution));
 
  70         execution.setVariable(BBConstants.G_ALACARTE, true);
 
  71         assertFalse("should not be triggered",
 
  72                 multiStageSkipListener.shouldRunFor("AssignVfModuleBB2", true, execution));
 
  74         execution.setVariable("multiStageDesign", true);
 
  75         assertTrue("should be triggered", multiStageSkipListener.shouldRunFor(execution));
 
  77         execution.setVariable("multiStageDesign", false);
 
  78         assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor(execution));
 
  80         execution.setVariable("multiStageDesign", null);
 
  81         assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor(execution));
 
  86     public void testProcessMultiStageSkip() {
 
  87         String vfModuleId = "vfModuleId";
 
  88         String vnfId = "vnfId";
 
  89         List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
 
  90         WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
 
  91         workflowResourceIds.setServiceInstanceId("serviceInstanceId");
 
  92         workflowResourceIds.setVnfId(vnfId);
 
  93         flowsToExecute.add(new ExecuteBuildingBlock());
 
  94         flowsToExecute.add(new ExecuteBuildingBlock());
 
  95         flowsToExecute.add(new ExecuteBuildingBlock());
 
  96         flowsToExecute.get(0).setResourceId(vfModuleId);
 
  97         flowsToExecute.get(0).setBuildingBlock(new BuildingBlock());
 
  98         flowsToExecute.get(0).getBuildingBlock().setBpmnFlowName("AssignVfModuleBB");
 
  99         flowsToExecute.get(0).setWorkflowResourceIds(workflowResourceIds);
 
 100         BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
 
 102         org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule();
 
 103         vfModule.setVfModuleId(vfModuleId);
 
 104         org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf();
 
 105         vnf.setModelCustomizationId("modelCustomizationUUID");
 
 106         VnfResourceCustomization vnfCust = new VnfResourceCustomization();
 
 107         vnfCust.setModelCustomizationUUID("modelCustomizationUUID");
 
 108         vnfCust.setMultiStageDesign("true");
 
 109         when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(vnf.getModelCustomizationId()))
 
 110                 .thenReturn(vnfCust);
 
 111         when(bbInputSetupUtils.getAAIVfModule(eq(vnfId), eq(vfModuleId))).thenReturn(null);
 
 112         when(bbInputSetupUtils.getAAIGenericVnf(eq(vnfId))).thenReturn(vnf);
 
 114         multiStageSkipListener.run(flowsToExecute, flowsToExecute.get(0), execution);
 
 115         assertEquals("Flows should only have Assign", flowsToExecute.size(), 1);
 
 116         assertEquals("Flows should only have Assign", flowsToExecute.get(0).getBuildingBlock().getBpmnFlowName(),
 
 121     public void postCompletionRequestsDbListenerTest() {
 
 122         InfraActiveRequests request = new InfraActiveRequests();
 
 123         BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
 
 124         multiStageSkipListener.run(request, execution);
 
 126         assertEquals("Successfully completed Assign Building Block only due to multi-stage-design VNF",
 
 127                 request.getFlowStatus());