ActivitiRuntimeHelper { public void setTaskErrorInWorkflow(DelegateExecution execution, String errorMessage, Exception exception) { setTaskWorkflowVariable(execution, VARIABLE_STATUS, TASK_STATUS_ERROR); setTaskWorkflowVariable(execution, VARIABLE_ERROR_MESSAGE, errorMessage); if (exception != null) { LOGGER.warn("Workflow encountered an error. Logging stack trace in case it is needed to debug an issue. " + "activitiCurrentActivityId=\"{}\" activitiExecutionId=\"{}\"", execution.getCurrentActivityId(), execution.getId(), exception); } }  void signal(String processInstanceId, String signalTaskId); void setTaskWorkflowVariable(String executionId, String activitiId, String variableName, Object variableValue); void setTaskWorkflowVariable(DelegateExecution execution, String variableName, Object variableValue); void setTaskSuccessInWorkflow(DelegateExecution execution); void setTaskErrorInWorkflow(DelegateExecution execution, String errorMessage, Exception exception); String buildTaskWorkflowVariableName(String activitiId, String variableName); static final String VARIABLE_STATUS; static final String VARIABLE_ERROR_MESSAGE; static final String TASK_STATUS_SUCCESS; static final String TASK_STATUS_ERROR; static final String TASK_VARIABLE_MARKER; }
@Test public void testSetTaskErrorInWorkflow() { final String currentActivityId = ACTIVITI_ID; final String executionId = ACTIVITI_ID_2; final String statusTaskWorkflowVariableName = activitiRuntimeHelper.buildTaskWorkflowVariableName(currentActivityId, ActivitiRuntimeHelper.VARIABLE_STATUS); final String errorMessageTaskWorkflowVariableName = activitiRuntimeHelper.buildTaskWorkflowVariableName(currentActivityId, ActivitiRuntimeHelper.VARIABLE_ERROR_MESSAGE); Exception exception = new Exception(ERROR_CODE); DelegateExecution execution = mock(DelegateExecution.class); when(execution.getCurrentActivityId()).thenReturn(currentActivityId); when(execution.getId()).thenReturn(executionId); activitiRuntimeHelper.setTaskErrorInWorkflow(execution, ERROR_MESSAGE, exception); verify(execution, times(3)).getCurrentActivityId(); verify(execution, times(3)).getId(); verify(runtimeService, times(2)).getVariables(executionId); verify(runtimeService).setVariable(executionId, statusTaskWorkflowVariableName, ActivitiRuntimeHelper.TASK_STATUS_ERROR); verify(runtimeService).setVariable(executionId, errorMessageTaskWorkflowVariableName, ERROR_MESSAGE); verifyNoMoreInteractions(execution, runtimeService); }