2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2020 Tech Mahindra
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.aai.tasks;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.ArgumentMatchers;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mockito;
31 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
32 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
33 import org.onap.so.bpmn.BaseTaskTest;
34 import org.onap.so.bpmn.common.BuildingBlockExecution;
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.Pnf;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
44 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import org.onap.so.client.exception.BBObjectNotFoundException;
46 import org.onap.so.db.catalog.beans.OrchestrationStatus;
47 import java.util.HashMap;
48 import static org.junit.Assert.assertEquals;
49 import static org.mockito.ArgumentMatchers.any;
50 import static org.mockito.ArgumentMatchers.eq;
51 import static org.mockito.Mockito.doNothing;
52 import static org.mockito.Mockito.doReturn;
53 import static org.mockito.Mockito.doThrow;
54 import static org.mockito.Mockito.mock;
55 import static org.mockito.Mockito.spy;
56 import static org.mockito.Mockito.times;
57 import static org.mockito.Mockito.verify;
58 import static org.mockito.Mockito.when;
60 public class AAIUpdateTasksTest extends BaseTaskTest {
63 private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks();
65 private L3Network network;
66 private ServiceInstance serviceInstance;
67 private VfModule vfModule;
68 private GenericVnf genericVnf;
69 private VolumeGroup volumeGroup;
70 private CloudRegion cloudRegion;
71 private Configuration configuration;
72 private Subnet subnet;
75 public void before() throws BBObjectNotFoundException {
76 serviceInstance = setServiceInstance();
77 genericVnf = setGenericVnf();
78 vfModule = setVfModule();
79 volumeGroup = setVolumeGroup();
80 cloudRegion = setCloudRegion();
81 network = setL3Network();
82 configuration = setConfiguration();
83 subnet = buildSubnet();
85 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
86 .thenReturn(genericVnf);
87 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
88 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
89 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID)))
90 .thenReturn(volumeGroup);
91 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
92 .thenReturn(serviceInstance);
93 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID)))
94 .thenReturn(configuration);
97 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
98 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
102 public void updateOrchestrationStatusAssignedServiceTest() throws Exception {
103 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
104 OrchestrationStatus.ASSIGNED);
106 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
108 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
109 OrchestrationStatus.ASSIGNED);
113 public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
114 expectedException.expect(BpmnError.class);
116 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
117 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
119 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
123 public void updateOrchestrationStatusActiveServiceTest() throws Exception {
124 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
125 OrchestrationStatus.ACTIVE);
127 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
129 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
130 OrchestrationStatus.ACTIVE);
134 public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
135 expectedException.expect(BpmnError.class);
137 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
138 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
140 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
144 public void updateOrchestrationStatusAssignedPnfTest() throws Exception {
145 Pnf pnf = preparePnfAndExtractForPnf();
146 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
148 aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
150 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
154 public void updateOrchestrationStatusAssignedPnfExceptionTest() throws Exception {
155 Pnf pnf = preparePnfAndExtractForPnf();
156 doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
157 OrchestrationStatus.ASSIGNED);
159 expectedException.expect(BpmnError.class);
160 aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
164 public void updateOrchestrationStatusInventoriedPnfTest() throws Exception {
165 Pnf pnf = preparePnfAndExtractForPnf();
166 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.INVENTORIED);
168 aaiUpdateTasks.updateOrchestrationStatusInventoriedPnf(execution);
170 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.INVENTORIED);
174 public void updateOrchestrationStatusInventoriedPnfExceptionTest() throws Exception {
175 Pnf pnf = preparePnfAndExtractForPnf();
176 doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
177 OrchestrationStatus.INVENTORIED);
179 expectedException.expect(BpmnError.class);
180 aaiUpdateTasks.updateOrchestrationStatusInventoriedPnf(execution);
184 public void updateOrchestrationStatusActivePnfTest() throws Exception {
185 Pnf pnf = preparePnfAndExtractForPnf();
186 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
188 aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
190 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
194 public void updateOrchestrationStatusActivePnfExceptionTest() throws Exception {
195 Pnf pnf = preparePnfAndExtractForPnf();
196 doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
197 OrchestrationStatus.ACTIVE);
199 expectedException.expect(BpmnError.class);
200 aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
204 public void updateOrchestrationStatusRegisterPnfTest() throws Exception {
205 Pnf pnf = preparePnfAndExtractForPnf();
206 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
208 aaiUpdateTasks.updateOrchestrationStatusRegisterPnf(execution);
210 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
214 public void updateOrchestrationStatusRegisteredPnfTest() throws Exception {
215 Pnf pnf = preparePnfAndExtractForPnf();
216 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
218 aaiUpdateTasks.updateOrchestrationStatusRegisteredPnf(execution);
220 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
224 public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
225 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
227 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
229 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
233 public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
234 expectedException.expect(BpmnError.class);
236 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
237 OrchestrationStatus.ASSIGNED);
239 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
243 public void updateOrchestrationStatusActiveVnfTest() throws Exception {
244 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
246 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
248 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
252 public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
253 expectedException.expect(BpmnError.class);
255 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
256 OrchestrationStatus.ACTIVE);
258 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
262 public void updateOrchestrationStatusAssignVfModuleTest() throws Exception {
263 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
264 OrchestrationStatus.ASSIGNED);
265 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
266 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
267 OrchestrationStatus.ASSIGNED);
268 assertEquals("", vfModule.getHeatStackId());
272 public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
273 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
274 genericVnf, OrchestrationStatus.ASSIGNED);
276 expectedException.expect(BpmnError.class);
278 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
282 public void updateOrchestrationStatusCreatedVfModuleTest() throws Exception {
283 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
284 OrchestrationStatus.CREATED);
285 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
286 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
287 OrchestrationStatus.CREATED);
291 public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
292 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
293 genericVnf, OrchestrationStatus.CREATED);
295 expectedException.expect(BpmnError.class);
297 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
301 public void updateOrchestrationStatusPendingActivatefModuleTest() throws Exception {
302 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
303 OrchestrationStatus.PENDING_ACTIVATION);
305 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
307 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
308 OrchestrationStatus.PENDING_ACTIVATION);
312 public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
313 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
314 genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
316 expectedException.expect(BpmnError.class);
318 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
322 public void updateOrchestrationStatusDectivateVfModuleTest() throws Exception {
323 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
324 OrchestrationStatus.CREATED);
326 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
328 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
329 OrchestrationStatus.CREATED);
333 public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
334 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
335 genericVnf, OrchestrationStatus.CREATED);
337 expectedException.expect(BpmnError.class);
339 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
343 public void updateHeatStackIdVfModuleTest() throws Exception {
344 execution.setVariable("heatStackId", "newHeatStackId");
345 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
347 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
349 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
350 assertEquals("newHeatStackId", vfModule.getHeatStackId());
354 public void updateHeatStackIdVfModuleToNullTest() throws Exception {
355 execution.setVariable("heatStackId", null);
356 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
358 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
360 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
361 assertEquals(vfModule.getHeatStackId(), "");
365 public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
366 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
368 expectedException.expect(BpmnError.class);
370 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
374 public void updateOrchestrationStatusActiveVolumeGroupTest() throws Exception {
375 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
376 OrchestrationStatus.ACTIVE);
378 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
380 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
381 OrchestrationStatus.ACTIVE);
385 public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
386 expectedException.expect(BpmnError.class);
387 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
388 cloudRegion, OrchestrationStatus.ACTIVE);
389 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
393 public void updateOrchestrationStatusCreatedVolumeGroupTest() throws Exception {
394 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
395 OrchestrationStatus.CREATED);
397 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
399 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
400 OrchestrationStatus.CREATED);
404 public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
405 expectedException.expect(BpmnError.class);
406 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
407 cloudRegion, OrchestrationStatus.CREATED);
408 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
412 public void test_updateOrchestrationStatusAssignedVolumeGroup() throws Exception {
413 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
414 OrchestrationStatus.ASSIGNED);
416 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
418 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
419 OrchestrationStatus.ASSIGNED);
420 assertEquals("", volumeGroup.getHeatStackId());
424 public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
425 expectedException.expect(BpmnError.class);
426 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
427 cloudRegion, OrchestrationStatus.ASSIGNED);
428 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
432 public void updateHeatStackIdVolumeGroupTest() throws Exception {
433 execution.setVariable("heatStackId", "newHeatStackId");
434 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
436 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
438 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
439 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
443 public void updateHeatStackIdVolumeGroupToNullTest() throws Exception {
444 execution.setVariable("heatStackId", null);
445 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
447 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
449 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
450 assertEquals(volumeGroup.getHeatStackId(), "");
454 public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
455 expectedException.expect(BpmnError.class);
456 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup,
458 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
462 public void updateNetworkExceptionTest() throws Exception {
463 expectedException.expect(BpmnError.class);
465 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
467 aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
471 public void updateOstatusActivedNetworkCollectionTest() throws Exception {
472 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
473 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
474 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
478 public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
479 expectedException.expect(BpmnError.class);
480 doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
481 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
485 public void updateOrchestrationStatusActivateVfModuleTest() throws Exception {
486 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
487 OrchestrationStatus.ACTIVE);
489 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
491 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
492 OrchestrationStatus.ACTIVE);
496 public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
497 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
498 genericVnf, OrchestrationStatus.ACTIVE);
500 expectedException.expect(BpmnError.class);
502 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
506 public void updateNetworkCreatedTest() throws Exception {
507 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
508 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
509 createNetworkResponse.setNetworkStackId("testNetworkStackId");
510 HashMap<String, String> subnetMap = new HashMap<>();
511 subnetMap.put("testSubnetId", "testNeutronSubnetId");
512 createNetworkResponse.setSubnetMap(subnetMap);
514 network.getSubnets().add(subnet);
516 execution.setVariable("createNetworkResponse", createNetworkResponse);
518 doNothing().when(aaiNetworkResources).updateNetwork(network);
519 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
521 aaiUpdateTasks.updateNetworkCreated(execution);
522 verify(aaiNetworkResources, times(1)).updateNetwork(network);
523 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
525 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
526 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
527 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
528 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
529 String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
530 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
534 public void updateNetworkUpdatedTest() throws Exception {
535 UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse();
536 updateNetworkResponse.setNeutronNetworkId("testNeutronNetworkId");
537 HashMap<String, String> subnetMap = new HashMap<>();
538 subnetMap.put("testSubnetId", "testNeutronSubnetId");
539 updateNetworkResponse.setSubnetMap(subnetMap);
541 network.getSubnets().add(subnet);
543 execution.setVariable("updateNetworkResponse", updateNetworkResponse);
545 doNothing().when(aaiNetworkResources).updateNetwork(network);
546 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
548 aaiUpdateTasks.updateNetworkUpdated(execution);
549 verify(aaiNetworkResources, times(1)).updateNetwork(network);
550 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
552 String neutronSubnetId = updateNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
553 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
557 public void updateOrchestrationStatusNetworkTest() {
558 AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
559 doNothing().when(spy).updateNetwork(eq(execution), any());
560 spy.updateOrchestrationStatusActiveNetwork(execution);
561 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
562 spy.updateOrchestrationStatusAssignedNetwork(execution);
563 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
564 spy.updateOrchestrationStatusCreatedNetwork(execution);
565 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
569 public void updateNetworkAAITest() {
571 L3Network spy = spy(new L3Network());
572 L3Network shallowCopy = mock(L3Network.class);
573 Subnet mockSubnet = mock(Subnet.class);
574 Subnet shallowCopySubnet = mock(Subnet.class);
575 when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
576 doReturn(shallowCopy).when(spy).shallowCopyId();
578 doNothing().when(aaiNetworkResources).updateNetwork(network);
579 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
581 spy.getSubnets().add(mockSubnet);
582 aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
584 verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
585 verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
586 verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
590 public void updateNetworkCreatedkExceptionTest() throws Exception {
591 expectedException.expect(BpmnError.class);
592 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
593 aaiUpdateTasks.updateNetworkCreated(execution);
597 public void updateObjectNetworkTest() {
598 doNothing().when(aaiNetworkResources).updateNetwork(network);
600 aaiUpdateTasks.updateObjectNetwork(execution);
602 verify(aaiNetworkResources, times(1)).updateNetwork(network);
606 public void updateObjectNetworkExceptionText() {
607 expectedException.expect(BpmnError.class);
609 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
611 aaiUpdateTasks.updateObjectNetwork(execution);
615 public void test_updateServiceInstance() {
616 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
617 aaiUpdateTasks.updateServiceInstance(execution);
618 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
622 public void test_updateServiceInstance_exception() {
623 expectedException.expect(BpmnError.class);
624 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
625 aaiUpdateTasks.updateServiceInstance(execution);
629 public void updateObjectVnfTest() {
630 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
632 aaiUpdateTasks.updateObjectVnf(execution);
634 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
638 public void updateObjectVnfExceptionTest() {
639 expectedException.expect(BpmnError.class);
640 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
641 aaiUpdateTasks.updateObjectVnf(execution);
645 public void updateOrchestrationStatusDeleteVfModuleTest() throws Exception {
646 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
647 OrchestrationStatus.ASSIGNED);
649 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
651 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
652 OrchestrationStatus.ASSIGNED);
653 assertEquals("", vfModule.getHeatStackId());
657 public void updateModelVfModuleTest() {
658 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
659 aaiUpdateTasks.updateModelVfModule(execution);
660 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
664 public void updateModelVfModuleExceptionTest() {
665 expectedException.expect(BpmnError.class);
666 doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
667 aaiUpdateTasks.updateModelVfModule(execution);
671 public void updateOrchestrationStatusDeactivateFabricConfigurationTest() throws Exception {
672 gBBInput = execution.getGeneralBuildingBlock();
673 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
674 OrchestrationStatus.ASSIGNED);
676 aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
678 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
679 OrchestrationStatus.ASSIGNED);
683 public void updateOrchestrationStatusActivateFabricConfigurationTest() throws Exception {
684 gBBInput = execution.getGeneralBuildingBlock();
685 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
686 OrchestrationStatus.ACTIVE);
688 aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
690 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
691 OrchestrationStatus.ACTIVE);
695 public void updateOrchestrationStatusAssignedFabricConfigurationTest() throws Exception {
696 gBBInput = execution.getGeneralBuildingBlock();
697 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
698 OrchestrationStatus.ASSIGNED);
700 aaiUpdateTasks.updateOrchestrationStatusAssignFabricConfiguration(execution);
702 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
703 OrchestrationStatus.ASSIGNED);
707 public void updateContrailServiceInstanceFqdnVfModuleTest() throws Exception {
708 execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn");
709 doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
711 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
713 verify(aaiVfModuleResources, times(1)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
714 assertEquals("newContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn());
718 public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() throws Exception {
719 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
720 verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
724 public void updateIpv4OamAddressVnfTest() throws Exception {
725 execution.setVariable("oamManagementV4Address", "newIpv4OamAddress");
726 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
728 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
730 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
731 assertEquals("newIpv4OamAddress", genericVnf.getIpv4OamAddress());
735 public void updateIpv4OamAddressVnfNoUpdateTest() throws Exception {
736 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
737 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
741 public void updateManagementV6AddressVnfTest() throws Exception {
742 execution.setVariable("oamManagementV6Address", "newManagementV6Address");
743 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
745 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
747 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
748 assertEquals("newManagementV6Address", genericVnf.getManagementV6Address());
752 public void updateManagementV6AddressVnfNoUpdateTest() throws Exception {
753 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
754 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
758 public void updateOrchestrationStatusVnfConfigureTest() throws Exception {
759 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
760 OrchestrationStatus.CONFIGURE);
762 aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfigureVnf(execution);
766 public void updateOrchestrationStatusVnfConfiguredTest() throws Exception {
767 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
768 OrchestrationStatus.CONFIGURED);
770 aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfiguredVnf(execution);
773 private Pnf preparePnfAndExtractForPnf() throws BBObjectNotFoundException {
774 Pnf pnf = buildPnf();
775 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf);
780 public void updateOrchestrationStatusVnfConfigAssignedTest() throws Exception {
781 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGASSIGNED);
783 aaiUpdateTasks.updateOrchestrationStatus(execution, "vnf", "config-assign");
785 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGASSIGNED);
789 public void updateOrchestrationStatusVnfConfigDeployedTest() throws Exception {
790 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGDEPLOYED);
792 aaiUpdateTasks.updateOrchestrationStatus(execution, "vnf", "config-deploy");
794 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGDEPLOYED);
798 public void updateOrchestrationStatusVfModuleConfigDeployedTest() throws Exception {
799 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
800 OrchestrationStatus.CONFIGDEPLOYED);
801 aaiUpdateTasks.updateOrchestrationStatus(execution, "vfmodule", "config-deploy");
802 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
803 OrchestrationStatus.CONFIGDEPLOYED);
807 public void updateOrchestrationStatusVfModuleConfigAssignedTest() throws Exception {
808 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
809 OrchestrationStatus.CONFIGASSIGNED);
810 aaiUpdateTasks.updateOrchestrationStatus(execution, "vfmodule", "config-assign");
811 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
812 OrchestrationStatus.CONFIGASSIGNED);