diff options
2 files changed, 39 insertions, 2 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java index 9340609ffc..d9c6857ef1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java @@ -33,6 +33,7 @@ import org.camunda.bpm.engine.delegate.JavaDelegate; import org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables; import org.camunda.bpm.engine.variable.VariableMap; import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBFailure; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBTasks; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; @@ -79,6 +80,8 @@ public class ExecuteActivity implements JavaDelegate { @Autowired private ExceptionBuilder exceptionBuilder; @Autowired + private WorkflowActionBBFailure workflowActionBBFailure; + @Autowired private WorkflowActionBBTasks workflowActionBBTasks; @Override @@ -178,13 +181,15 @@ public class ExecuteActivity implements JavaDelegate { protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) { logger.error(LoggingAnchor.FIVE, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(), msg, "BPMN", ErrorCode.UnknownError.getValue(), msg, ex); - execution.setVariable("ExecuteActivityErrorMessage", msg); + execution.setVariable(EXECUTE_ACTIVITY_ERROR_MESSAGE, msg); + workflowActionBBFailure.updateRequestStatusToFailed(execution); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); } protected void buildAndThrowException(DelegateExecution execution, String msg) { logger.error(msg); execution.setVariable(EXECUTE_ACTIVITY_ERROR_MESSAGE, msg); + workflowActionBBFailure.updateRequestStatusToFailed(execution); exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java index 56ff813e73..c0056291ef 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java @@ -22,22 +22,41 @@ package org.onap.so.bpmn.infrastructure.activity; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import java.nio.file.Files; import java.nio.file.Paths; +import org.camunda.bpm.engine.delegate.BpmnError; 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.Spy; import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionBBFailure; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; -import org.springframework.beans.factory.annotation.Autowired; +import org.onap.so.client.exception.ExceptionBuilder; public class ExecuteActivityTest extends BaseTaskTest { @InjectMocks protected ExecuteActivity executeActivity = new ExecuteActivity(); + @InjectMocks + @Spy + private ExceptionBuilder exceptionBuilder; + + @Mock + private WorkflowActionBBFailure workflowActionBBFailure; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + private DelegateExecution execution; @Before @@ -72,4 +91,17 @@ public class ExecuteActivityTest extends BaseTaskTest { assertEquals(ebb.getBuildingBlock(), bb); } + @Test + public void buildAndThrowException_Test() throws Exception { + doNothing().when(workflowActionBBFailure).updateRequestStatusToFailed(execution); + doReturn("Process key").when(exceptionBuilder).getProcessKey(execution); + thrown.expect(BpmnError.class); + executeActivity.buildAndThrowException(execution, "TEST EXCEPTION MSG"); + String errorMessage = (String) execution.getVariable("ExecuteActivityErrorMessage"); + assertEquals(errorMessage, "TEST EXCEPTION MSG"); + WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException"); + assertEquals(workflowException.getErrorMessage(), "TEST EXCEPTION MSG"); + assertEquals(workflowException.getErrorCode(), 7000); + } + } |