fixed null pointer in update request db 06/74406/1
authorKalkere Ramesh, Sharan (sk720x) <sk720x@att.com>
Fri, 7 Dec 2018 17:18:52 +0000 (12:18 -0500)
committerKalkere Ramesh, Sharan (sk720x) <sk720x@att.com>
Fri, 7 Dec 2018 17:20:24 +0000 (12:20 -0500)
Fix issue with broken JUNIT tests case
Update logic so it does not null pointer

Change-Id: I88bbb6eb28125331ee10e6ba5185b15bae8b2375
Issue-ID: SO-1300
Signed-off-by: Kalkere Ramesh, Sharan (sk720x) <sk720x@att.com>
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");
+       }
 }