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.Configuration;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
41 import org.onap.so.db.catalog.beans.OrchestrationStatus;
42 import org.springframework.beans.factory.annotation.Autowired;
44 public class AAIUpdateTasksTest extends BaseTaskTest{
46 private AAIUpdateTasks aaiUpdateTasks;
48 private L3Network network;
49 private ServiceInstance serviceInstance;
50 private VfModule vfModule;
51 private GenericVnf genericVnf;
52 private VolumeGroup volumeGroup;
53 private CloudRegion cloudRegion;
54 private Configuration configuration;
57 public void before() {
58 serviceInstance = setServiceInstance();
59 genericVnf = setGenericVnf();
60 vfModule = setVfModule();
61 volumeGroup = setVolumeGroup();
62 cloudRegion = setCloudRegion();
63 network = setL3Network();
64 configuration = setConfiguration();
68 public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
69 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
71 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
73 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
77 public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
78 expectedException.expect(BpmnError.class);
80 doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
82 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
86 public void updateOrchestrationStatusActiveServiceTest() throws Exception {
87 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
89 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
91 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
95 public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
96 expectedException.expect(BpmnError.class);
98 doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
100 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
104 public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
105 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
107 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
109 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
113 public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
114 expectedException.expect(BpmnError.class);
116 doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
118 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
122 public void updateOrchestrationStatusActiveVnfTest() throws Exception {
123 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
125 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
127 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
131 public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
132 expectedException.expect(BpmnError.class);
134 doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
136 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
140 public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {
141 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
142 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
143 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
144 assertEquals("", vfModule.getHeatStackId());
148 public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
149 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
151 expectedException.expect(BpmnError.class);
153 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
157 public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {
158 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
159 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
160 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
164 public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
165 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
167 expectedException.expect(BpmnError.class);
169 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
173 public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
174 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
176 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
178 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
182 public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
183 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
185 expectedException.expect(BpmnError.class);
187 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
191 public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
192 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
194 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
196 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
200 public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
201 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
203 expectedException.expect(BpmnError.class);
205 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
209 public void updateHeatStackIdVfModuleTest() throws Exception {
210 execution.setVariable("heatStackId", "newHeatStackId");
211 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
213 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
215 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
216 assertEquals("newHeatStackId", vfModule.getHeatStackId());
220 public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
221 doThrow(Exception.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
223 expectedException.expect(BpmnError.class);
225 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
229 public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
230 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
232 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
234 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
238 public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
239 expectedException.expect(BpmnError.class);
240 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
241 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
245 public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
246 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
248 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
250 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
254 public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
255 expectedException.expect(BpmnError.class);
256 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
257 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
261 public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
262 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
264 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
266 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
267 assertEquals("", volumeGroup.getHeatStackId());
271 public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
272 expectedException.expect(BpmnError.class);
273 doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
274 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
277 public void updateHeatStackIdVolumeGroupTest() throws Exception {
278 execution.setVariable("heatStackId", "newHeatStackId");
279 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
281 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
283 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
284 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
288 public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
289 expectedException.expect(BpmnError.class);
290 doThrow(Exception.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
291 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
295 public void updateOstatusAssignedNetworkTest() throws Exception {
296 doNothing().when(aaiNetworkResources).updateNetwork(network);
298 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
300 verify(aaiNetworkResources, times(1)).updateNetwork(network);
301 assertEquals("", network.getHeatStackId());
305 public void updateOstatusAssignedNetworkExceptionTest() throws Exception {
306 expectedException.expect(BpmnError.class);
308 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
310 aaiUpdateTasks.updateOrchestrationStatusAssignedNetwork(execution);
314 public void updateOstatusActivedNetworkTest() throws Exception {
315 doNothing().when(aaiNetworkResources).updateNetwork(network);
317 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
319 verify(aaiNetworkResources, times(1)).updateNetwork(network);
323 public void updateOstatusCreatedNetworkTest() throws Exception {
324 doNothing().when(aaiNetworkResources).updateNetwork(network);
326 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
328 verify(aaiNetworkResources, times(1)).updateNetwork(network);
332 public void updateOstatusActiveNetworkExceptionTest() throws Exception {
333 expectedException.expect(BpmnError.class);
335 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
337 aaiUpdateTasks.updateOrchestrationStatusActiveNetwork(execution);
341 public void updateOstatusActivedNetworkCollectionTest() throws Exception {
342 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
343 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
344 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
348 public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
349 expectedException.expect(BpmnError.class);
350 doThrow(Exception.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
351 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
355 public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
356 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
358 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
360 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
364 public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
365 doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
367 expectedException.expect(BpmnError.class);
369 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
373 public void updateNetworkCreatedTest() throws Exception {
374 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
375 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
376 createNetworkResponse.setNetworkStackId("testNetworkStackId");
378 execution.setVariable("createNetworkResponse", createNetworkResponse);
380 doNothing().when(aaiNetworkResources).updateNetwork(network);
381 aaiUpdateTasks.updateNetworkCreated(execution);
382 verify(aaiNetworkResources, times(1)).updateNetwork(network);
384 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
385 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
386 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
387 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
391 public void updateNetworkCreatedkExceptionTest() throws Exception {
392 expectedException.expect(BpmnError.class);
393 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
394 aaiUpdateTasks.updateNetworkCreated(execution);
398 public void updateObjectNetworkTest() {
399 doNothing().when(aaiNetworkResources).updateNetwork(network);
401 aaiUpdateTasks.updateObjectNetwork(execution);
403 verify(aaiNetworkResources, times(1)).updateNetwork(network);
407 public void updateObjectNetworkExceptionText() {
408 expectedException.expect(BpmnError.class);
410 doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
412 aaiUpdateTasks.updateObjectNetwork(execution);
416 public void test_updateServiceInstance() {
417 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
418 aaiUpdateTasks.updateServiceInstance(execution);
419 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
423 public void test_updateServiceInstance_exception() {
424 expectedException.expect(BpmnError.class);
425 doThrow(Exception.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
426 aaiUpdateTasks.updateServiceInstance(execution);
430 public void updateObjectVnfTest() {
431 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
433 aaiUpdateTasks.updateObjectVnf(execution);
435 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
439 public void updateObjectVnfExceptionTest() {
440 expectedException.expect(BpmnError.class);
441 doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
442 aaiUpdateTasks.updateObjectVnf(execution);
446 public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
447 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
449 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
451 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
452 assertEquals("", vfModule.getHeatStackId());
456 public void updateModelVfModuleTest() {
457 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
458 aaiUpdateTasks.updateModelVfModule(execution);
459 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
463 public void updateModelVfModuleExceptionTest() {
464 expectedException.expect(BpmnError.class);
465 doThrow(Exception.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
466 aaiUpdateTasks.updateModelVfModule(execution);
470 public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
471 gBBInput = execution.getGeneralBuildingBlock();
472 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED);
474 aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
476 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ASSIGNED);
479 public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
480 gBBInput = execution.getGeneralBuildingBlock();
481 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE);
483 aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
485 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration, OrchestrationStatus.ACTIVE);