aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/listeners/SkipConfigVnfListenerTest.java
blob: 64c42fa577d22a562e8f75a70ad5aaaaf9cc3ae6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2020 Nokia
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.so.bpmn.infrastructure.workflow.tasks.listeners;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.common.DelegateExecutionImpl;
import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
import org.onap.so.db.catalog.beans.VnfResourceCustomization;
import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.RequestDetails;

@RunWith(MockitoJUnitRunner.class)
public class SkipConfigVnfListenerTest {

    private static final String MODEL_UUID = "modelUuidTest";
    private static final String VNF_CUSTOMIZATION_UUID = "vnfCustomizationUUIDTest";
    private static final String G_CURRENT_SEQUENCE = "gCurrentSequence";

    private DelegateExecution execution;
    @Mock
    private CatalogDbClient catalogDbClientMock;
    @InjectMocks
    private SkipConfigVnfListener testedObject;
    private BuildingBlockExecution buildingBlockExecution;

    @Before
    public void setup() {
        execution = new DelegateExecutionFake();
        buildingBlockExecution = new DelegateExecutionImpl(execution);
    }

    @Test
    public void shouldRunFor_ConfigAssignVnfBB() {
        assertThat(testedObject.shouldRunFor("ConfigAssignVnfBB", true, null)).isTrue();
    }

    @Test
    public void shouldRunFor_ConfigDeployVnfBB() {
        assertThat(testedObject.shouldRunFor("ConfigDeployVnfBB", true, null)).isTrue();
    }

    @Test
    public void shouldNotRunFor_notConfigBB() {
        assertThat(testedObject.shouldRunFor("BBtest", true, null)).isFalse();
    }

    @Test
    public void skipVnfSuccessful_sequenceIncremented() {
        // given
        execution.setVariable(G_CURRENT_SEQUENCE, 0);
        List<VnfResourceCustomization> vnfResourceCustomizations = createVnfResourceCustomizationList();
        when(catalogDbClientMock.getVnfResourceCustomizationByModelUuid(MODEL_UUID))
                .thenReturn(vnfResourceCustomizations);
        when(catalogDbClientMock.findVnfResourceCustomizationInList(VNF_CUSTOMIZATION_UUID, vnfResourceCustomizations))
                .thenReturn(createVnfResourceCustomization());
        // when
        testedObject.run(null, createExecuteBuildingBlock(), buildingBlockExecution);
        // then
        assertThat((int) execution.getVariable(G_CURRENT_SEQUENCE)).isEqualTo(1);
    }

    private ExecuteBuildingBlock createExecuteBuildingBlock() {
        ModelInfo modelInfo = new ModelInfo();
        modelInfo.setModelUuid(MODEL_UUID);
        RequestDetails requestDetails = new RequestDetails();
        requestDetails.setModelInfo(modelInfo);

        ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
        BuildingBlock buildingBlock = new BuildingBlock();
        buildingBlock.setKey(VNF_CUSTOMIZATION_UUID);
        executeBuildingBlock.setBuildingBlock(buildingBlock);
        executeBuildingBlock.setRequestDetails(requestDetails);
        return executeBuildingBlock;
    }

    private List<VnfResourceCustomization> createVnfResourceCustomizationList() {
        VnfResourceCustomization vnfResourceCustomization2 = new VnfResourceCustomization();
        vnfResourceCustomization2.setSkipPostInstConf(false);
        return new ArrayList<>(Arrays.asList(createVnfResourceCustomization(), vnfResourceCustomization2));
    }

    private VnfResourceCustomization createVnfResourceCustomization() {
        VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
        vnfResourceCustomization.setSkipPostInstConf(true);
        return vnfResourceCustomization;
    }

}