2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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.workflow.tasks.listeners;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.when;
25 import java.util.ArrayList;
26 import java.util.List;
27 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.so.bpmn.common.BBConstants;
35 import org.onap.so.bpmn.common.BuildingBlockExecution;
36 import org.onap.so.bpmn.common.DelegateExecutionImpl;
37 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
38 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
39 import org.onap.so.db.catalog.beans.VfModuleCustomization;
40 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
41 import org.onap.so.db.catalog.client.CatalogDbClient;
42 import org.onap.so.serviceinstancebeans.ModelInfo;
43 import org.onap.so.serviceinstancebeans.RequestDetails;
45 @RunWith(MockitoJUnitRunner.Silent.class)
46 public class SkipCDSBuildingBlockListenerTest {
48 private static final String VNF_SCOPE = "VNF";
49 private static final String VF_SCOPE = "VFModule";
50 private static final String TEST_MODELUUID = "123456789";
51 private static final String VNF_TEST_ACTION = "VnfConfigAssign";
52 private static final String VFModule_TEST_ACTION = "VfModuleConfigAssign";
53 private static final String MODELCUSTOMIZATIONUUID = "123456789";
54 private static final String BBNAME = "ControllerExecutionBB";
55 private static final boolean ISFIRST = true;
58 private List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
59 private List<VnfResourceCustomization> vnfResourceCustomization;
60 private List<VfModuleCustomization> vfModuleCustomization;
61 private ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
62 private RequestDetails reqDetail = new RequestDetails();
63 private BuildingBlockExecution buildingBlockExecution = new DelegateExecutionImpl(new DelegateExecutionFake());
64 private VnfResourceCustomization vnfCust = new VnfResourceCustomization();
65 private VfModuleCustomization vfCust = new VfModuleCustomization();
66 private BuildingBlock buildingBlock = new BuildingBlock();
69 private SkipCDSBuildingBlockListener skipCDSBuildingBlockListener;
71 private CatalogDbClient catalogDbClient;
74 public void before() {
75 ModelInfo model = new ModelInfo();
76 model.setModelUuid(TEST_MODELUUID);
77 reqDetail.setModelInfo(model);
78 executeBuildingBlock.setRequestDetails(reqDetail);
82 public void testTrigger() {
83 BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
84 skipCDSBuildingBlockListener.shouldRunFor(BBNAME, ISFIRST, execution);
85 assertEquals("ControllerExecutionBB", BBNAME);
89 public void testProcessForVNFToSkipCDSBB() {
91 setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, 0);
92 vnfResourceCustomization = getVnfResourceCustomizationList(true);
94 when(catalogDbClient.getVnfResourceCustomizationByModelUuid(
95 executeBuildingBlock.getRequestDetails().getModelInfo().getModelUuid()))
96 .thenReturn(vnfResourceCustomization);
97 when(catalogDbClient.findVnfResourceCustomizationInList(executeBuildingBlock.getBuildingBlock().getKey(),
98 vnfResourceCustomization)).thenReturn(vnfCust);
101 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
104 actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
105 assertEquals(1, actual);
110 public void testProcessForVNFNotToSkipCDSBB() {
112 setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, 0);
113 vnfResourceCustomization = getVnfResourceCustomizationList(false);
115 when(catalogDbClient.getVnfResourceCustomizationByModelUuid(
116 executeBuildingBlock.getRequestDetails().getModelInfo().getModelUuid()))
117 .thenReturn(vnfResourceCustomization);
118 when(catalogDbClient.findVnfResourceCustomizationInList(executeBuildingBlock.getBuildingBlock().getKey(),
119 vnfResourceCustomization)).thenReturn(vnfCust);
122 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
125 actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
126 assertEquals(0, actual);
132 public void testProcessForVFToSkipCDSBB() {
134 setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, 0);
135 vfModuleCustomization = getVfModuleCustomizationList(true);
138 .getVfModuleCustomizationByModelCuztomizationUUID(executeBuildingBlock.getBuildingBlock().getKey()))
142 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
145 actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
146 assertEquals(1, actual);
151 public void testProcessForVFNotToSkipCDSBB() {
153 setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, 0);
154 vfModuleCustomization = getVfModuleCustomizationList(false);
157 .getVfModuleCustomizationByModelCuztomizationUUID(executeBuildingBlock.getBuildingBlock().getKey()))
161 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
164 actual = buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE);
165 assertEquals(0, actual);
170 * setting scope action in buildingBlock and BB current sequence in BuildingBlockExecution
176 private void setBuildingBlockAndCurrentSequence(String scope, String action, int sequence) {
177 buildingBlock.setBpmnScope(scope);
178 buildingBlock.setBpmnAction(action);
179 buildingBlock.setBpmnFlowName("ControllerExecutionBB");
180 buildingBlock.setKey(MODELCUSTOMIZATIONUUID);
181 executeBuildingBlock.setBuildingBlock(buildingBlock);
182 buildingBlockExecution.setVariable(BBConstants.G_CURRENT_SEQUENCE, sequence);
186 private List<VnfResourceCustomization> getVnfResourceCustomizationList(boolean setSkippost) {
187 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
188 vnfCust.setModelCustomizationUUID(MODELCUSTOMIZATIONUUID);
189 vnfCust.setSkipPostInstConf(setSkippost);
190 vnfResourceCustomizations.add(vnfCust);
191 return vnfResourceCustomizations;
194 private List<VfModuleCustomization> getVfModuleCustomizationList(boolean setSkippost) {
195 List<VfModuleCustomization> vfModuleCustomizations = new ArrayList<>();
196 vfCust.setModelCustomizationUUID(MODELCUSTOMIZATIONUUID);
197 vfCust.setSkipPostInstConf(setSkippost);
198 vfModuleCustomizations.add(vfCust);
199 return vfModuleCustomizations;