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

Commit

Permalink
WorkFlowDefintion: increase test coverage
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 Apr 19, 2023
1 parent d5f89a8 commit 6c5cde3
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public void saveWorkFlowChecker(String workFlowTaskName, String workFlowCheckerN
private void getWorksFromWorkDefinition(List<WorkFlowWorkDefinition> workFlowWorkDefinitions,
CopyOnWriteArrayList<WorkDefinitionResponseDTO> responseDTOs) {
workFlowWorkDefinitions.forEach(workFlowWorkDefinition -> {

WorkType workType = workFlowWorkDefinition.getWorkDefinitionType();
if (workType == null) {
return;
Expand All @@ -255,6 +256,7 @@ private void getWorksFromWorkDefinition(List<WorkFlowWorkDefinition> workFlowWor
workFlowWorkDefinition.getWorkDefinitionId());
return;
}
log.error("Here is a change");
List<WorkFlowWorkDefinition> wdWorkFlowWorkDependencies = workFlowWorkRepository
.findByWorkFlowDefinitionIdOrderByCreateDateAsc(wd.get().getId());

Expand Down Expand Up @@ -284,7 +286,9 @@ private List<WorkDefinitionResponseDTO> buildWorkFlowWorksDTOs(WorkFlowDefinitio
this.getWorksFromWorkDefinition(workFlowWorkDefinitions, workDefinitionResponseDTOs);

// fill in subsequent workUnits
for (int i = 1; i < workDefinitionResponseDTOs.size(); i++) {
// this responseSize is like this because we modify the size of the workDefinitionResponseDTO
int responseSize = workDefinitionResponseDTOs.size();
for (int i = 1; i < responseSize; i++) {
if (workDefinitionResponseDTOs.get(i).getWorkType().equalsIgnoreCase(WorkType.WORKFLOW.name())) {

workFlowWorksStartIndex.put(workDefinitionResponseDTOs.get(i).getName(),
Expand All @@ -306,8 +310,9 @@ private List<WorkDefinitionResponseDTO> buildWorkFlowWorksDTOs(WorkFlowDefinitio
for (int k = workFlowWorksStartIndex
.get(workDefinitionResponseDTOs.get(j).getName()); k < workFlowWorksStartIndex
.get(workDefinitionResponseDTOs.get(j).getName())
+ workDefinitionResponseDTOs.get(j).getNumberOfWorkUnits(); k++) {
tmpList.add(workDefinitionResponseDTOs.get(k));
+ workDefinitionResponseDTOs.get(j).getNumberOfWorkUnits() && k <workDefinitionResponseDTOs.size() ; k++) {

tmpList.add(workDefinitionResponseDTOs.get(k));
}
workDefinitionResponseDTOs.get(j).setWorks(tmpList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.redhat.parodos.workflow.definition.entity.WorkFlowCheckerMappingDefinition;
import com.redhat.parodos.workflow.definition.entity.WorkFlowPropertiesDefinition;
import com.redhat.parodos.workflow.definition.entity.WorkFlowWorkDefinition;
import com.redhat.parodos.workflow.definition.repository.WorkFlowCheckerMappingDefinitionRepository;
import com.redhat.parodos.workflow.definition.repository.WorkFlowWorkRepository;
import com.redhat.parodos.workflow.enums.WorkFlowProcessingType;
Expand All @@ -27,6 +28,7 @@
import com.redhat.parodos.workflow.definition.entity.WorkFlowTaskDefinition;
import com.redhat.parodos.workflow.definition.repository.WorkFlowDefinitionRepository;
import com.redhat.parodos.workflow.definition.repository.WorkFlowTaskDefinitionRepository;
import com.redhat.parodos.workflow.enums.WorkType;
import com.redhat.parodos.workflow.parameter.WorkParameter;
import com.redhat.parodos.workflow.parameter.WorkParameterType;
import com.redhat.parodos.workflow.util.WorkFlowDTOUtil;
Expand Down Expand Up @@ -222,6 +224,64 @@ public void getWorkFlowDefinitionByNameWithValidNameTest() {
Mockito.verify(this.workFlowDefinitionRepository, Mockito.times(1)).findFirstByName(any());
}

@Test
public void getWorkFlowDefinitionByNameWithMasterWorkflow() {
// given
WorkFlowDefinition masterWorkFlow = sampleWorkFlowDefinition(TEST);
WorkFlowWorkDefinition workFlowWorkDefinition = sampleWorkFlowWorkDefinition("workTest");
Mockito.when(this.workFlowDefinitionRepository.findFirstByName(any())).thenReturn(masterWorkFlow);

Mockito.when(this.workFlowDefinitionRepository.findById(Mockito.any()))
.thenReturn(Optional.of(sampleWorkFlowDefinition("SubWorkFlow")));

Mockito.when(this.workFlowWorkRepository.findByWorkFlowDefinitionIdOrderByCreateDateAsc(Mockito.any()))
.thenReturn(List.of(workFlowWorkDefinition));

// when
WorkFlowDefinitionResponseDTO result = this.workFlowDefinitionService.getWorkFlowDefinitionByName(TEST);

// then
assertNotNull(result);
assertEquals(result.getName(), TEST);

Mockito.verify(this.workFlowDefinitionRepository, Mockito.times(1)).findFirstByName(any());
Mockito.when(this.workFlowDefinitionRepository.findFirstByName(any()))
.thenReturn(sampleWorkFlowDefinition(TEST));

assertEquals(result.getWorks().size(), 1);
assertEquals(result.getWorks().get(0).getName(), "SubWorkFlow");
assertEquals(result.getWorks().get(0).getWorkType(), WorkType.WORKFLOW.toString());
}


@Test
public void getWorkFlowDefinitionByNameWithEmptyMasterWorkflow() {
// given
WorkFlowDefinition masterWorkFlow = sampleWorkFlowDefinition(TEST);
WorkFlowWorkDefinition workFlowWorkDefinition = sampleWorkFlowWorkDefinition("workTest");
Mockito.when(this.workFlowDefinitionRepository.findFirstByName(any())).thenReturn(masterWorkFlow);

Mockito.when(this.workFlowDefinitionRepository.findById(Mockito.any()))
.thenReturn(Optional.empty());

Mockito.when(this.workFlowWorkRepository.findByWorkFlowDefinitionIdOrderByCreateDateAsc(Mockito.any()))
.thenReturn(List.of(workFlowWorkDefinition));

// when
WorkFlowDefinitionResponseDTO result = this.workFlowDefinitionService.getWorkFlowDefinitionByName(TEST);

// then
assertNotNull(result);
assertEquals(result.getName(), TEST);

Mockito.verify(this.workFlowDefinitionRepository, Mockito.times(1)).findFirstByName(any());
Mockito.when(this.workFlowDefinitionRepository.findFirstByName(any()))
.thenReturn(sampleWorkFlowDefinition(TEST));

assertEquals(result.getWorks().size(), 0);
}


@Test
public void getWorkFlowDefinitionByNameWithInvalidNameTest() {
// given
Expand Down Expand Up @@ -345,6 +405,14 @@ private WorkFlowTaskDefinition sampleWorkFlowTaskDefinition(WorkFlowDefinition w
return workFlowTaskDefinition;
}

private WorkFlowWorkDefinition sampleWorkFlowWorkDefinition(String name) {
WorkFlowWorkDefinition workFlowWorkDefinition = WorkFlowWorkDefinition.builder().build();
workFlowWorkDefinition.setWorkFlowDefinition(sampleWorkFlowDefinition(name));
workFlowWorkDefinition.setWorkDefinitionType(WorkType.WORKFLOW);
workFlowWorkDefinition.setId(UUID.randomUUID());
return workFlowWorkDefinition;
}

private WorkFlowDefinitionServiceImpl getWorkflowDefinitionService() {
return new WorkFlowDefinitionServiceImpl(this.workFlowDefinitionRepository,
this.workFlowTaskDefinitionRepository, this.workFlowCheckerMappingDefinitionRepository,
Expand Down

0 comments on commit 6c5cde3

Please sign in to comment.