add junit coverage
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / vfmodule / DeleteVfModuleTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nokia
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.vfmodule;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.when;
25 import org.camunda.bpm.engine.delegate.DelegateExecution;
26 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.junit.MockitoJUnitRunner;
32 import org.onap.so.bpmn.common.BuildingBlockExecution;
33 import org.onap.so.bpmn.common.DelegateExecutionImpl;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.Tenant;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
38 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
39 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
40 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
41 import org.onap.so.client.exception.BBObjectNotFoundException;
42 import org.onap.so.cloud.resource.beans.CloudInformation;
43
44 @RunWith(MockitoJUnitRunner.class)
45 public class DeleteVfModuleTest {
46
47     private static final String VF_MODULE_ID = "vfModuleIdTest";
48     private static final String HEAT_STACK_ID = "hsId";
49     private static final String VNF_ID = "vnfId";
50     private static final String VNF_NAME = "vnfName";
51
52     private static final String CLOUD_OWNER = "cloudOwTest";
53     private static final String LCP_CLOUD_REGION_ID = "lcpClRegTest";
54     private static final String TENANT_ID = "tenantIdTest";
55     private static final String TENANT_NAME = "tenantNameTest";
56     private static final String TENANT_CONTEXT = "tenantContext";
57
58     @Mock
59     private ExtractPojosForBB extractPojosForBB;
60
61     @InjectMocks
62     private DeleteVFModule testedObject;
63
64     @Test
65     public void createInventoryVariable_Success() throws BBObjectNotFoundException {
66         // given
67         BuildingBlockExecution buildingBlockExecution = prepareBuildingBlockExecution();
68         when(extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.VF_MODULE_ID))
69                 .thenReturn(prepareVmModule());
70         when(extractPojosForBB.extractByKey(buildingBlockExecution, ResourceKey.GENERIC_VNF_ID))
71                 .thenReturn(prepareGenericVnf());
72         // when
73         testedObject.createInventoryVariable(buildingBlockExecution);
74         // then
75         verifyExecution(buildingBlockExecution);
76     }
77
78     private void verifyExecution(BuildingBlockExecution buildingBlockExecution) {
79         CloudInformation cloudInformation = buildingBlockExecution.getVariable("cloudInformation");
80         assertThat(cloudInformation.getOwner()).isEqualTo(CLOUD_OWNER);
81         assertThat(cloudInformation.getRegionId()).isEqualTo(LCP_CLOUD_REGION_ID);
82         assertThat(cloudInformation.getTenantId()).isEqualTo(TENANT_ID);
83         assertThat(cloudInformation.getTenantName()).isEqualTo(TENANT_NAME);
84         assertThat(cloudInformation.getTenantContext()).isEqualTo(TENANT_CONTEXT);
85         assertThat(cloudInformation.getTemplateInstanceId()).isEqualTo(HEAT_STACK_ID);
86
87         assertThat(cloudInformation.getVnfId()).isEqualTo(VNF_ID);
88         assertThat(cloudInformation.getVnfName()).isEqualTo(VNF_NAME);
89         assertThat(cloudInformation.getVfModuleId()).isEqualTo(VF_MODULE_ID);
90     }
91
92     private BuildingBlockExecution prepareBuildingBlockExecution() {
93         DelegateExecution execution = new DelegateExecutionFake();
94         execution.setVariable("gBBInput", prepareGeneralBuildingBlock());
95         return new DelegateExecutionImpl(execution);
96     }
97
98     private GeneralBuildingBlock prepareGeneralBuildingBlock() {
99         GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock();
100         CloudRegion cloudRegion = new CloudRegion();
101         cloudRegion.setCloudOwner(CLOUD_OWNER);
102         cloudRegion.setLcpCloudRegionId(LCP_CLOUD_REGION_ID);
103         generalBuildingBlock.setCloudRegion(cloudRegion);
104         Tenant tenant = new Tenant();
105         tenant.setTenantId(TENANT_ID);
106         tenant.setTenantName(TENANT_NAME);
107         tenant.setTenantContext(TENANT_CONTEXT);
108         generalBuildingBlock.setTenant(tenant);
109         return generalBuildingBlock;
110     }
111
112     private VfModule prepareVmModule() {
113         VfModule vfModule = new VfModule();
114         vfModule.setVfModuleId(VF_MODULE_ID);
115         vfModule.setHeatStackId(HEAT_STACK_ID);
116         return vfModule;
117     }
118
119     private GenericVnf prepareGenericVnf() {
120         GenericVnf genericVnf = new GenericVnf();
121         genericVnf.setVnfId(VNF_ID);
122         genericVnf.setVnfName(VNF_NAME);
123         return genericVnf;
124     }
125 }