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.infrastructure.workflow.tasks.listeners.MultiStageSkipListener;
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.WorkflowResourceIds;
43 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
44 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
45 import org.onap.so.db.catalog.client.CatalogDbClient;
47 @RunWith(MockitoJUnitRunner.class)
48 public class MultiStageSkipTest {
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));
78 public void testProcessMultiStageSkip() {
79 String vfModuleId = "vfModuleId";
80 String vnfId = "vnfId";
81 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
82 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
83 workflowResourceIds.setServiceInstanceId("serviceInstanceId");
84 workflowResourceIds.setVnfId(vnfId);
85 flowsToExecute.add(new ExecuteBuildingBlock());
86 flowsToExecute.add(new ExecuteBuildingBlock());
87 flowsToExecute.add(new ExecuteBuildingBlock());
88 flowsToExecute.get(0).setResourceId(vfModuleId);
89 flowsToExecute.get(0).setBuildingBlock(new BuildingBlock());
90 flowsToExecute.get(0).getBuildingBlock().setBpmnFlowName("AssignVfModuleBB");
91 flowsToExecute.get(0).setWorkflowResourceIds(workflowResourceIds);
92 BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
94 org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule();
95 vfModule.setVfModuleId(vfModuleId);
96 org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf();
97 vnf.setModelCustomizationId("modelCustomizationUUID");
98 VnfResourceCustomization vnfCust = new VnfResourceCustomization();
99 vnfCust.setModelCustomizationUUID("modelCustomizationUUID");
100 vnfCust.setMultiStageDesign("true");
101 when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(vnf.getModelCustomizationId()))
102 .thenReturn(vnfCust);
103 when(bbInputSetupUtils.getAAIVfModule(eq(vnfId), eq(vfModuleId))).thenReturn(null);
104 when(bbInputSetupUtils.getAAIGenericVnf(eq(vnfId))).thenReturn(vnf);
106 multiStageSkipListener.run(flowsToExecute, flowsToExecute.get(0), execution);
107 assertEquals("Flows should only have Assign", flowsToExecute.size(), 1);
108 assertEquals("Flows should only have Assign", flowsToExecute.get(0).getBuildingBlock().getBpmnFlowName(),