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.junit.runner.RunWith;
29 import org.mockito.ArgumentMatchers;
30 import org.mockito.InjectMocks;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
35 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
36 import org.onap.so.bpmn.common.BuildingBlockExecution;
37 import org.onap.so.bpmn.common.data.TestDataSetup;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
47 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
48 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
49 import org.onap.so.client.exception.BBObjectNotFoundException;
50 import org.onap.so.client.exception.ExceptionBuilder;
51 import org.onap.so.client.orchestration.AAICollectionResources;
52 import org.onap.so.client.orchestration.AAIConfigurationResources;
53 import org.onap.so.client.orchestration.AAINetworkResources;
54 import org.onap.so.client.orchestration.AAIPnfResources;
55 import org.onap.so.client.orchestration.AAIServiceInstanceResources;
56 import org.onap.so.client.orchestration.AAIVfModuleResources;
57 import org.onap.so.client.orchestration.AAIVnfResources;
58 import org.onap.so.client.orchestration.AAIVolumeGroupResources;
59 import org.onap.so.db.catalog.beans.OrchestrationStatus;
60 import java.util.HashMap;
61 import static org.junit.Assert.assertEquals;
62 import static org.mockito.ArgumentMatchers.any;
63 import static org.mockito.ArgumentMatchers.eq;
64 import static org.mockito.Mockito.doNothing;
65 import static org.mockito.Mockito.doReturn;
66 import static org.mockito.Mockito.doThrow;
67 import static org.mockito.Mockito.mock;
68 import static org.mockito.Mockito.spy;
69 import static org.mockito.Mockito.times;
70 import static org.mockito.Mockito.verify;
71 import static org.mockito.Mockito.when;
73 @RunWith(MockitoJUnitRunner.Silent.class)
74 public class AAIUpdateTasksTest extends TestDataSetup {
77 protected ExtractPojosForBB extractPojosForBB;
79 protected ExceptionBuilder exceptionUtil;
81 protected AAIServiceInstanceResources aaiServiceInstanceResources;
83 protected AAIPnfResources aaiPnfResources;
85 protected AAIVnfResources aaiVnfResources;
87 protected AAIVfModuleResources aaiVfModuleResources;
89 protected AAIVolumeGroupResources aaiVolumeGroupResources;
91 protected AAINetworkResources aaiNetworkResources;
93 protected AAICollectionResources aaiCollectionResources;
95 protected AAIConfigurationResources aaiConfigurationResources;
97 private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks();
99 private L3Network network;
100 private ServiceInstance serviceInstance;
101 private VfModule vfModule;
102 private GenericVnf genericVnf;
103 private VolumeGroup volumeGroup;
104 private CloudRegion cloudRegion;
105 private Configuration configuration;
106 private Subnet subnet;
109 public void before() throws BBObjectNotFoundException {
110 serviceInstance = setServiceInstance();
111 genericVnf = setGenericVnf();
112 vfModule = setVfModule();
113 volumeGroup = setVolumeGroup();
114 cloudRegion = setCloudRegion();
115 network = setL3Network();
116 configuration = setConfiguration();
117 subnet = buildSubnet();
119 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
120 .thenReturn(genericVnf);
121 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
122 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
123 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID)))
124 .thenReturn(volumeGroup);
125 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
126 .thenReturn(serviceInstance);
127 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID)))
128 .thenReturn(configuration);
131 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
132 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
136 public void updateOrchestrationStatusAssignedServiceTest() {
137 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
138 OrchestrationStatus.ASSIGNED);
140 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
142 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
143 OrchestrationStatus.ASSIGNED);
147 public void updateOrchestrationStatusAssignedServiceExceptionTest() {
148 expectedException.expect(BpmnError.class);
150 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
151 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
153 aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
157 public void updateOrchestrationStatusActiveServiceTest() {
158 doNothing().when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance,
159 OrchestrationStatus.ACTIVE);
161 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
163 verify(aaiServiceInstanceResources, times(1)).updateOrchestrationStatusServiceInstance(serviceInstance,
164 OrchestrationStatus.ACTIVE);
168 public void updateOrchestrationStatusActiveServiceExceptionTest() {
169 expectedException.expect(BpmnError.class);
171 doThrow(RuntimeException.class).when(aaiServiceInstanceResources)
172 .updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
174 aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
178 public void updateOrchestrationStatusAssignedPnfTest() throws Exception {
179 Pnf pnf = preparePnfAndExtractForPnf();
180 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
182 aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
184 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
188 public void updateOrchestrationStatusAssignedPnfExceptionTest() throws Exception {
189 Pnf pnf = preparePnfAndExtractForPnf();
190 doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
191 OrchestrationStatus.ASSIGNED);
193 expectedException.expect(BpmnError.class);
194 aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
198 public void updateOrchestrationStatusInventoriedPnfTest() throws Exception {
199 Pnf pnf = preparePnfAndExtractForPnf();
200 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.INVENTORIED);
202 aaiUpdateTasks.updateOrchestrationStatusInventoriedPnf(execution);
204 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.INVENTORIED);
208 public void updateOrchestrationStatusInventoriedPnfExceptionTest() throws Exception {
209 Pnf pnf = preparePnfAndExtractForPnf();
210 doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
211 OrchestrationStatus.INVENTORIED);
213 expectedException.expect(BpmnError.class);
214 aaiUpdateTasks.updateOrchestrationStatusInventoriedPnf(execution);
218 public void updateOrchestrationStatusActivePnfTest() throws Exception {
219 Pnf pnf = preparePnfAndExtractForPnf();
220 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
222 aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
224 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
228 public void updateOrchestrationStatusActivePnfExceptionTest() throws Exception {
229 Pnf pnf = preparePnfAndExtractForPnf();
230 doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
231 OrchestrationStatus.ACTIVE);
233 expectedException.expect(BpmnError.class);
234 aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
238 public void updateOrchestrationStatusRegisterPnfTest() throws Exception {
239 Pnf pnf = preparePnfAndExtractForPnf();
240 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
242 aaiUpdateTasks.updateOrchestrationStatusRegisterPnf(execution);
244 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
248 public void updateOrchestrationStatusRegisteredPnfTest() throws Exception {
249 Pnf pnf = preparePnfAndExtractForPnf();
250 doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
252 aaiUpdateTasks.updateOrchestrationStatusRegisteredPnf(execution);
254 verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
258 public void updateOrchestrationStatusAssignedVnfTest() {
259 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
261 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
263 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
267 public void updateOrchestrationStatusAssignedVnfExceptionTest() {
268 expectedException.expect(BpmnError.class);
270 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
271 OrchestrationStatus.ASSIGNED);
273 aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
277 public void updateOrchestrationStatusActiveVnfTest() {
278 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
280 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
282 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
286 public void updateOrchestrationStatusActiveVnfExceptionTest() {
287 expectedException.expect(BpmnError.class);
289 doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf,
290 OrchestrationStatus.ACTIVE);
292 aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
296 public void updateOrchestrationStatusAssignVfModuleTest() {
297 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
298 OrchestrationStatus.ASSIGNED);
299 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
300 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
301 OrchestrationStatus.ASSIGNED);
302 assertEquals("", vfModule.getHeatStackId());
306 public void updateOrchestrationStatusAssignVfModuleExceptionTest() {
307 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
308 genericVnf, OrchestrationStatus.ASSIGNED);
310 expectedException.expect(BpmnError.class);
312 aaiUpdateTasks.updateOrchestrationStatusAssignedVfModule(execution);
316 public void updateOrchestrationStatusCreatedVfModuleTest() {
317 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
318 OrchestrationStatus.CREATED);
319 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
320 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
321 OrchestrationStatus.CREATED);
325 public void updateOrchestrationStatusCreatedVfModuleExceptionTest() {
326 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
327 genericVnf, OrchestrationStatus.CREATED);
329 expectedException.expect(BpmnError.class);
331 aaiUpdateTasks.updateOrchestrationStatusCreatedVfModule(execution);
335 public void updateOrchestrationStatusPendingActivatefModuleTest() {
336 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
337 OrchestrationStatus.PENDING_ACTIVATION);
339 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
341 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
342 OrchestrationStatus.PENDING_ACTIVATION);
346 public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() {
347 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
348 genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
350 expectedException.expect(BpmnError.class);
352 aaiUpdateTasks.updateOrchestrationStatusPendingActivationVfModule(execution);
356 public void updateOrchestrationStatusDectivateVfModuleTest() {
357 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
358 OrchestrationStatus.CREATED);
360 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
362 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
363 OrchestrationStatus.CREATED);
367 public void updateOrchestrationStatusDectivateVfModuleExceptionTest() {
368 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
369 genericVnf, OrchestrationStatus.CREATED);
371 expectedException.expect(BpmnError.class);
373 aaiUpdateTasks.updateOrchestrationStatusDeactivateVfModule(execution);
377 public void updateHeatStackIdVfModuleTest() {
378 execution.setVariable("heatStackId", "newHeatStackId");
379 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
381 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
383 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
384 assertEquals("newHeatStackId", vfModule.getHeatStackId());
388 public void updateHeatStackIdVfModuleToNullTest() {
389 execution.setVariable("heatStackId", null);
390 doNothing().when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
392 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
394 verify(aaiVfModuleResources, times(1)).updateHeatStackIdVfModule(vfModule, genericVnf);
395 assertEquals("", vfModule.getHeatStackId());
399 public void updateHeatStackIdVfModuleExceptionTest() {
400 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
402 expectedException.expect(BpmnError.class);
404 aaiUpdateTasks.updateHeatStackIdVfModule(execution);
408 public void updateOrchestrationStatusActiveVolumeGroupTest() {
409 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
410 OrchestrationStatus.ACTIVE);
412 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
414 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
415 OrchestrationStatus.ACTIVE);
419 public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() {
420 expectedException.expect(BpmnError.class);
421 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
422 cloudRegion, OrchestrationStatus.ACTIVE);
423 aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
427 public void updateOrchestrationStatusCreatedVolumeGroupTest() {
428 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
429 OrchestrationStatus.CREATED);
431 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
433 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
434 OrchestrationStatus.CREATED);
438 public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() {
439 expectedException.expect(BpmnError.class);
440 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
441 cloudRegion, OrchestrationStatus.CREATED);
442 aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
446 public void test_updateOrchestrationStatusAssignedVolumeGroup() {
447 doNothing().when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
448 OrchestrationStatus.ASSIGNED);
450 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
452 verify(aaiVolumeGroupResources, times(1)).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion,
453 OrchestrationStatus.ASSIGNED);
454 assertEquals("", volumeGroup.getHeatStackId());
458 public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() {
459 expectedException.expect(BpmnError.class);
460 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup,
461 cloudRegion, OrchestrationStatus.ASSIGNED);
462 aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
466 public void updateHeatStackIdVolumeGroupTest() {
467 execution.setVariable("heatStackId", "newHeatStackId");
468 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
470 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
472 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
473 assertEquals("newHeatStackId", volumeGroup.getHeatStackId());
477 public void updateHeatStackIdVolumeGroupToNullTest() {
478 execution.setVariable("heatStackId", null);
479 doNothing().when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
481 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
483 verify(aaiVolumeGroupResources, times(1)).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
484 assertEquals("", volumeGroup.getHeatStackId());
488 public void updateHeatStackIdVolumeGroupExceptionTest() {
489 expectedException.expect(BpmnError.class);
490 doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup,
492 aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
496 public void updateNetworkExceptionTest() {
497 expectedException.expect(BpmnError.class);
499 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
501 aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
505 public void updateOstatusActivedNetworkCollectionTest() {
506 doNothing().when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
507 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
508 verify(aaiCollectionResources, times(1)).updateCollection(serviceInstance.getCollection());
512 public void updateOstatusActiveNetworkColectionExceptionTest() {
513 expectedException.expect(BpmnError.class);
514 doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
515 aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
519 public void updateOrchestrationStatusActivateVfModuleTest() {
520 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
521 OrchestrationStatus.ACTIVE);
523 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
525 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
526 OrchestrationStatus.ACTIVE);
530 public void updateOrchestrationStatusActivateVfModuleExceptionTest() {
531 doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule,
532 genericVnf, OrchestrationStatus.ACTIVE);
534 expectedException.expect(BpmnError.class);
536 aaiUpdateTasks.updateOrchestrationStatusActivateVfModule(execution);
540 public void updateNetworkCreatedTest() throws Exception {
541 CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
542 createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
543 createNetworkResponse.setNetworkStackId("testNetworkStackId");
544 HashMap<String, String> subnetMap = new HashMap<>();
545 subnetMap.put("testSubnetId", "testNeutronSubnetId");
546 createNetworkResponse.setSubnetMap(subnetMap);
548 network.getSubnets().add(subnet);
550 execution.setVariable("createNetworkResponse", createNetworkResponse);
552 doNothing().when(aaiNetworkResources).updateNetwork(network);
553 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
555 aaiUpdateTasks.updateNetworkCreated(execution);
556 verify(aaiNetworkResources, times(1)).updateNetwork(network);
557 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
559 assertEquals(createNetworkResponse.getNetworkFqdn(), network.getContrailNetworkFqdn());
560 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());
561 assertEquals(createNetworkResponse.getNetworkStackId(), network.getHeatStackId());
562 assertEquals(createNetworkResponse.getNeutronNetworkId(), network.getNeutronNetworkId());
563 String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
564 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
568 public void updateNetworkUpdatedTest() throws Exception {
569 UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse();
570 updateNetworkResponse.setNeutronNetworkId("testNeutronNetworkId");
571 HashMap<String, String> subnetMap = new HashMap<>();
572 subnetMap.put("testSubnetId", "testNeutronSubnetId");
573 updateNetworkResponse.setSubnetMap(subnetMap);
575 network.getSubnets().add(subnet);
577 execution.setVariable("updateNetworkResponse", updateNetworkResponse);
579 doNothing().when(aaiNetworkResources).updateNetwork(network);
580 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
582 aaiUpdateTasks.updateNetworkUpdated(execution);
583 verify(aaiNetworkResources, times(1)).updateNetwork(network);
584 verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet);
586 String neutronSubnetId = updateNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue();
587 assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId());
591 public void updateOrchestrationStatusNetworkTest() {
592 AAIUpdateTasks spy = Mockito.spy(new AAIUpdateTasks());
593 doNothing().when(spy).updateNetwork(eq(execution), any());
594 spy.updateOrchestrationStatusActiveNetwork(execution);
595 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ACTIVE);
596 spy.updateOrchestrationStatusAssignedNetwork(execution);
597 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.ASSIGNED);
598 spy.updateOrchestrationStatusCreatedNetwork(execution);
599 verify(spy, times(1)).updateNetwork(execution, OrchestrationStatus.CREATED);
603 public void updateNetworkAAITest() {
605 L3Network spy = spy(new L3Network());
606 L3Network shallowCopy = mock(L3Network.class);
607 Subnet mockSubnet = mock(Subnet.class);
608 Subnet shallowCopySubnet = mock(Subnet.class);
609 when(mockSubnet.shallowCopyId()).thenReturn(shallowCopySubnet);
610 doReturn(shallowCopy).when(spy).shallowCopyId();
612 doNothing().when(aaiNetworkResources).updateNetwork(network);
613 doNothing().when(aaiNetworkResources).updateSubnet(network, subnet);
615 spy.getSubnets().add(mockSubnet);
616 aaiUpdateTasks.updateNetworkAAI(spy, OrchestrationStatus.CREATED);
618 verify(shallowCopy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
619 verify(spy, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
620 verify(shallowCopySubnet, times(1)).setOrchestrationStatus(OrchestrationStatus.CREATED);
624 public void updateNetworkCreatedkExceptionTest() throws Exception {
625 expectedException.expect(BpmnError.class);
626 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
627 aaiUpdateTasks.updateNetworkCreated(execution);
631 public void updateObjectNetworkTest() {
632 doNothing().when(aaiNetworkResources).updateNetwork(network);
634 aaiUpdateTasks.updateObjectNetwork(execution);
636 verify(aaiNetworkResources, times(1)).updateNetwork(network);
640 public void updateObjectNetworkExceptionText() {
641 expectedException.expect(BpmnError.class);
643 doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
645 aaiUpdateTasks.updateObjectNetwork(execution);
649 public void test_updateServiceInstance() {
650 doNothing().when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
651 aaiUpdateTasks.updateServiceInstance(execution);
652 verify(aaiServiceInstanceResources, times(1)).updateServiceInstance(serviceInstance);
656 public void test_updateServiceInstance_exception() {
657 expectedException.expect(BpmnError.class);
658 doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
659 aaiUpdateTasks.updateServiceInstance(execution);
663 public void updateObjectVnfTest() {
664 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
666 aaiUpdateTasks.updateObjectVnf(execution);
668 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
672 public void updateObjectVnfExceptionTest() {
673 expectedException.expect(BpmnError.class);
674 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
675 aaiUpdateTasks.updateObjectVnf(execution);
679 public void updateOrchestrationStatusDeleteVfModuleTest() {
680 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
681 OrchestrationStatus.ASSIGNED);
683 aaiUpdateTasks.updateOrchestrationStatusDeleteVfModule(execution);
685 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
686 OrchestrationStatus.ASSIGNED);
687 assertEquals("", vfModule.getHeatStackId());
691 public void updateModelVfModuleTest() {
692 doNothing().when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
693 aaiUpdateTasks.updateModelVfModule(execution);
694 verify(aaiVfModuleResources, times(1)).changeAssignVfModule(vfModule, genericVnf);
698 public void updateModelVfModuleExceptionTest() {
699 expectedException.expect(BpmnError.class);
700 doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
701 aaiUpdateTasks.updateModelVfModule(execution);
705 public void updateOrchestrationStatusDeactivateFabricConfigurationTest() {
706 gBBInput = execution.getGeneralBuildingBlock();
707 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
708 OrchestrationStatus.ASSIGNED);
710 aaiUpdateTasks.updateOrchestrationStatusDeactivateFabricConfiguration(execution);
712 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
713 OrchestrationStatus.ASSIGNED);
717 public void updateOrchestrationStatusActivateFabricConfigurationTest() {
718 gBBInput = execution.getGeneralBuildingBlock();
719 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
720 OrchestrationStatus.ACTIVE);
722 aaiUpdateTasks.updateOrchestrationStatusActivateFabricConfiguration(execution);
724 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
725 OrchestrationStatus.ACTIVE);
729 public void updateOrchestrationStatusAssignedFabricConfigurationTest() {
730 gBBInput = execution.getGeneralBuildingBlock();
731 doNothing().when(aaiConfigurationResources).updateOrchestrationStatusConfiguration(configuration,
732 OrchestrationStatus.ASSIGNED);
734 aaiUpdateTasks.updateOrchestrationStatusAssignFabricConfiguration(execution);
736 verify(aaiConfigurationResources, times(1)).updateOrchestrationStatusConfiguration(configuration,
737 OrchestrationStatus.ASSIGNED);
741 public void updateContrailServiceInstanceFqdnVfModuleTest() {
742 execution.setVariable("contrailServiceInstanceFqdn", "newContrailServiceInstanceFqdn");
743 doNothing().when(aaiVfModuleResources).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
745 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
747 verify(aaiVfModuleResources, times(1)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
748 assertEquals("newContrailServiceInstanceFqdn", vfModule.getContrailServiceInstanceFqdn());
752 public void updateContrailServiceInstanceFqdnVfModuleNoUpdateTest() {
753 aaiUpdateTasks.updateContrailServiceInstanceFqdnVfModule(execution);
754 verify(aaiVfModuleResources, times(0)).updateContrailServiceInstanceFqdnVfModule(vfModule, genericVnf);
758 public void updateIpv4OamAddressVnfTest() {
759 execution.setVariable("oamManagementV4Address", "newIpv4OamAddress");
760 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
762 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
764 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
765 assertEquals("newIpv4OamAddress", genericVnf.getIpv4OamAddress());
769 public void updateIpv4OamAddressVnfNoUpdateTest() {
770 aaiUpdateTasks.updateIpv4OamAddressVnf(execution);
771 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
775 public void updateManagementV6AddressVnfTest() {
776 execution.setVariable("oamManagementV6Address", "newManagementV6Address");
777 doNothing().when(aaiVnfResources).updateObjectVnf(genericVnf);
779 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
781 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
782 assertEquals("newManagementV6Address", genericVnf.getManagementV6Address());
786 public void updateManagementV6AddressVnfNoUpdateTest() {
787 aaiUpdateTasks.updateManagementV6AddressVnf(execution);
788 verify(aaiVnfResources, times(0)).updateObjectVnf(genericVnf);
792 public void updateOrchestrationStatusVnfConfigureTest() {
793 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
794 OrchestrationStatus.CONFIGURE);
796 aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfigureVnf(execution);
800 public void updateOrchestrationStatusVnfConfiguredTest() {
801 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
802 OrchestrationStatus.CONFIGURED);
804 aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfiguredVnf(execution);
807 private Pnf preparePnfAndExtractForPnf() throws BBObjectNotFoundException {
808 Pnf pnf = buildPnf();
809 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf);
814 public void updateOrchestrationStatusVnfConfigAssignedTest() {
815 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGASSIGNED);
817 aaiUpdateTasks.updateOrchestrationStatus(execution, "vnf", "config-assign");
819 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGASSIGNED);
823 public void updateOrchestrationStatusVnfConfigDeployedTest() {
824 doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGDEPLOYED);
826 aaiUpdateTasks.updateOrchestrationStatus(execution, "vnf", "config-deploy");
828 verify(aaiVnfResources, times(1)).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.CONFIGDEPLOYED);
832 public void updateOrchestrationStatusVfModuleConfigDeployedTest() {
833 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
834 OrchestrationStatus.CONFIGDEPLOYED);
835 aaiUpdateTasks.updateOrchestrationStatus(execution, "vfmodule", "config-deploy");
836 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
837 OrchestrationStatus.CONFIGDEPLOYED);
841 public void updateOrchestrationStatusVfModuleConfigAssignedTest() {
842 doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
843 OrchestrationStatus.CONFIGASSIGNED);
844 aaiUpdateTasks.updateOrchestrationStatus(execution, "vfmodule", "config-assign");
845 verify(aaiVfModuleResources, times(1)).updateOrchestrationStatusVfModule(vfModule, genericVnf,
846 OrchestrationStatus.CONFIGASSIGNED);