diff --git a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/aspect/WorkFlowExecutionAspect.java b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/aspect/WorkFlowExecutionAspect.java index 8171fb6d8..171099ad8 100644 --- a/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/aspect/WorkFlowExecutionAspect.java +++ b/workflow-service/src/main/java/com/redhat/parodos/workflow/execution/aspect/WorkFlowExecutionAspect.java @@ -15,6 +15,9 @@ */ package com.redhat.parodos.workflow.execution.aspect; +import com.redhat.parodos.common.exceptions.IDType; +import com.redhat.parodos.common.exceptions.ResourceNotFoundException; +import com.redhat.parodos.common.exceptions.ResourceType; import com.redhat.parodos.workflow.definition.entity.WorkFlowDefinition; import com.redhat.parodos.workflow.definition.repository.WorkFlowDefinitionRepository; import com.redhat.parodos.workflow.enums.WorkFlowType; @@ -83,9 +86,9 @@ public WorkReport executeAroundAdvice(ProceedingJoinPoint proceedingJoinPoint, W /* get workflow definition entity */ WorkFlowDefinition workFlowDefinition = this.workFlowDefinitionRepository.findFirstByName(workflowName); if (workFlowDefinition == null) { - return new DefaultWorkReport(WorkStatus.FAILED, workContext, new Exception("Cannot find workflow '"+ workflowName + "'")); + return new DefaultWorkReport(WorkStatus.FAILED, workContext, + new ResourceNotFoundException(ResourceType.WORKFLOW_DEFINITION, IDType.NAME, workflowName)); } - WorkFlowExecutionInterceptor executionHandler = workFlowExecutionFactory .createExecutionHandler(workFlowDefinition, workContext); WorkFlowExecution workFlowExecution = executionHandler.handlePreWorkFlowExecution(); diff --git a/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/aspect/WorkFlowExecutionAspectTest.java b/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/aspect/WorkFlowExecutionAspectTest.java index f6fe70b9d..469536eb4 100644 --- a/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/aspect/WorkFlowExecutionAspectTest.java +++ b/workflow-service/src/test/java/com/redhat/parodos/workflow/execution/aspect/WorkFlowExecutionAspectTest.java @@ -3,6 +3,7 @@ import java.util.Optional; import java.util.UUID; +import com.redhat.parodos.common.exceptions.ResourceNotFoundException; import com.redhat.parodos.user.entity.User; import com.redhat.parodos.workflow.WorkFlowDelegate; import com.redhat.parodos.workflow.definition.entity.WorkFlowCheckerMappingDefinition; @@ -30,6 +31,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -132,6 +134,7 @@ public void ExecuteAroundAdviceWithValidDataTest() { assertEquals(workReport.getStatus().toString(), COMPLETED); assertEquals(workReport.getWorkContext().get(WORKFLOW_DEFINITION_NAME), TEST_WORK_FLOW); assertEquals(workReport.getWorkContext().get(PROJECT_ID), projectID); + assertNull(workReport.getError()); verify(this.workFlowSchedulerService, times(1)).stop(any(), any(), any()); verify(this.workFlowService, times(1)).updateWorkFlow(argThat(w -> w.getStatus().toString().equals(COMPLETED))); } @@ -146,7 +149,6 @@ void ExecuteAroundAdviceWithInProgressWorkFlowTestWithoutWorkFlowDefinition() { when(proceedingJoinPoint.getTarget()).thenReturn(workFlow); when(workFlow.getName()).thenReturn(TEST_WORK_FLOW); - // when WorkReport workReport = this.workFlowExecutionAspect.executeAroundAdvice(proceedingJoinPoint, workContext); @@ -154,6 +156,9 @@ void ExecuteAroundAdviceWithInProgressWorkFlowTestWithoutWorkFlowDefinition() { assertNotNull(workReport); assertEquals(workReport.getStatus().toString(), FAILED); assertNotNull(workReport.getError()); + assertThat(workReport.getError()).isInstanceOf(ResourceNotFoundException.class); + // To validate that is workflow definition with type Name and the correct name + assertThat(workReport.getError().getMessage()).contains("Workflow definition with Name: testWorkFlow not found"); verify(this.workFlowDefinitionRepository, times(1)).findFirstByName(TEST_WORK_FLOW); }