64c42fa577d22a562e8f75a70ad5aaaaf9cc3ae6
[so.git] /
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.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;
45
46 @RunWith(MockitoJUnitRunner.class)
47 public class SkipConfigVnfListenerTest {
48
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";
52
53     private DelegateExecution execution;
54     @Mock
55     private CatalogDbClient catalogDbClientMock;
56     @InjectMocks
57     private SkipConfigVnfListener testedObject;
58     private BuildingBlockExecution buildingBlockExecution;
59
60     @Before
61     public void setup() {
62         execution = new DelegateExecutionFake();
63         buildingBlockExecution = new DelegateExecutionImpl(execution);
64     }
65
66     @Test
67     public void shouldRunFor_ConfigAssignVnfBB() {
68         assertThat(testedObject.shouldRunFor("ConfigAssignVnfBB", true, null)).isTrue();
69     }
70
71     @Test
72     public void shouldRunFor_ConfigDeployVnfBB() {
73         assertThat(testedObject.shouldRunFor("ConfigDeployVnfBB", true, null)).isTrue();
74     }
75
76     @Test
77     public void shouldNotRunFor_notConfigBB() {
78         assertThat(testedObject.shouldRunFor("BBtest", true, null)).isFalse();
79     }
80
81     @Test
82     public void skipVnfSuccessful_sequenceIncremented() {
83         // given
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());
90         // when
91         testedObject.run(null, createExecuteBuildingBlock(), buildingBlockExecution);
92         // then
93         assertThat((int) execution.getVariable(G_CURRENT_SEQUENCE)).isEqualTo(1);
94     }
95
96     private ExecuteBuildingBlock createExecuteBuildingBlock() {
97         ModelInfo modelInfo = new ModelInfo();
98         modelInfo.setModelUuid(MODEL_UUID);
99         RequestDetails requestDetails = new RequestDetails();
100         requestDetails.setModelInfo(modelInfo);
101
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;
108     }
109
110     private List<VnfResourceCustomization> createVnfResourceCustomizationList() {
111         VnfResourceCustomization vnfResourceCustomization2 = new VnfResourceCustomization();
112         vnfResourceCustomization2.setSkipPostInstConf(false);
113         return new ArrayList<>(Arrays.asList(createVnfResourceCustomization(), vnfResourceCustomization2));
114     }
115
116     private VnfResourceCustomization createVnfResourceCustomization() {
117         VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
118         vnfResourceCustomization.setSkipPostInstConf(true);
119         return vnfResourceCustomization;
120     }
121
122 }