From 9d6f84234a66f349b4f05e04a45ba544533ca56a Mon Sep 17 00:00:00 2001 From: Elena Kuleshov Date: Thu, 29 Aug 2019 16:47:28 -0400 Subject: Update requestStatus to FAILED on activity error. 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 Change-Id: I1a2e97afb95e4510b4860486c2b7836b014f990e --- .../activity/ExecuteActivityTest.java | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'bpmn/so-bpmn-tasks/src/test/java') 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); + } + } -- cgit 1.2.3-korg