2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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.aai.tasks;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.doThrow;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
31 import java.util.ArrayList;
32 import java.util.List;
34 import org.camunda.bpm.engine.delegate.BpmnError;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.ArgumentMatchers;
38 import org.mockito.InjectMocks;
39 import org.onap.so.bpmn.BaseTaskTest;
40 import org.onap.so.bpmn.common.BuildingBlockExecution;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
48 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
49 import org.onap.so.client.exception.BBObjectNotFoundException;
52 public class AAIDeleteTasksTest extends BaseTaskTest {
55 private AAIDeleteTasks aaiDeleteTasks = new AAIDeleteTasks();
57 private L3Network network;
58 private ServiceInstance serviceInstance;
59 private GenericVnf genericVnf;
60 private VfModule vfModule;
61 private VolumeGroup volumeGroup;
62 private CloudRegion cloudRegion;
63 private Configuration configuration;
66 public void before() throws BBObjectNotFoundException {
67 serviceInstance = setServiceInstance();
68 genericVnf = setGenericVnf();
69 vfModule = setVfModule();
70 network = setL3Network();
71 volumeGroup = setVolumeGroup();
72 cloudRegion = setCloudRegion();
73 configuration = setConfiguration();
75 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
76 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
77 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID), any())).thenReturn(network);
78 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID), any())).thenReturn(volumeGroup);
79 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance);
80 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID), any())).thenReturn(configuration);
83 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
87 public void deleteVfModuleTest() throws Exception {
89 doNothing().when(aaiVfModuleResources).deleteVfModule(vfModule, genericVnf);
91 aaiDeleteTasks.deleteVfModule(execution);
92 verify(aaiVfModuleResources, times(1)).deleteVfModule(vfModule, genericVnf);
96 public void deleteVfModuleExceptionTest() throws Exception {
97 expectedException.expect(BpmnError.class);
98 doThrow(RuntimeException.class).when(aaiVfModuleResources).deleteVfModule(vfModule, genericVnf);
99 aaiDeleteTasks.deleteVfModule(execution);
103 public void deleteServiceInstanceTest() throws Exception {
104 doNothing().when(aaiServiceInstanceResources).deleteServiceInstance(serviceInstance);
106 aaiDeleteTasks.deleteServiceInstance(execution);
108 verify(aaiServiceInstanceResources, times(1)).deleteServiceInstance(serviceInstance);
112 public void deleteServiceInstanceExceptionTest() throws Exception {
113 expectedException.expect(BpmnError.class);
115 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).deleteServiceInstance(serviceInstance);
117 aaiDeleteTasks.deleteServiceInstance(execution);
121 public void deleteVnfTest() throws Exception {
122 doNothing().when(aaiVnfResources).deleteVnf(genericVnf);
123 aaiDeleteTasks.deleteVnf(execution);
124 verify(aaiVnfResources, times(1)).deleteVnf(genericVnf);
128 public void deleteVnfTestException() throws Exception {
129 expectedException.expect(BpmnError.class);
130 doThrow(RuntimeException.class).when(aaiVnfResources).deleteVnf(genericVnf);
132 aaiDeleteTasks.deleteVnf(execution);
133 verify(aaiVnfResources, times(1)).deleteVnf(genericVnf);
137 public void deleteNetworkTest() throws Exception {
138 doNothing().when(aaiNetworkResources).deleteNetwork(network);
139 aaiDeleteTasks.deleteNetwork(execution);
140 verify(aaiNetworkResources, times(1)).deleteNetwork(network);
144 public void deleteCollectionTest() throws Exception {
145 doNothing().when(aaiNetworkResources).deleteCollection(serviceInstance.getCollection());
146 aaiDeleteTasks.deleteCollection(execution);
147 verify(aaiNetworkResources, times(1)).deleteCollection(serviceInstance.getCollection());
151 public void deleteInstanceGroupTest() throws Exception {
152 doNothing().when(aaiNetworkResources).deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
153 aaiDeleteTasks.deleteInstanceGroup(execution);
154 verify(aaiNetworkResources, times(1)).deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
158 public void deleteVolumeGroupTest() {
159 doNothing().when(aaiVolumeGroupResources).deleteVolumeGroup(volumeGroup, cloudRegion);
161 aaiDeleteTasks.deleteVolumeGroup(execution);
163 verify(aaiVolumeGroupResources, times(1)).deleteVolumeGroup(volumeGroup, cloudRegion);
167 public void deleteVolumeGroupExceptionTest() {
168 expectedException.expect(BpmnError.class);
170 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).deleteVolumeGroup(volumeGroup, cloudRegion);
172 aaiDeleteTasks.deleteVolumeGroup(execution);
176 public void deleteConfigurationTest() throws Exception {
177 gBBInput = execution.getGeneralBuildingBlock();
178 doNothing().when(aaiConfigurationResources).deleteConfiguration(configuration);
179 aaiDeleteTasks.deleteConfiguration(execution);
180 verify(aaiConfigurationResources, times(1)).deleteConfiguration(configuration);