Update requestStatus to FAILED on activity error. 39/94639/1
authorElena Kuleshov <evn@att.com>
Thu, 29 Aug 2019 20:47:28 +0000 (16:47 -0400)
committerElena Kuleshov <evn@att.com>
Thu, 29 Aug 2019 20:49:17 +0000 (16:49 -0400)
Update status and related fields in Requests DB on activity error, add a junit to verify error reporting.

Issue-ID: SO-2263
Signed-off-by: Kuleshov, Elena <evn@att.com>
Change-Id: I1a2e97afb95e4510b4860486c2b7836b014f990e

bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivityTest.java

index 9340609..d9c6857 100644 (file)
@@ -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);
     }
 }
index 56ff813..c005629 100644 (file)
@@ -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);
+    }
+
 }