add junit coverage
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / workflow / tasks / listeners / SkipConfigVnfListenerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.workflow.tasks.listeners;
22
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;
41
42 public class SkipConfigVnfListenerTest {
43
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";
47
48     private DelegateExecution execution;
49     private CatalogDbClient catalogDbClientMock;
50     private SkipConfigVnfListener testedObject;
51     private BuildingBlockExecution buildingBlockExecution;
52
53     @Before
54     public void setup() {
55         execution = new DelegateExecutionFake();
56         buildingBlockExecution = new DelegateExecutionImpl(execution);
57         catalogDbClientMock = mock(CatalogDbClient.class);
58         testedObject = new SkipConfigVnfListener(catalogDbClientMock);
59     }
60
61     @Test
62     public void shouldRunFor_ConfigAssignVnfBB() {
63         assertThat(testedObject.shouldRunFor("ConfigAssignVnfBB", true, null)).isTrue();
64     }
65
66     @Test
67     public void shouldRunFor_ConfigDeployVnfBB() {
68         assertThat(testedObject.shouldRunFor("ConfigDeployVnfBB", true, null)).isTrue();
69     }
70
71     @Test
72     public void shouldNotRunFor_notConfigBB() {
73         assertThat(testedObject.shouldRunFor("BBtest", true, null)).isFalse();
74     }
75
76     @Test
77     public void skipVnfSuccessful_sequenceIncremented() {
78         // given
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());
85         // when
86         testedObject.run(null, createExecuteBuildingBlock(), buildingBlockExecution);
87         // then
88         assertThat((int) execution.getVariable(G_CURRENT_SEQUENCE)).isEqualTo(1);
89     }
90
91     private ExecuteBuildingBlock createExecuteBuildingBlock() {
92         ModelInfo modelInfo = new ModelInfo();
93         modelInfo.setModelUuid(MODEL_UUID);
94         RequestDetails requestDetails = new RequestDetails();
95         requestDetails.setModelInfo(modelInfo);
96
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;
103     }
104
105     private List<VnfResourceCustomization> createVnfResourceCustomizationList() {
106         VnfResourceCustomization vnfResourceCustomization2 = new VnfResourceCustomization();
107         vnfResourceCustomization2.setSkipPostInstConf(false);
108         return new ArrayList<>(Arrays.asList(createVnfResourceCustomization(), vnfResourceCustomization2));
109     }
110
111     private VnfResourceCustomization createVnfResourceCustomization() {
112         VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
113         vnfResourceCustomization.setSkipPostInstConf(true);
114         return vnfResourceCustomization;
115     }
116
117 }