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.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.doNothing;
25 import static org.mockito.Mockito.doThrow;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
33 import org.onap.so.bpmn.BaseTaskTest;
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.L3Network;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
40 import org.onap.so.db.catalog.beans.OrchestrationStatus;
41 import org.springframework.beans.factory.annotation.Autowired;
43 public class AAIUpdateTasksTest extends BaseTaskTest{
45 private AAIUpdateTasks aaiUpdateTasks;
47 private L3Network network;
48 private ServiceInstance serviceInstance;
49 private VfModule vfModule;
50 private GenericVnf genericVnf;
51 private VolumeGroup volumeGroup;
52 private CloudRegion cloudRegion;
55 public void before() {
56 serviceInstance = setServiceInstance();
57 genericVnf = setGenericVnf();
58 vfModule = setVfModule();
59 volumeGroup = setVolumeGroup();
60 cloudRegion = setCloudRegion();
61 network = setL3Network();
65 public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
66 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
68 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
70 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
74 public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
75 expectedException.expect(BpmnError.class);
77 doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
79 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
83 public void updateOrchestrationStatusActiveServiceTest() throws Exception {
84 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
86 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
88 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
92 public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
93 expectedException.expect(BpmnError.class);
95 doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
97 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
101 public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
102 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
104 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
106 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
110 public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
111 expectedException.expect(BpmnError.class);
113 doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
115 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
119 public void updateOrchestrationStatusActiveVnfTest() throws Exception {
120 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
122 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
124 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
128 public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
129 expectedException.expect(BpmnError.class);
131 doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
133 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
137 public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {
138 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
139 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
140 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
141 assertEquals("", vfModule.getHeatStackId());
145 public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
146 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
148 expectedException.expect(BpmnError.class);
150 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
154 public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {
155 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
156 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
157 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
161 public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
162 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
164 expectedException.expect(BpmnError.class);
166 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
170 public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
171 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
173 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
175 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
179 public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
180 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
182 expectedException.expect(BpmnError.class);
184 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
188 public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
189 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
191 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
193 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
197 public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
198 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
200 expectedException.expect(BpmnError.class);
202 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
206 public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
207 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
209 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
211 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
215 public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
216 expectedException.expect(BpmnError.class);
217 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
218 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
222 public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
223 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
225 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
227 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
231 public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
232 expectedException.expect(BpmnError.class);
233 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
234 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
238 public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
239 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
241 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
243 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
244 assertEquals("", volumeGroup.getHeatStackId());
248 public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
249 expectedException.expect(BpmnError.class);
250 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
251 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
254 public void updateOstatusAssignedNetworkTest() throws Exception {
255 doNothing().when(aaiNetworkResources).updateNetwork(network);
257 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
259 verify(aaiNetworkResources, times(1)).updateNetwork(network);
260 assertEquals("", network.getHeatStackId());
264 public void updateOstatusAssignedNetworkExceptionTest() throws Exception {
265 expectedException.expect(BpmnError.class);
267 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
269 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
273 public void updateOstatusActivedNetworkTest() throws Exception {
274 doNothing().when(aaiNetworkResources).updateNetwork(network);
276 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
278 verify(aaiNetworkResources, times(1)).updateNetwork(network);
282 public void updateOstatusCreatedNetworkTest() throws Exception {
283 doNothing().when(aaiNetworkResources).updateNetwork(network);
285 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
287 verify(aaiNetworkResources, times(1)).updateNetwork(network);
291 public void updateOstatusActiveNetworkExceptionTest() throws Exception {
292 expectedException.expect(BpmnError.class);
294 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
296 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
300 public void updateOstatusActivedNetworkCollectionTest() throws Exception {
301 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
302 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
303 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
307 public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
308 expectedException.expect(BpmnError.class);
309 doThrow(Exception.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
310 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
314 public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
315 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
317 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
319 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
323 public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
324 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
326 expectedException.expect(BpmnError.class);
328 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
332 public void updateNetworkCreatedTest() throws Exception {
333 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
334 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
335 createNetworkResponse.setNetworkStackId("testNetworkStackId");
337 execution.setVariable("createNetworkResponse", createNetworkResponse);
339 doNothing().when(aaiNetworkResources).updateNetwork(network);
340 aaiUpdateTasks.updateNetworkCreated(execution);
341 verify(aaiNetworkResources, times(1)).updateNetwork(network);
343 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
344 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
345 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
346 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
350 public void updateNetworkCreatedkExceptionTest() throws Exception {
351 expectedException.expect(BpmnError.class);
352 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
353 aaiUpdateTasks.updateNetworkCreated(execution);
357 public void updateObjectNetworkTest() {
358 doNothing().when(aaiNetworkResources).updateNetwork(network);
360 aaiUpdateTasks.updateObjectNetwork(execution);
362 verify(aaiNetworkResources, times(1)).updateNetwork(network);
366 public void updateObjectNetworkExceptionText() {
367 expectedException.expect(BpmnError.class);
369 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
371 aaiUpdateTasks.updateObjectNetwork(execution);
375 public void test_updateServiceInstance() {
376 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
377 aaiUpdateTasks.updateServiceInstance(execution);
378 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
382 public void test_updateServiceInstance_exception() {
383 expectedException.expect(BpmnError.class);
384 doThrow(Exception.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
385 aaiUpdateTasks.updateServiceInstance(execution);
389 public void updateObjectVnfTest() {
390 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
392 aaiUpdateTasks.updateObjectVnf(execution);
394 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
398 public void updateObjectVnfExceptionTest() {
399 expectedException.expect(BpmnError.class);
400 doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
401 aaiUpdateTasks.updateObjectVnf(execution);
405 public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
406 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
408 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
410 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
411 assertEquals("", vfModule.getHeatStackId());
415 public void updateModelVfModuleTest() {
416 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
417 aaiUpdateTasks.updateModelVfModule(execution);
418 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
422 public void updateModelVfModuleExceptionTest() {
423 expectedException.expect(BpmnError.class);
424 doThrow(Exception.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
425 aaiUpdateTasks.updateModelVfModule(execution);