Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / aai / tasks / AAIDeleteTasksTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.aai.tasks;
22
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;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
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;
50
51
52 public class AAIDeleteTasksTest extends BaseTaskTest {
53         
54         @InjectMocks
55         private AAIDeleteTasks aaiDeleteTasks = new AAIDeleteTasks();
56         
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;
64         
65         @Before
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();
74                 
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);
81                 
82
83                 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
84         }
85         
86         @Test
87         public void deleteVfModuleTest() throws Exception {
88                 
89                 doNothing().when(aaiVfModuleResources).deleteVfModule(vfModule, genericVnf);
90                 
91                 aaiDeleteTasks.deleteVfModule(execution);
92                 verify(aaiVfModuleResources, times(1)).deleteVfModule(vfModule, genericVnf);
93         }
94         
95         @Test
96         public void deleteVfModuleExceptionTest() throws Exception {
97                 expectedException.expect(BpmnError.class);
98                 doThrow(RuntimeException.class).when(aaiVfModuleResources).deleteVfModule(vfModule, genericVnf);
99                 aaiDeleteTasks.deleteVfModule(execution);
100         }
101         
102         @Test
103         public void deleteServiceInstanceTest() throws Exception {
104                 doNothing().when(aaiServiceInstanceResources).deleteServiceInstance(serviceInstance);
105                 
106                 aaiDeleteTasks.deleteServiceInstance(execution);
107                 
108                 verify(aaiServiceInstanceResources, times(1)).deleteServiceInstance(serviceInstance);
109         }
110         
111         @Test 
112         public void deleteServiceInstanceExceptionTest() throws Exception {
113                 expectedException.expect(BpmnError.class);
114                 
115                 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).deleteServiceInstance(serviceInstance);
116                 
117                 aaiDeleteTasks.deleteServiceInstance(execution);
118         }       
119         
120         @Test
121         public void deleteVnfTest() throws Exception {
122                 doNothing().when(aaiVnfResources).deleteVnf(genericVnf);
123                 aaiDeleteTasks.deleteVnf(execution);
124                 verify(aaiVnfResources, times(1)).deleteVnf(genericVnf);
125         }
126         
127         @Test
128         public void deleteVnfTestException() throws Exception {
129                 expectedException.expect(BpmnError.class);
130                 doThrow(RuntimeException.class).when(aaiVnfResources).deleteVnf(genericVnf);
131                 
132                 aaiDeleteTasks.deleteVnf(execution);
133                 verify(aaiVnfResources, times(1)).deleteVnf(genericVnf);
134         }
135         
136         @Test 
137         public void deleteNetworkTest() throws Exception {
138                 doNothing().when(aaiNetworkResources).deleteNetwork(network);
139                 aaiDeleteTasks.deleteNetwork(execution);
140                 verify(aaiNetworkResources, times(1)).deleteNetwork(network);
141         }
142         
143         @Test 
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());
148         }
149         
150         @Test 
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());
155         }
156
157         @Test
158         public void deleteVolumeGroupTest() {
159                 doNothing().when(aaiVolumeGroupResources).deleteVolumeGroup(volumeGroup, cloudRegion);
160                 
161                 aaiDeleteTasks.deleteVolumeGroup(execution);
162                 
163                 verify(aaiVolumeGroupResources, times(1)).deleteVolumeGroup(volumeGroup, cloudRegion);
164         }
165         
166         @Test
167         public void deleteVolumeGroupExceptionTest() {
168                 expectedException.expect(BpmnError.class);
169                 
170                 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).deleteVolumeGroup(volumeGroup, cloudRegion);
171                 
172                 aaiDeleteTasks.deleteVolumeGroup(execution);
173         }
174         
175         @Test
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);
181         }
182 }