diff options
author | Kalkere Ramesh, Sharan (sk720x) <sk720x@att.com> | 2018-12-10 15:33:39 -0500 |
---|---|---|
committer | Kalkere Ramesh, Sharan (sk720x) <sk720x@att.com> | 2018-12-10 15:36:43 -0500 |
commit | 14a324a7607335b381552e27c345970d5c2a2070 (patch) | |
tree | be69ac55766757c6878d22e7760c66ad2ecca6bc /bpmn/so-bpmn-tasks/src/test | |
parent | 533311a4934838b67ffd0ca49d7958f69059bccd (diff) |
refactor updaterequeststatustofailed method
fixed compliation error in workflowActionbbtest mocks
moved request db failure logic to a separate class
refactored and added test cases for updateReqToFailed
Change-Id: Ie928aa541e86afb8e867ca445258b118eed8b357
Issue-ID: SO-1310
Signed-off-by: Kalkere Ramesh, Sharan (sk720x) <sk720x@att.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test')
2 files changed, 137 insertions, 27 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java new file mode 100644 index 0000000000..d9a7eeb8f7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailureTest.java @@ -0,0 +1,126 @@ +package org.onap.so.bpmn.infrastructure.workflow.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Rule; +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.bbobjects.Customer; +import org.onap.so.db.request.beans.InfraActiveRequests; + +public class WorkflowActionBBFailureTest extends BaseTaskTest { + + @Mock + protected WorkflowAction workflowAction; + + @InjectMocks + @Spy + protected WorkflowActionBBFailure workflowActionBBFailure; + + @Mock + InfraActiveRequests reqMock; + + private DelegateExecution execution; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void before() throws Exception { + execution = new DelegateExecutionFake(); + org.onap.aai.domain.yang.ServiceInstance servInstance = new org.onap.aai.domain.yang.ServiceInstance(); + servInstance.setServiceInstanceId("TEST"); + when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), isA(Customer.class))).thenReturn(servInstance); + workflowAction.setBbInputSetupUtils(bbSetupUtils); + workflowAction.setBbInputSetup(bbInputSetup); + } + + @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); + workflowActionBBFailure.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"); + } + + @Test + public void updateRequestStatusToFailed(){ + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", false); + execution.setVariable("isRollback", false); + InfraActiveRequests req = new InfraActiveRequests(); + WorkflowException wfe = new WorkflowException("processKey123", 1, "error in test case"); + execution.setVariable("WorkflowException", wfe); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("ErrorMessage"); + assertEquals("error in test case", errorMsg); + } + + @Test + public void updateRequestStatusToFailedRollback(){ + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", false); + execution.setVariable("isRollback", true); + InfraActiveRequests req = new InfraActiveRequests(); + WorkflowException wfe = new WorkflowException("processKey123", 1, "error in rollback"); + execution.setVariable("WorkflowException", wfe); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("RollbackErrorMessage"); + assertEquals("error in rollback", errorMsg); + } + + @Test + public void updateRequestStatusToFailedRollbackCompleted(){ + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", true); + execution.setVariable("isRollback", true); + InfraActiveRequests req = new InfraActiveRequests(); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("RollbackErrorMessage"); + assertEquals("Rollback has been completed successfully.", errorMsg); + } + + @Test + public void updateRequestStatusToFailedNoWorkflowException(){ + execution.setVariable("mso-request-id", "123"); + execution.setVariable("isRollbackComplete", false); + execution.setVariable("isRollback", false); + execution.setVariable("WorkflowExceptionErrorMessage", "error in test case"); + InfraActiveRequests req = new InfraActiveRequests(); + doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId("123"); + doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class)); + workflowActionBBFailure.updateRequestStatusToFailed(execution); + String errorMsg = (String) execution.getVariable("ErrorMessage"); + assertEquals("error in test case", errorMsg); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java index 0ef764ac99..189ecb96c7 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java @@ -52,6 +52,9 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { @Mock protected WorkflowAction workflowAction; + @Mock + protected WorkflowActionBBFailure workflowActionBBFailure; + @InjectMocks @Spy protected WorkflowActionBBTasks workflowActionBBTasks; @@ -146,8 +149,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); - + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeactivateVfModuleBB"); @@ -179,8 +182,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 2); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); - + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"DeleteVfModuleBB"); @@ -217,8 +220,8 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); - + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(),"UnassignNetworkBB"); @@ -255,7 +258,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { execution.setVariable("flowsToExecute", flowsToExecute); execution.setVariable("gCurrentSequence", 3); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); workflowActionBBTasks.rollbackExecutionPath(execution); List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); @@ -267,7 +270,7 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { public void checkRetryStatusTest(){ String reqId = "reqId123"; execution.setVariable("mso-request-id", reqId); - doNothing().when(workflowActionBBTasks).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); + doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class)); execution.setVariable("handlingCode","Retry"); execution.setVariable("retryCount", 1); execution.setVariable("gCurrentSequence",1); @@ -289,23 +292,4 @@ 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"); - } } |