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

FLPATH-377: fix log not found #390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private WorkFlowTaskExecution getWorkFlowTaskExecution(UUID mainWorkflowExecutio
WorkFlowExecution workFlowExecution = Optional
.ofNullable(workFlowRepository.findFirstByMainWorkFlowExecutionIdAndWorkFlowDefinitionId(
mainWorkflowExecutionId, workFlowTaskDefinition.getWorkFlowDefinition().getId()))
.orElseThrow(
.or(() -> workFlowRepository.findById(mainWorkflowExecutionId)).orElseThrow(
() -> new ResourceNotFoundException(ResourceType.WORKFLOW_EXECUTION, mainWorkflowExecutionId));
return Optional
.ofNullable(workFlowTaskRepository.findByWorkFlowExecutionIdAndWorkFlowTaskDefinitionId(
Expand All @@ -96,7 +96,8 @@ private WorkFlowTaskExecution getWorkFlowTaskExecution(UUID mainWorkflowExecutio

private String getTaskLog(UUID mainWorkflowExecutionId, String taskName) {
WorkFlowTaskExecution workFlowTaskExecution = getWorkFlowTaskExecution(mainWorkflowExecutionId, taskName);
return workFlowTaskExecution.getWorkFlowTaskExecutionLog().getLog();
return Optional.ofNullable(workFlowTaskExecution.getWorkFlowTaskExecutionLog())
.map(WorkFlowTaskExecutionLog::getLog).orElse("");
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.redhat.parodos.workflow.execution.service;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import com.redhat.parodos.common.exceptions.ResourceNotFoundException;
Expand Down Expand Up @@ -67,7 +68,7 @@ void getLog_when_workflowExecutionLogIsFound_then_return_log() {
}

@Test
void getLog_when_workflowExecutionLogIsNotFound_then_throwException() {
void getLog_when_workflowTaskExecutionIsNotFound_then_throwException() {
UUID mainWorkflowExecutionId = UUID.randomUUID();
WorkFlowDefinition workFlowDefinition = createTestWorkflowDefinition();
when(workFlowTaskDefinitionRepository.findFirstByName(anyString()))
Expand All @@ -80,6 +81,19 @@ void getLog_when_workflowExecutionLogIsNotFound_then_throwException() {
() -> workFlowLogService.getLog(mainWorkflowExecutionId, "test-task"));
}

@Test
void getLog_when_workflowExecutionLogIsNotFound_then_returnEmpty() {
UUID mainWorkflowExecutionId = UUID.randomUUID();
WorkFlowDefinition workFlowDefinition = createTestWorkflowDefinition();
when(workFlowTaskDefinitionRepository.findFirstByName(anyString()))
.thenReturn(createTestTaskDefinition(workFlowDefinition));
when(workFlowRepository.findFirstByMainWorkFlowExecutionIdAndWorkFlowDefinitionId(any(), any()))
.thenReturn(createTestExecution(workFlowDefinition));
when(workFlowTaskRepository.findByWorkFlowExecutionIdAndWorkFlowTaskDefinitionId(any(), any()))
.thenReturn(List.of(createTestTaskExecution(UUID.randomUUID(), UUID.randomUUID(), null)));
assertEquals("", workFlowLogService.getLog(mainWorkflowExecutionId, "test-task"));
}

@Test
void writeLog_when_workflowExecutionLogIsFound_then_return_save() {
UUID mainWorkflowExecutionId = UUID.randomUUID();
Expand All @@ -101,6 +115,29 @@ void writeLog_when_workflowExecutionLogIsFound_then_return_save() {

}

@Test
void writeLog_when_workflowIsMain_then_return_save() {
UUID mainWorkflowExecutionId = UUID.randomUUID();
WorkFlowDefinition workFlowDefinition = createTestWorkflowDefinition();
WorkFlowTaskExecutionLog workFlowTaskExecutionLog = createTestTaskExecutionLog();
when(workFlowTaskDefinitionRepository.findFirstByName(anyString()))
.thenReturn(createTestTaskDefinition(workFlowDefinition));
when(workFlowRepository.findFirstByMainWorkFlowExecutionIdAndWorkFlowDefinitionId(any(), any()))
.thenReturn(null);
when(workFlowRepository.findById(mainWorkflowExecutionId))
.thenReturn(Optional.of(createTestExecution(workFlowDefinition)));
when(workFlowTaskRepository.findByWorkFlowExecutionIdAndWorkFlowTaskDefinitionId(any(), any())).thenReturn(
List.of(createTestTaskExecution(UUID.randomUUID(), UUID.randomUUID(), workFlowTaskExecutionLog)));
workFlowLogService.writeLog(mainWorkflowExecutionId, "test-task",
WorkFlowTaskLog.builder().workFlowLoglevel(WorkFlowLogLevel.INFO).logText("test-log1").build());

ArgumentCaptor<WorkFlowTaskExecution> argument = ArgumentCaptor.forClass(WorkFlowTaskExecution.class);
verify(workFlowTaskRepository, times(1)).save(argument.capture());
assertThat(argument.getValue().getWorkFlowTaskExecutionLog().getLog()).startsWith("test-log\n")
.endsWith("\u001B[32mINFO\u001B[39m test-log1");

}

private WorkFlowDefinition createTestWorkflowDefinition() {
WorkFlowDefinition workFlowDefinition = WorkFlowDefinition.builder().name("test-workflow").build();
workFlowDefinition.setId(UUID.randomUUID());
Expand Down