Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
feat: add WorkFlowDefinitionNotFoundException class
Browse files Browse the repository at this point in the history
Signed-off-by: Eloy Coto <eloy.coto@acalustra.com>
  • Loading branch information
eloycoto committed May 21, 2023
1 parent 1d67f80 commit f095c9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
Expand All @@ -146,14 +149,16 @@ void ExecuteAroundAdviceWithInProgressWorkFlowTestWithoutWorkFlowDefinition() {
when(proceedingJoinPoint.getTarget()).thenReturn(workFlow);
when(workFlow.getName()).thenReturn(TEST_WORK_FLOW);


// when
WorkReport workReport = this.workFlowExecutionAspect.executeAroundAdvice(proceedingJoinPoint, workContext);

// then
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);
}

Expand Down

0 comments on commit f095c9f

Please sign in to comment.