efe5b5d97144e283797494281fdea7729f8e201f
[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.Mockito.doNothing;
24 import static org.mockito.Mockito.doThrow;
25 import static org.mockito.Mockito.times;
26 import static org.mockito.Mockito.verify;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.so.bpmn.BaseTaskTest;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
42 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
43 import org.springframework.beans.factory.annotation.Autowired;
44
45 public class AAIDeleteTasksTest extends BaseTaskTest {
46         @Autowired
47         private AAIDeleteTasks aaiDeleteTasks;
48         
49         private L3Network network;
50         private ServiceInstance serviceInstance;
51         private GenericVnf genericVnf;
52         private VfModule vfModule;
53         private VolumeGroup volumeGroup;
54         private CloudRegion cloudRegion;
55         private Configuration configuration;
56         
57         @Before
58         public void before() {
59                 serviceInstance = setServiceInstance();
60                 genericVnf = setGenericVnf();
61                 vfModule = setVfModule();
62                 network = setL3Network();
63                 volumeGroup = setVolumeGroup();
64                 cloudRegion = setCloudRegion();
65                 configuration = setConfiguration();
66         }
67         
68         @Test
69         public void deleteVfModuleTest() throws Exception {
70                 doNothing().when(aaiVfModuleResources).deleteVfModule(vfModule, genericVnf);
71                 aaiDeleteTasks.deleteVfModule(execution);
72                 verify(aaiVfModuleResources, times(1)).deleteVfModule(vfModule, genericVnf);
73         }
74         
75         @Test
76         public void deleteVfModuleExceptionTest() throws Exception {
77                 expectedException.expect(BpmnError.class);
78                 doThrow(Exception.class).when(aaiVfModuleResources).deleteVfModule(vfModule, genericVnf);
79                 aaiDeleteTasks.deleteVfModule(execution);
80         }
81         
82         @Test
83         public void deleteServiceInstanceTest() throws Exception {
84                 doNothing().when(aaiServiceInstanceResources).deleteServiceInstance(serviceInstance);
85                 
86                 aaiDeleteTasks.deleteServiceInstance(execution);
87                 
88                 verify(aaiServiceInstanceResources, times(1)).deleteServiceInstance(serviceInstance);
89         }
90         
91         @Test 
92         public void deleteServiceInstanceExceptionTest() throws Exception {
93                 expectedException.expect(BpmnError.class);
94                 
95                 doThrow(Exception.class).when(aaiServiceInstanceResources).deleteServiceInstance(serviceInstance);
96                 
97                 aaiDeleteTasks.deleteServiceInstance(execution);
98         }       
99         
100         @Test
101         public void deleteVnfTest() throws Exception {
102                 doNothing().when(aaiVnfResources).deleteVnf(genericVnf);
103                 aaiDeleteTasks.deleteVnf(execution);
104                 verify(aaiVnfResources, times(1)).deleteVnf(genericVnf);
105         }
106         
107         @Test
108         public void deleteVnfTestException() throws Exception {
109                 expectedException.expect(BpmnError.class);
110                 doThrow(Exception.class).when(aaiVnfResources).deleteVnf(genericVnf);
111                 
112                 aaiDeleteTasks.deleteVnf(execution);
113                 verify(aaiVnfResources, times(1)).deleteVnf(genericVnf);
114         }
115         
116         @Test 
117         public void deleteNetworkTest() throws Exception {
118                 doNothing().when(aaiNetworkResources).deleteNetwork(network);
119                 aaiDeleteTasks.deleteNetwork(execution);
120                 verify(aaiNetworkResources, times(1)).deleteNetwork(network);
121         }
122         
123         @Test 
124         public void deleteCollectionTest() throws Exception {
125                 doNothing().when(aaiNetworkResources).deleteCollection(serviceInstance.getCollection());
126                 aaiDeleteTasks.deleteCollection(execution);
127                 verify(aaiNetworkResources, times(1)).deleteCollection(serviceInstance.getCollection());
128         }
129         
130         @Test 
131         public void deleteInstanceGroupTest() throws Exception {
132                 doNothing().when(aaiNetworkResources).deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
133                 aaiDeleteTasks.deleteInstanceGroup(execution);
134                 verify(aaiNetworkResources, times(1)).deleteNetworkInstanceGroup(serviceInstance.getCollection().getInstanceGroup());
135         }
136
137         @Test
138         public void deleteVolumeGroupTest() {
139                 doNothing().when(aaiVolumeGroupResources).deleteVolumeGroup(volumeGroup, cloudRegion);
140                 
141                 aaiDeleteTasks.deleteVolumeGroup(execution);
142                 
143                 verify(aaiVolumeGroupResources, times(1)).deleteVolumeGroup(volumeGroup, cloudRegion);
144         }
145         
146         @Test
147         public void deleteVolumeGroupExceptionTest() {
148                 expectedException.expect(BpmnError.class);
149                 
150                 doThrow(Exception.class).when(aaiVolumeGroupResources).deleteVolumeGroup(volumeGroup, cloudRegion);
151                 
152                 aaiDeleteTasks.deleteVolumeGroup(execution);
153         }
154         
155         @Test
156         public void deleteConfigurationTest() throws Exception {
157                 gBBInput = execution.getGeneralBuildingBlock();
158                 doNothing().when(aaiConfigurationResources).deleteConfiguration(configuration);
159                 aaiDeleteTasks.deleteConfiguration(execution);
160                 verify(aaiConfigurationResources, times(1)).deleteConfiguration(configuration);
161         }
162 }