11/7: merge casablanca to master
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / aai / tasks / AAIUpdateTasksTest.java
index 1a302c2..6c20938 100644 (file)
@@ -21,8 +21,8 @@
 package org.onap.so.bpmn.infrastructure.aai.tasks;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
@@ -38,9 +38,12 @@ import org.camunda.bpm.engine.delegate.BpmnError;
 import org.hamcrest.Matchers;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.InjectMocks;
 import org.mockito.Mockito;
 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
 import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
@@ -49,13 +52,15 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
+import org.onap.so.client.exception.BBObjectNotFoundException;
 import org.onap.so.db.catalog.beans.OrchestrationStatus;
-import org.springframework.beans.factory.annotation.Autowired;
 
 public class AAIUpdateTasksTest extends BaseTaskTest{
-       @Autowired
-       private AAIUpdateTasks aaiUpdateTasks;
+       
+       @InjectMocks
+       private AAIUpdateTasks aaiUpdateTasks = new AAIUpdateTasks();
        
        private L3Network network;
        private ServiceInstance serviceInstance;
@@ -67,7 +72,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        private Subnet subnet;
        
        @Before
-       public void before() {
+       public void before() throws BBObjectNotFoundException {
                serviceInstance = setServiceInstance();
                genericVnf = setGenericVnf();
                vfModule = setVfModule();
@@ -76,6 +81,16 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
                network = setL3Network();
                configuration = setConfiguration();
                subnet = buildSubnet();
+
+               when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
+               when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
+               when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID), any())).thenReturn(network);
+               when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VOLUME_GROUP_ID), any())).thenReturn(volumeGroup);
+               when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID), any())).thenReturn(serviceInstance);
+               when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.CONFIGURATION_ID), any())).thenReturn(configuration);
+               
+
+               doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
        }
        
        @Test
@@ -91,7 +106,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        public void updateOrchestrationStatusAssignedServiceExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
                
-               doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
+               doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ASSIGNED);
 
                aaiUpdateTasks.updateOrchestrationStatusAssignedService(execution);
        }
@@ -109,7 +124,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        public void updateOrchestrationStatusActiveServiceExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
                
-               doThrow(Exception.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
+               doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateOrchestrationStatusServiceInstance(serviceInstance, OrchestrationStatus.ACTIVE);
 
                aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
        }
@@ -127,7 +142,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        public void updateOrchestrationStatusAssignedVnfExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
                
-               doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
+               doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
 
                aaiUpdateTasks.updateOrchestrationStatusAssignedVnf(execution);
        }
@@ -145,7 +160,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        public void updateOrchestrationStatusActiveVnfExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
                
-               doThrow(Exception.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
+               doThrow(RuntimeException.class).when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ACTIVE);
 
                aaiUpdateTasks.updateOrchestrationStatusActiveVnf(execution);
        }
@@ -160,7 +175,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        
        @Test
        public void updateOrchestrationStatusAssignVfModuleExceptionTest() throws Exception {
-               doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
+               doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
                
                expectedException.expect(BpmnError.class);
                
@@ -206,7 +221,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void updateOrchestrationStatusAssignedOrPendingActivationVfModuleExceptionTest() throws Exception {
                execution.setVariable("aLaCarte", true);
-               doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
+               doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ASSIGNED);
                
                expectedException.expect(BpmnError.class);
                
@@ -222,7 +237,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        
        @Test
        public void updateOrchestrationStatusCreatedVfModuleExceptionTest() throws Exception {
-               doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
+               doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
                
                expectedException.expect(BpmnError.class);
                
@@ -240,7 +255,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        
        @Test
        public void updateOrchestrationStatusPendingActivatefModuleExceptionTest() throws Exception {
-               doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
+               doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.PENDING_ACTIVATION);
                
                expectedException.expect(BpmnError.class);
        
@@ -258,7 +273,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        
        @Test
        public void updateOrchestrationStatusDectivateVfModuleExceptionTest() throws Exception {
-               doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
+               doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.CREATED);
                
                expectedException.expect(BpmnError.class);
        
@@ -278,7 +293,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        
        @Test
        public void updateHeatStackIdVfModuleExceptionTest() throws Exception {
-               doThrow(Exception.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
+               doThrow(RuntimeException.class).when(aaiVfModuleResources).updateHeatStackIdVfModule(vfModule, genericVnf);
                
                expectedException.expect(BpmnError.class);
        
@@ -297,7 +312,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void updateOrchestrationStatusActiveVolumeGroupExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
-               doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
+               doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ACTIVE);
                aaiUpdateTasks.updateOrchestrationStatusActiveVolumeGroup(execution);
        }
        
@@ -313,7 +328,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void updateOrchestrationStatusCreatedVolumeGroupExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
-               doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
+               doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.CREATED);
                aaiUpdateTasks.updateOrchestrationStatusCreatedVolumeGroup(execution);
        }       
        
