From 0eac9a23fb2e79f3c996664cf6d6f02e1573dadc Mon Sep 17 00:00:00 2001 From: "Gamboa, Gilbert" Date: Thu, 24 Oct 2019 14:33:12 -0400 Subject: Call WorkflowActionTasks.sendErrorSyncAck() Call WorkflowActionTasks.sendErrorSyncAck() instead of WorkflowActionTasks.sendSyncAck() from WorkflowActionBB in error handling subroutine. Call WorkflowActionTasks.sendErrorSyncAck() instead of WorkflowActionTasks.sendSyncAck() from WorkflowActionBB in error handling subroutine. Issue-ID: SO-2489 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I8c1c2bb6af70d5e76cfbfd3ce54fb506ab653cf7 --- .../workflow/service/WorkflowAsyncResource.java | 8 ++- .../service/WorkflowAsyncResourceTest.java | 59 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java (limited to 'bpmn/mso-infrastructure-bpmn/src') diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java index ace6e1937d..4fb63651eb 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java @@ -102,7 +102,11 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, getRequestId(inputVariables)); processor.startProcess(processKey, variableMap); WorkflowResponse response = waitForResponse(inputVariables); - return Response.status(202).entity(response).build(); + if (response.getMessageCode() == 500) { + return Response.status(500).entity(response).build(); + } else { + return Response.status(202).entity(response).build(); + } } catch (WorkflowProcessorException e) { WorkflowResponse response = e.getWorkflowResponse(); return Response.status(500).entity(response).build(); @@ -112,7 +116,7 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { } } - private WorkflowResponse waitForResponse(Map inputVariables) throws Exception { + protected WorkflowResponse waitForResponse(Map inputVariables) throws Exception { String requestId = getRequestId(inputVariables); long currentWaitTime = 0; long waitTime = getWaitTime(inputVariables); diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java new file mode 100644 index 0000000000..df9a23019a --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java @@ -0,0 +1,59 @@ +package org.onap.so.bpmn.common.workflow.service; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.ArgumentMatchers.anyMap; +import java.util.HashMap; +import java.util.Map; +import javax.ws.rs.core.Response; +import org.camunda.bpm.engine.variable.impl.VariableMapImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.workflow.context.WorkflowResponse; + +@RunWith(MockitoJUnitRunner.class) +public class WorkflowAsyncResourceTest { + + @InjectMocks + @Spy + private WorkflowAsyncResource workflowAsyncResource; + + @Mock + private WorkflowProcessor processor; + + private WorkflowResponse workflowResponse; + private VariableMapImpl varMap; + + @Before + public void before() { + workflowResponse = new WorkflowResponse(); + varMap = new VariableMapImpl(); + Map variables = new HashMap(); + Map requestIdMap = new HashMap(); + requestIdMap.put("value", "123"); + requestIdMap.put("type", "String"); + variables.put("mso-request-id", requestIdMap); + varMap.put("variables", variables); + } + + @Test + public void startProcessInstanceByKey200Test() throws Exception { + workflowResponse.setMessageCode(200); + doReturn(workflowResponse).when(workflowAsyncResource).waitForResponse(anyMap()); + Response response = workflowAsyncResource.startProcessInstanceByKey("123", varMap); + assertEquals(202, response.getStatus()); + } + + @Test + public void startProcessInstanceByKey500Test() throws Exception { + workflowResponse.setMessageCode(500); + doReturn(workflowResponse).when(workflowAsyncResource).waitForResponse(anyMap()); + Response response = workflowAsyncResource.startProcessInstanceByKey("123", varMap); + assertEquals(500, response.getStatus()); + } +} -- cgit 1.2.3-korg