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 org.camunda.bpm.engine.delegate.BpmnError;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.ArgumentMatchers;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mockito;
29 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
30 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
31 import org.onap.so.bpmn.BaseTaskTest;
32 import org.onap.so.bpmn.common.BuildingBlockExecution;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
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.Pnf;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
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.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
44 import org.onap.so.client.exception.BBObjectNotFoundException;
45 import org.onap.so.db.catalog.beans.OrchestrationStatus;
46 import java.util.HashMap;
47 import static org.junit.Assert.assertEquals;
48 import static org.mockito.ArgumentMatchers.any;
49 import static org.mockito.ArgumentMatchers.eq;
50 import static org.mockito.Mockito.doNothing;
51 import static org.mockito.Mockito.doReturn;
52 import static org.mockito.Mockito.doThrow;
53 import static org.mockito.Mockito.mock;
54 import static org.mockito.Mockito.spy;
55 import static org.mockito.Mockito.times;
56 import static org.mockito.Mockito.verify;
57 import static org.mockito.Mockito.when;
59 public class AAIUpdateTasksTest extends BaseTaskTest {
62 private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks();
64 private L3Network network;
65 private ServiceInstance serviceInstance;
66 private VfModule vfModule;
67 private GenericVnf genericVnf;
68 private VolumeGroup volumeGroup;
69 private CloudRegion cloudRegion;
70 private Configuration configuration;
71 private Subnet subnet;
74 public void before() throws BBObjectNotFoundException {
75 serviceInstance = setServiceInstance();
76 genericVnf = setGenericVnf();
77 vfModule = setVfModule();
78 volumeGroup = setVolumeGroup();
79 cloudRegion = setCloudRegion();
80 network = setL3Network();
81 configuration = setConfiguration();
82 subnet = buildSubnet();
84 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
85 .thenReturn(genericVnf);
86 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
87 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
88 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID)))
89 .thenReturn(volumeGroup);
90 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
91 .thenReturn(serviceInstance);
92 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID)))
93 .thenReturn(configuration);
96 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
97 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
101 public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
102 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
103 OrchestrationStatus.ASSIGNED);
105 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
107 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
108 OrchestrationStatus.ASSIGNED);
112 public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
113 expectedException.expect(BpmnError.class);
115 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
116 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
118 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
122 public void updateOrchestrationStatusActiveServiceTest() throws Exception {
123 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
124 OrchestrationStatus.ACTIVE);
126 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
128 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
129 OrchestrationStatus.ACTIVE);
133 public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
134 expectedException.expect(BpmnError.class);
136 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
137 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
139 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
143 public void updateOrchestrationStatusAssignedPnfTest() throws Exception {
144 Pnf pnf = preparePnfAndExtractForPnf();
145 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
147 aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
149 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
153 public void updateOrchestrationStatusAssignedPnfExceptionTest() throws Exception {
154 Pnf pnf = preparePnfAndExtractForPnf();
155 doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
156 OrchestrationStatus.ASSIGNED);
158 expectedException.expect(BpmnError.class);
159 aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
163 public void updateOrchestrationStatusActivePnfTest() throws Exception {
164 Pnf pnf = preparePnfAndExtractForPnf();
165 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
167 aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
169 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
173 public void updateOrchestrationStatusActivePnfExceptionTest() throws Exception {
174 Pnf pnf = preparePnfAndExtractForPnf();
175 doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
176 OrchestrationStatus.ACTIVE);
178 expectedException.expect(BpmnError.class);
179 aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
183 public void updateOrchestrationStatusRegisterPnfTest() throws Exception {
184 Pnf pnf = preparePnfAndExtractForPnf();
185 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
187 aaiUpdateTasks.updateOrchestrationStatusRegisterPnf(execution);
189 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
193 public void updateOrchestrationStatusRegisteredPnfTest() throws Exception {
194 Pnf pnf = preparePnfAndExtractForPnf();
195 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
197 aaiUpdateTasks.updateOrchestrationStatusRegisteredPnf(execution);
199 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
203 public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
204 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
206 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
208 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
212 public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
213 expectedException.expect(BpmnError.class);
215 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
216 OrchestrationStatus.ASSIGNED);
218 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
222 public void updateOrchestrationStatusActiveVnfTest() throws Exception {
223 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
225 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
227 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
231 public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
232 expectedException.expect(BpmnError.class);
234 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
235 OrchestrationStatus.ACTIVE);
237 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
241 public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {
242 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
243 OrchestrationStatus.ASSIGNED);
244 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
245 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
246 OrchestrationStatus.ASSIGNED);
247 assertEquals("", vfModule.getHeatStackId());
251 public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
252 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
253 genericVnf, OrchestrationStatus.ASSIGNED);
255 expectedException.expect(BpmnError.class);
257 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
261 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleNoMultiStageTest() throws Exception {
262 execution.setVariable("aLaCarte", true);
263 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
264 modelInfoGenericVnf.setMultiStageDesign("false");
265 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
266 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
267 OrchestrationStatus.ASSIGNED);
268 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
269 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
270 OrchestrationStatus.ASSIGNED);
271 assertEquals("", vfModule.getHeatStackId());
275 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleMultiStageButNotAlacarteTest()
277 execution.setVariable("aLaCarte", false);
278 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
279 modelInfoGenericVnf.setMultiStageDesign("true");
280 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
281 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
282 OrchestrationStatus.ASSIGNED);
283 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
284 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
285 OrchestrationStatus.ASSIGNED);
286 assertEquals("", vfModule.getHeatStackId());
290 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleWithMultiStageTest() throws Exception {
291 execution.setVariable("aLaCarte", true);
292 ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf();
293 modelInfoGenericVnf.setMultiStageDesign("true");
294 genericVnf.setModelInfoGenericVnf(modelInfoGenericVnf);
295 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
296 OrchestrationStatus.PENDING_ACTIVATION);
297 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
298 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
299 OrchestrationStatus.PENDING_ACTIVATION);
300 assertEquals("", vfModule.getHeatStackId());
304 public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception {
305 execution.setVariable("aLaCarte", true);
306 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
307 genericVnf, OrchestrationStatus.ASSIGNED);
309 expectedException.expect(BpmnError.class);
311 aaiUpdateTasks.updateOrchestrationStatusAssignedOrPendingActivationVfModule(execution);
315 public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {
316 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
317 OrchestrationStatus.CREATED);
318 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
319 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
320 OrchestrationStatus.CREATED);
324 public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
325 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
326 genericVnf, OrchestrationStatus.CREATED);
328 expectedException.expect(BpmnError.class);
330 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
334 public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
335 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
336 OrchestrationStatus.PENDING_ACTIVATION);
338 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
340 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
341 OrchestrationStatus.PENDING_ACTIVATION);
345 public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
346 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
347 genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
349 expectedException.expect(BpmnError.class);
351 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
355 public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
356 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
357 OrchestrationStatus.CREATED);
359 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
361 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
362 OrchestrationStatus.CREATED);
366 public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
367 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
368 genericVnf, OrchestrationStatus.CREATED);
370 expectedException.expect(BpmnError.class);
372 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
376 public void updateHeatStackIdVfModuleTest() throws Exception {
377 execution.setVariable("heatStackId", "newHeatStackId");
378 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
380 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
382 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
383 assertEquals("newHeatStackId", vfModule.getHeatStackId());
387 public void updateHeatStackIdVfModuleToNullTest() throws Exception {
388 execution.setVariable("heatStackId", null);
389 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
391 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
393 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
394 assertEquals(vfModule.getHeatStackId(), "");
398 public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
399 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
401 expectedException.expect(BpmnError.class);
403 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
407 public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
408 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
409 OrchestrationStatus.ACTIVE);
411 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
413 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
414 OrchestrationStatus.ACTIVE);
418 public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
419 expectedException.expect(BpmnError.class);
420 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
421 cloudRegion, OrchestrationStatus.ACTIVE);
422 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
426 public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
427 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
428 OrchestrationStatus.CREATED);
430 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
432 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
433 OrchestrationStatus.CREATED);
437 public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
438 expectedException.expect(BpmnError.class);
439 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
440 cloudRegion, OrchestrationStatus.CREATED);
441 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
445 public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
446 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
447 OrchestrationStatus.ASSIGNED);
449 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
451 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
452 OrchestrationStatus.ASSIGNED);
453 assertEquals("", volumeGroup.getHeatStackId());
457 public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
458 expectedException.expect(BpmnError.class);
459 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
460 cloudRegion, OrchestrationStatus.ASSIGNED);
461 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
465 public void updateHeatStackIdVolumeGroupTest() throws Exception {
466 execution.setVariable("heatStackId", "newHeatStackId");
467 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
469 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
471 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
472 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
476 public void updateHeatStackIdVolumeGroupToNullTest() throws Exception {
477 execution.setVariable("heatStackId", null);
478 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
480 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
482 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
483 assertEquals(volumeGroup.getHeatStackId(), "");
487 public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
488 expectedException.expect(BpmnError.class);
489 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup,
491 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
495 public void updateNetworkExceptionTest() throws Exception {
496 expectedException.expect(BpmnError.class);
498 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
500 aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
504 public void updateOstatusActivedNetworkCollectionTest() throws Exception {
505 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
506 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
507 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
511 public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
512 expectedException.expect(BpmnError.class);
513 doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
514 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
518 public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
519 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
520 OrchestrationStatus.ACTIVE);
522 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
524 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
525 OrchestrationStatus.ACTIVE);
529 public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
530 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
531 genericVnf, OrchestrationStatus.ACTIVE);
533 expectedException.expect(BpmnError.class);
535 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
539 public void updateNetworkCreatedTest() throws Exception {
540 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
541 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
542 createNetworkResponse.setNetworkStackId("testNetworkStackId");
543 HashMap<String, String> subnetMap = new HashMap<>();
544 subnetMap.put("testSubnetId", "testNeutronSubnetId");
545 createNetworkResponse.setSubnetMap(subnetMap);
547 network.getSubnets().add(subnet);
549 execution.setVariable("createNetworkResponse", createNetworkResponse);
551 doNothing().when(aaiNetworkResources).updateNetwork(network);
552 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
554 aaiUpdateTasks.updateNetworkCreated(execution);
555 verify(aaiNetworkResources, times(1)).updateNetwork(network);
556 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
558 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
559 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
560 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
561 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
562 String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
563 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
567 public void updateNetworkUpdatedTest() throws Exception {
568 UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse();
569 updateNetworkResponse.setNeutronNetworkId("testNeutronNetworkId");
570 HashMap<String, String> subnetMap = new HashMap<>();
571 subnetMap.put("testSubnetId", "testNeutronSubnetId");
572 updateNetworkResponse.setSubnetMap(subnetMap);
574 network.getSubnets().add(subnet);
576 execution.setVariable("updateNetworkResponse", updateNetworkResponse);
578 doNothing().when(aaiNetworkResources).updateNetwork(network);
579 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
581 aaiUpdateTasks.updateNetworkUpdated(execution);
582 verify(aaiNetworkResources, times(1)).updateNetwork(network);
583 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
585 String neutronSubnetId = updateNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
586 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
590 public void updateOrchestrationStatusNetworkTest() {
591 AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
592 doNothing().when(spy).updateNetwork(eq(execution), any());
593 spy.updateOrchestrationStatusActiveNetwork(execution);
594 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
595 spy.updateOrchestrationStatusAssignedNetwork(execution);
596 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
597 spy.updateOrchestrationStatusCreatedNetwork(execution);
598 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
602 public void updateNetworkAAITest() {
604 L3Network spy = spy(new L3Network());
605 L3Network shallowCopy = mock(L3Network.class);
606 Subnet mockSubnet = mock(Subnet.class);
607 Subnet shallowCopySubnet = mock(Subnet.class);
608 when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
609 doReturn(shallowCopy).when(spy).shallowCopyId();
611 doNothing().when(aaiNetworkResources).updateNetwork(network);
612 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
614 spy.getSubnets().add(mockSubnet);
615 aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
617 verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
618 verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
619 verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
623 public void updateNetworkCreatedkExceptionTest() throws Exception {
624 expectedException.expect(BpmnError.class);
625 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
626 aaiUpdateTasks.updateNetworkCreated(execution);
630 public void updateObjectNetworkTest() {
631 doNothing().when(aaiNetworkResources).updateNetwork(network);
633 aaiUpdateTasks.updateObjectNetwork(execution);
635 verify(aaiNetworkResources, times(1)).updateNetwork(network);
639 public void updateObjectNetworkExceptionText() {
640 expectedException.expect(BpmnError.class);
642 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
644 aaiUpdateTasks.updateObjectNetwork(execution);
648 public void test_updateServiceInstance() {
649 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
650 aaiUpdateTasks.updateServiceInstance(execution);
651 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
655 public void test_updateServiceInstance_exception() {
656 expectedException.expect(BpmnError.class);
657 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
658 aaiUpdateTasks.updateServiceInstance(execution);
662 public void updateObjectVnfTest() {
663 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
665 aaiUpdateTasks.updateObjectVnf(execution);
667 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
671 public void updateObjectVnfExceptionTest() {
672 expectedException.expect(BpmnError.class);
673 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
674 aaiUpdateTasks.updateObjectVnf(execution);
678 public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
679 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
680 OrchestrationStatus.ASSIGNED);
682 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
684 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
685 OrchestrationStatus.ASSIGNED);
686 assertEquals("", vfModule.getHeatStackId());
690 public void updateModelVfModuleTest() {
691 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
692 aaiUpdateTasks.updateModelVfModule(execution);
693 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
697 public void updateModelVfModuleExceptionTest() {
698 expectedException.expect(BpmnError.class);
699 doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
700 aaiUpdateTasks.updateModelVfModule(execution);
704 public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
705 gBBInput = execution.getGeneralBuildingBlock();
706 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
707 OrchestrationStatus.ASSIGNED);
709 aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
711 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
712 OrchestrationStatus.ASSIGNED);
716 public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
717 gBBInput = execution.getGeneralBuildingBlock();
718 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
719 OrchestrationStatus.ACTIVE);
721 aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
723 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
724 OrchestrationStatus.ACTIVE);
728 public void updateOrchestrationStatusAssignedFabricConfigurationTest() throws Exception {
729 gBBInput = execution.getGeneralBuildingBlock();
730 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
731 OrchestrationStatus.ASSIGNED);
733 aaiUpdateTasks.updateOrchestrationStatusAssignFabricConfiguration(execution);
735 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
736 OrchestrationStatus.ASSIGNED);
740 public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception {
741 execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn");
742 doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
744 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
746 verify(aaiVfModuleResources, times(1)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
747 assertEquals("newContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn());
751 public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() throws Exception {
752 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
753 verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
757 public void updateIpv4OamAddressVnfTest() throws Exception {
758 execution.setVariable("oamManagementV4Address", "newIpv4OamAddress");
759 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
761 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
763 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
764 assertEquals("newIpv4OamAddress", genericVnf.getIpv4OamAddress());
768 public void updateIpv4OamAddressVnfNoUpdateTest() throws Exception {
769 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
770 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
774 public void updateManagementV6AddressVnfTest() throws Exception {
775 execution.setVariable("oamManagementV6Address", "newManagementV6Address");
776 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
778 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
780 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
781 assertEquals("newManagementV6Address", genericVnf.getManagementV6Address());
785 public void updateManagementV6AddressVnfNoUpdateTest() throws Exception {
786 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
787 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
791 public void updateOrchestrationStatusVnfConfigureTest() throws Exception {
792 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
793 OrchestrationStatus.CONFIGURE);
795 aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfigureVnf(execution);
799 public void updateOrchestrationStatusVnfConfiguredTest() throws Exception {
800 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
801 OrchestrationStatus.CONFIGURED);
803 aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfiguredVnf(execution);
806 private Pnf preparePnfAndExtractForPnf() throws BBObjectNotFoundException {
807 Pnf pnf = buildPnf();
808 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf);