2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia
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.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.so.bpmn.common.BuildingBlockExecution;
34 import org.onap.so.bpmn.common.DelegateExecutionImpl;
35 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
36 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
37 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
38 import org.onap.so.db.catalog.client.CatalogDbClient;
39 import org.onap.so.serviceinstancebeans.ModelInfo;
40 import org.onap.so.serviceinstancebeans.RequestDetails;
42 public class SkipConfigVnfListenerTest {
44 private static final String MODEL_UUID = "modelUuidTest";
45 private static final String VNF_CUSTOMIZATION_UUID = "vnfCustomizationUUIDTest";
46 private static final String G_CURRENT_SEQUENCE = "gCurrentSequence";
48 private DelegateExecution execution;
49 private CatalogDbClient catalogDbClientMock;
50 private SkipConfigVnfListener testedObject;
51 private BuildingBlockExecution buildingBlockExecution;
55 execution = new DelegateExecutionFake();
56 buildingBlockExecution = new DelegateExecutionImpl(execution);
57 catalogDbClientMock = mock(CatalogDbClient.class);
58 testedObject = new SkipConfigVnfListener(catalogDbClientMock);
62 public void shouldRunFor_ConfigAssignVnfBB() {
63 assertThat(testedObject.shouldRunFor("ConfigAssignVnfBB", true, null)).isTrue();
67 public void shouldRunFor_ConfigDeployVnfBB() {
68 assertThat(testedObject.shouldRunFor("ConfigDeployVnfBB", true, null)).isTrue();
72 public void shouldNotRunFor_notConfigBB() {
73 assertThat(testedObject.shouldRunFor("BBtest", true, null)).isFalse();
77 public void skipVnfSuccessful_sequenceIncremented() {
79 execution.setVariable(G_CURRENT_SEQUENCE, 0);
80 List<VnfResourceCustomization> vnfResourceCustomizations = createVnfResourceCustomizationList();
81 when(catalogDbClientMock.getVnfResourceCustomizationByModelUuid(MODEL_UUID))
82 .thenReturn(vnfResourceCustomizations);
83 when(catalogDbClientMock.findVnfResourceCustomizationInList(VNF_CUSTOMIZATION_UUID, vnfResourceCustomizations))
84 .thenReturn(createVnfResourceCustomization());
86 testedObject.run(null, createExecuteBuildingBlock(), buildingBlockExecution);
88 assertThat((int) execution.getVariable(G_CURRENT_SEQUENCE)).isEqualTo(1);
91 private ExecuteBuildingBlock createExecuteBuildingBlock() {
92 ModelInfo modelInfo = new ModelInfo();
93 modelInfo.setModelUuid(MODEL_UUID);
94 RequestDetails requestDetails = new RequestDetails();
95 requestDetails.setModelInfo(modelInfo);
97 ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
98 BuildingBlock buildingBlock = new BuildingBlock();
99 buildingBlock.setKey(VNF_CUSTOMIZATION_UUID);
100 executeBuildingBlock.setBuildingBlock(buildingBlock);
101 executeBuildingBlock.setRequestDetails(requestDetails);
102 return executeBuildingBlock;
105 private List<VnfResourceCustomization> createVnfResourceCustomizationList() {
106 VnfResourceCustomization vnfResourceCustomization2 = new VnfResourceCustomization();
107 vnfResourceCustomization2.setSkipPostInstConf(false);
108 return new ArrayList<>(Arrays.asList(createVnfResourceCustomization(), vnfResourceCustomization2));
111 private VnfResourceCustomization createVnfResourceCustomization() {
112 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
113 vnfResourceCustomization.setSkipPostInstConf(true);
114 return vnfResourceCustomization;