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 java.util.UUID;
28 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.so.bpmn.common.BBConstants;
36 import org.onap.so.bpmn.common.BuildingBlockExecution;
37 import org.onap.so.bpmn.common.DelegateExecutionImpl;
38 import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource;
39 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType;
40 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
41 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
42 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
43 import org.onap.so.db.catalog.beans.Service;
44 import org.onap.so.db.catalog.beans.VfModuleCustomization;
45 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
46 import org.onap.so.db.catalog.client.CatalogDbClient;
47 import org.onap.so.serviceinstancebeans.RequestDetails;
49 @RunWith(MockitoJUnitRunner.Silent.class)
50 public class SkipCDSBuildingBlockListenerTest {
52 private static final String SERVICE_SCOPE = "service";
53 private static final String VNF_SCOPE = "VNF";
54 private static final String VF_SCOPE = "VFModule";
55 private static final String PNF_SCOPE = "pnf";
56 private static final String VNF_TEST_ACTION = "VnfConfigAssign";
57 private static final String VFModule_TEST_ACTION = "VfModuleConfigAssign";
58 private static final String PNFModule_TEST_ACTION = "config-assign";
59 private static final String SERVICE_MODEL_VERSION_ID = UUID.randomUUID().toString();
60 private static final String VNF_MODEL_CUSTOMIZATION_ID = UUID.randomUUID().toString();
61 private static final String VF_MODULE_CUSTOMIZATION_ID = UUID.randomUUID().toString();
62 private static final String PNF_CUSTOMIZATION_ID = UUID.randomUUID().toString();
63 private static final String BBNAME = "ControllerExecutionBB";
64 private static final boolean ISFIRST = true;
66 private List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
67 private ExecuteBuildingBlock executeBuildingBlock;
68 private RequestDetails reqDetail = new RequestDetails();
69 private BuildingBlockExecution buildingBlockExecution = new DelegateExecutionImpl(new DelegateExecutionFake());
70 private VnfResourceCustomization vnfCust;
71 private VfModuleCustomization vfCust;
72 private PnfResourceCustomization pnfResourceCustomization;
73 private BuildingBlock buildingBlock;
76 private SkipCDSBuildingBlockListener skipCDSBuildingBlockListener;
78 private CatalogDbClient catalogDbClient;
81 public void before() {
82 executeBuildingBlock = new ExecuteBuildingBlock();
83 buildingBlock = new BuildingBlock();
85 ArrayList<Resource> resources = new ArrayList<>();
86 Resource service = new Resource(WorkflowType.SERVICE, SERVICE_MODEL_VERSION_ID, false, null);
87 service.setModelVersionId(SERVICE_MODEL_VERSION_ID);
88 resources.add(service);
89 Resource vnf = new Resource(WorkflowType.VNF, VNF_MODEL_CUSTOMIZATION_ID, false, null);
90 vnf.setModelCustomizationId(VNF_MODEL_CUSTOMIZATION_ID);
92 Resource vfModule = new Resource(WorkflowType.VFMODULE, VF_MODULE_CUSTOMIZATION_ID, false, null);
93 vfModule.setModelCustomizationId(VF_MODULE_CUSTOMIZATION_ID);
94 resources.add(vfModule);
95 Resource pnf = new Resource(WorkflowType.PNF, PNF_CUSTOMIZATION_ID, false, null);
96 pnf.setModelCustomizationId(PNF_CUSTOMIZATION_ID);
98 buildingBlockExecution.setVariable("resources", resources);
100 vnfCust = new VnfResourceCustomization();
101 vfCust = new VfModuleCustomization();
102 pnfResourceCustomization = new PnfResourceCustomization();
106 public void testTrigger() {
107 BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
108 skipCDSBuildingBlockListener.shouldRunFor(BBNAME, ISFIRST, execution);
109 assertEquals("ControllerExecutionBB", BBNAME);
113 public void testSkipCDSforService() {
114 setBuildingBlockAndCurrentSequence(SERVICE_SCOPE, "service-config-assign", SERVICE_MODEL_VERSION_ID, 0);
115 when(catalogDbClient.getServiceByID(SERVICE_MODEL_VERSION_ID)).thenReturn(new Service());
117 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
119 assertEquals(1, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE));
123 public void testProcessForVNFToSkipCDSBB() {
124 setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, VNF_MODEL_CUSTOMIZATION_ID, 0);
125 when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(VNF_MODEL_CUSTOMIZATION_ID))
126 .thenReturn(vnfCust);
128 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
130 assertEquals(1, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE));
134 public void testProcessForVNFNotToSkipCDSBB() {
135 setBuildingBlockAndCurrentSequence(VNF_SCOPE, VNF_TEST_ACTION, VNF_MODEL_CUSTOMIZATION_ID, 0);
136 vnfCust.setSkipPostInstConf(false);
137 when(catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(VNF_MODEL_CUSTOMIZATION_ID))
138 .thenReturn(vnfCust);
140 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
142 assertEquals(0, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE));
147 public void testProcessForVFToSkipCDSBB() {
148 setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, VF_MODULE_CUSTOMIZATION_ID, 0);
149 when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(VF_MODULE_CUSTOMIZATION_ID))
152 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
154 assertEquals(1, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE));
158 public void testProcessForVFNotToSkipCDSBB() {
159 setBuildingBlockAndCurrentSequence(VF_SCOPE, VFModule_TEST_ACTION, VF_MODULE_CUSTOMIZATION_ID, 0);
160 vfCust.setSkipPostInstConf(false);
162 .getVfModuleCustomizationByModelCuztomizationUUID(executeBuildingBlock.getBuildingBlock().getKey()))
165 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
167 assertEquals(0, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE));
171 public void testProcessForPNFToSkipCDSBB() {
172 setBuildingBlockAndCurrentSequence(PNF_SCOPE, PNFModule_TEST_ACTION, PNF_CUSTOMIZATION_ID, 0);
173 when(catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(PNF_CUSTOMIZATION_ID))
174 .thenReturn(pnfResourceCustomization);
176 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
178 assertEquals(1, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE));
182 public void testProcessForPNFNotToSkipCDSBB() {
183 setBuildingBlockAndCurrentSequence(PNF_SCOPE, PNFModule_TEST_ACTION, PNF_CUSTOMIZATION_ID, 0);
184 pnfResourceCustomization.setSkipPostInstConf(false);
185 when(catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(PNF_CUSTOMIZATION_ID))
186 .thenReturn(pnfResourceCustomization);
188 skipCDSBuildingBlockListener.run(flowsToExecute, executeBuildingBlock, buildingBlockExecution);
190 assertEquals(0, (int) buildingBlockExecution.getVariable(BBConstants.G_CURRENT_SEQUENCE));
194 * setting scope action in buildingBlock and BB current sequence in BuildingBlockExecution
200 private void setBuildingBlockAndCurrentSequence(String scope, String action, String key, int sequence) {
201 buildingBlock.setBpmnScope(scope);
202 buildingBlock.setBpmnAction(action);
203 buildingBlock.setBpmnFlowName("ControllerExecutionBB");
204 buildingBlock.setKey(key);
205 executeBuildingBlock.setBuildingBlock(buildingBlock);
206 buildingBlockExecution.setVariable(BBConstants.G_CURRENT_SEQUENCE, sequence);