AssignPnfBB - set orchestration status to Assigned after successful assignment
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / aai / tasks / AAIUpdateTasksTest.java
index 905f244..e26009a 100644 (file)
 
 package org.onap.so.bpmn.infrastructure.aai.tasks;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-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;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import java.util.HashMap;
 import org.camunda.bpm.engine.delegate.BpmnError;
-import org.hamcrest.Matchers;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentMatchers;
@@ -48,6 +34,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
@@ -56,6 +43,18 @@ 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 java.util.HashMap;
+import static org.junit.Assert.assertEquals;
+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;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 public class AAIUpdateTasksTest extends BaseTaskTest {
 
@@ -140,6 +139,66 @@ public class AAIUpdateTasksTest extends BaseTaskTest {
         aaiUpdateTasks.updateOrchestrationStatusActiveService(execution);
     }
 
+    @Test
+    public void updateOrchestrationStatusAssignedPnfTest() throws Exception {
+        Pnf pnf = preparePnfAndExtractForPnf();
+        doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
+
+        aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
+
+        verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ASSIGNED);
+    }
+
+    @Test
+    public void updateOrchestrationStatusAssignedPnfExceptionTest() throws Exception {
+        Pnf pnf = preparePnfAndExtractForPnf();
+        doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
+                OrchestrationStatus.ASSIGNED);
+
+        expectedException.expect(BpmnError.class);
+        aaiUpdateTasks.updateOrchestrationStatusAssignedPnf(execution);
+    }
+
+    @Test
+    public void updateOrchestrationStatusActivePnfTest() throws Exception {
+        Pnf pnf = preparePnfAndExtractForPnf();
+        doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
+
+        aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
+
+        verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE);
+    }
+
+    @Test
+    public void updateOrchestrationStatusActivePnfExceptionTest() throws Exception {
+        Pnf pnf = preparePnfAndExtractForPnf();
+        doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf,
+                OrchestrationStatus.ACTIVE);
+
+        expectedException.expect(BpmnError.class);
+        aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution);
+    }
+
+    @Test
+    public void updateOrchestrationStatusRegisterPnfTest() throws Exception {
+        Pnf pnf = preparePnfAndExtractForPnf();
+        doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
+
+        aaiUpdateTasks.updateOrchestrationStatusRegisterPnf(execution);
+
+        verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTER);
+    }
+
+    @Test
+    public void updateOrchestrationStatusRegisteredPnfTest() throws Exception {
+        Pnf pnf = preparePnfAndExtractForPnf();
+        doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
+
+        aaiUpdateTasks.updateOrchestrationStatusRegisteredPnf(execution);
+
+        verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.REGISTERED);
+    }
+
     @Test
     public void updateOrchestrationStatusAssignedVnfTest() throws Exception {
         doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED);
@@ -733,7 +792,7 @@ public class AAIUpdateTasksTest extends BaseTaskTest {
         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
                 OrchestrationStatus.CONFIGURE);
 
-        aaiUpdateTasks.updateOrchestrationStausConfigDeployConfigureVnf(execution);
+        aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfigureVnf(execution);
     }
 
     @Test
@@ -741,6 +800,12 @@ public class AAIUpdateTasksTest extends BaseTaskTest {
         doNothing().when(aaiVfModuleResources).updateOrchestrationStatusVfModule(vfModule, genericVnf,
                 OrchestrationStatus.CONFIGURED);
 
-        aaiUpdateTasks.updateOrchestrationStausConfigDeployConfiguredVnf(execution);
+        aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfiguredVnf(execution);
+    }
+
+    private Pnf preparePnfAndExtractForPnf() throws BBObjectNotFoundException {
+        Pnf pnf = buildPnf();
+        when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf);
+        return pnf;
     }
 }