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.when;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28 import org.camunda.bpm.engine.delegate.DelegateExecution;
29 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
30 import org.junit.Before;
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.Spy;
36 import org.mockito.junit.MockitoJUnitRunner;
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.db.catalog.beans.VnfResourceCustomization;
42 import org.onap.so.db.catalog.client.CatalogDbClient;
43 import org.onap.so.serviceinstancebeans.ModelInfo;
44 import org.onap.so.serviceinstancebeans.RequestDetails;
46 @RunWith(MockitoJUnitRunner.class)
47 public class SkipConfigVnfListenerTest {
49 private static final String MODEL_UUID = "modelUuidTest";
50 private static final String VNF_CUSTOMIZATION_UUID = "vnfCustomizationUUIDTest";
51 private static final String G_CURRENT_SEQUENCE = "gCurrentSequence";
53 private DelegateExecution execution;
55 private CatalogDbClient catalogDbClientMock;
57 private SkipConfigVnfListener testedObject;
58 private BuildingBlockExecution buildingBlockExecution;
62 execution = new DelegateExecutionFake();
63 buildingBlockExecution = new DelegateExecutionImpl(execution);
67 public void shouldRunFor_ConfigAssignVnfBB() {
68 assertThat(testedObject.shouldRunFor("ConfigAssignVnfBB", true, null)).isTrue();
72 public void shouldRunFor_ConfigDeployVnfBB() {
73 assertThat(testedObject.shouldRunFor("ConfigDeployVnfBB", true, null)).isTrue();
77 public void shouldNotRunFor_notConfigBB() {
78 assertThat(testedObject.shouldRunFor("BBtest", true, null)).isFalse();
82 public void skipVnfSuccessful_sequenceIncremented() {
84 execution.setVariable(G_CURRENT_SEQUENCE, 0);
85 List<VnfResourceCustomization> vnfResourceCustomizations = createVnfResourceCustomizationList();
86 when(catalogDbClientMock.getVnfResourceCustomizationByModelUuid(MODEL_UUID))
87 .thenReturn(vnfResourceCustomizations);
88 when(catalogDbClientMock.findVnfResourceCustomizationInList(VNF_CUSTOMIZATION_UUID, vnfResourceCustomizations))
89 .thenReturn(createVnfResourceCustomization());
91 testedObject.run(null, createExecuteBuildingBlock(), buildingBlockExecution);
93 assertThat((int) execution.getVariable(G_CURRENT_SEQUENCE)).isEqualTo(1);
96 private ExecuteBuildingBlock createExecuteBuildingBlock() {
97 ModelInfo modelInfo = new ModelInfo();
98 modelInfo.setModelUuid(MODEL_UUID);
99 RequestDetails requestDetails = new RequestDetails();
100 requestDetails.setModelInfo(modelInfo);
102 ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
103 BuildingBlock buildingBlock = new BuildingBlock();
104 buildingBlock.setKey(VNF_CUSTOMIZATION_UUID);
105 executeBuildingBlock.setBuildingBlock(buildingBlock);
106 executeBuildingBlock.setRequestDetails(requestDetails);
107 return executeBuildingBlock;
110 private List<VnfResourceCustomization> createVnfResourceCustomizationList() {
111 VnfResourceCustomization vnfResourceCustomization2 = new VnfResourceCustomization();
112 vnfResourceCustomization2.setSkipPostInstConf(false);
113 return new ArrayList<>(Arrays.asList(createVnfResourceCustomization(), vnfResourceCustomization2));
116 private VnfResourceCustomization createVnfResourceCustomization() {
117 VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
118 vnfResourceCustomization.setSkipPostInstConf(true);
119 return vnfResourceCustomization;