@@ -330,7 +345,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void test_updateOrchestrationStatusAssignedVolumeGroup_exception() throws Exception {
                expectedException.expect(BpmnError.class);
-               doThrow(Exception.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
+               doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateOrchestrationStatusVolumeGroup(volumeGroup, cloudRegion, OrchestrationStatus.ASSIGNED);
                aaiUpdateTasks.updateOrchestrationStatusAssignedVolumeGroup(execution);
        }
        @Test
@@ -347,7 +362,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void updateHeatStackIdVolumeGroupExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
-               doThrow(Exception.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
+               doThrow(RuntimeException.class).when(aaiVolumeGroupResources).updateHeatStackIdVolumeGroup(volumeGroup, cloudRegion);
                aaiUpdateTasks.updateHeatStackIdVolumeGroup(execution);
        }
 
@@ -355,7 +370,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        public void updateNetworkExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
 
-               doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
+               doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
                
                aaiUpdateTasks.updateNetwork(execution, OrchestrationStatus.ACTIVE);
        }
@@ -370,7 +385,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void updateOstatusActiveNetworkColectionExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
-               doThrow(Exception.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
+               doThrow(RuntimeException.class).when(aaiCollectionResources).updateCollection(serviceInstance.getCollection());
                aaiUpdateTasks.updateOrchestrationStatusActiveNetworkCollection(execution);
        }
 
@@ -385,7 +400,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        
        @Test
        public void updateOrchestrationStatusActivateVfModuleExceptionTest() throws Exception {
-               doThrow(Exception.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
+               doThrow(RuntimeException.class).when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf, OrchestrationStatus.ACTIVE);
                
                expectedException.expect(BpmnError.class);
                
@@ -397,7 +412,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
                CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse();
                createNetworkResponse.setNetworkFqdn("testNetworkFqdn");
                createNetworkResponse.setNetworkStackId("testNetworkStackId");
-               HashMap<String, String> subnetMap = new HashMap<String, String>();
+               HashMap<String, String> subnetMap = new HashMap<>();
                subnetMap.put("testSubnetId", "testNeutronSubnetId");
                createNetworkResponse.setSubnetMap(subnetMap);
                
@@ -455,7 +470,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void updateNetworkCreatedkExceptionTest() throws Exception {
                expectedException.expect(BpmnError.class);
-               doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
+               doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
                aaiUpdateTasks.updateNetworkCreated(execution);
        }
        
@@ -472,7 +487,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        public void updateObjectNetworkExceptionText() {
                expectedException.expect(BpmnError.class);
                
-               doThrow(Exception.class).when(aaiNetworkResources).updateNetwork(network);
+               doThrow(RuntimeException.class).when(aaiNetworkResources).updateNetwork(network);
                
                aaiUpdateTasks.updateObjectNetwork(execution);
        }
@@ -487,7 +502,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void test_updateServiceInstance_exception() {
                expectedException.expect(BpmnError.class);
-               doThrow(Exception.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
+               doThrow(RuntimeException.class).when(aaiServiceInstanceResources).updateServiceInstance(serviceInstance);
                aaiUpdateTasks.updateServiceInstance(execution);
        }
        
@@ -503,7 +518,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void updateObjectVnfExceptionTest() {
                expectedException.expect(BpmnError.class);
-               doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
+               doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(genericVnf);
                aaiUpdateTasks.updateObjectVnf(execution);
        }
        
@@ -527,7 +542,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest{
        @Test
        public void updateModelVfModuleExceptionTest() {
                expectedException.expect(BpmnError.class);
-               doThrow(Exception.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
+               doThrow(RuntimeException.class).when(aaiVfModuleResources).changeAssignVfModule(vfModule, genericVnf);
                aaiUpdateTasks.updateModelVfModule(execution);
        }