Merge "fixed null pointer in update request db"
authorRob Daugherty <rd472p@att.com>
Mon, 10 Dec 2018 13:56:26 +0000 (13:56 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 10 Dec 2018 13:56:26 +0000 (13:56 +0000)
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java

index 66e2694..7670e02 100644 (file)
@@ -311,8 +311,14 @@ public class WorkflowActionBBTasks {
                        InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
                        String errorMsg = null;
                        String rollbackErrorMsg = null;
-                       boolean rollbackCompleted = (boolean) execution.getVariable("isRollbackComplete");
-                       boolean isRollbackFailure = (boolean) execution.getVariable("isRollback");
+                       Boolean rollbackCompleted = (Boolean) execution.getVariable("isRollbackComplete");
+                       Boolean isRollbackFailure = (Boolean) execution.getVariable("isRollback");
+                       
+                       if(rollbackCompleted==null)
+                               rollbackCompleted = false;
+                       
+                       if(isRollbackFailure==null)
+                               isRollbackFailure = false;
                        
                        if(rollbackCompleted){
                                rollbackErrorMsg = "Rollback has been completed successfully.";
index fc269cd..0ef764a 100644 (file)
@@ -39,8 +39,10 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.Spy;
 import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.core.WorkflowException;
 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
 import org.onap.so.db.request.beans.InfraActiveRequests;
@@ -54,6 +56,9 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
        @Spy
        protected WorkflowActionBBTasks workflowActionBBTasks;
        
+       @Mock
+       InfraActiveRequests reqMock;
+       
        private DelegateExecution execution;
        
        @Rule
@@ -284,4 +289,23 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest {
                workflowActionBBTasks.checkRetryStatus(execution);
                assertEquals(0,execution.getVariable("retryCount"));
        }
+       
+       
+       @Test
+       public void updateRequestStatusToFailed_Null_Rollback(){
+               String reqId = "reqId123";
+               execution.setVariable("mso-request-id", reqId);
+               execution.setVariable("retryCount", 3);
+               execution.setVariable("handlingCode","Success");
+               execution.setVariable("gCurrentSequence",1);
+               WorkflowException we = new WorkflowException("WorkflowAction",1231,"Error Case");
+               execution.setVariable("WorkflowException",we);
+               
+               doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
+               workflowActionBBTasks.updateRequestStatusToFailed(execution);
+               Mockito.verify( reqMock, Mockito.times(1)).setStatusMessage("Error Case");
+               Mockito.verify( reqMock, Mockito.times(1)).setRequestStatus("FAILED");
+               Mockito.verify( reqMock, Mockito.times(1)).setProgress(Long.valueOf(100));
+               Mockito.verify( reqMock, Mockito.times(1)).setLastModifiedBy("CamundaBPMN");
+       }
 }