[FINERACT-1678] COB business step order fix

This commit is contained in:
taskain7
2023-02-08 09:21:50 +01:00
committed by Arnold Gálovics
parent f8eacbba88
commit f5687750ff
12 changed files with 114 additions and 47 deletions
@@ -30,7 +30,9 @@ import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;
import org.apache.fineract.cob.data.BusinessStepNameAndOrder;
import org.apache.fineract.cob.domain.BatchBusinessStep;
import org.apache.fineract.cob.domain.BatchBusinessStepRepository;
import org.apache.fineract.cob.exceptions.BusinessStepException;
@@ -69,7 +71,7 @@ public class COBBusinessStepServiceStepDefinitions implements En {
private Class clazz;
private String jobName;
private BatchBusinessStep batchBusinessStep = mock(BatchBusinessStep.class);
private TreeMap<Long, String> resultMap;
private Set<BusinessStepNameAndOrder> resultSet;
public COBBusinessStepServiceStepDefinitions() {
Given("/^The COBBusinessStepService.run method with executeMap (.*)$/", (String executionMap) -> {
@@ -136,7 +138,7 @@ public class COBBusinessStepServiceStepDefinitions implements En {
});
When("COBBusinessStepService.getCOBBusinessStepMap method executed", () -> {
resultMap = this.businessStepService.getCOBBusinessStepMap(this.clazz, this.jobName);
resultSet = this.businessStepService.getCOBBusinessSteps(this.clazz, this.jobName);
});
Then("The COBBusinessStepService.run result should match", () -> {
@@ -162,19 +164,19 @@ public class COBBusinessStepServiceStepDefinitions implements En {
Then("The COBBusinessStepService.getCOBBusinessStepMap result exception", () -> {
assertThrows(BeanCreationException.class, () -> {
this.businessStepService.getCOBBusinessStepMap(this.clazz, this.jobName);
this.businessStepService.getCOBBusinessSteps(this.clazz, this.jobName);
});
ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT);
});
Then("The COBBusinessStepService.getCOBBusinessStepMap result should match", () -> {
assertEquals(1, resultMap.size());
assertEquals("test", resultMap.get(1L));
assertEquals(1, resultSet.size());
assertEquals("test", resultSet.stream().findFirst().get().getStepName());
ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT);
});
Then("The COBBusinessStepService.getCOBBusinessStepMap result empty", () -> {
assertEquals(0, resultMap.size());
assertEquals(0, resultSet.size());
ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT);
});
@@ -25,13 +25,17 @@ import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import com.google.gson.Gson;
import io.cucumber.java8.En;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.fineract.cob.COBBusinessStepService;
import org.apache.fineract.cob.data.BusinessStepNameAndOrder;
import org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper;
import org.apache.fineract.infrastructure.jobs.service.JobName;
import org.apache.fineract.infrastructure.springbatch.PropertyService;
import org.mockito.Mockito;
@@ -46,11 +50,12 @@ public class LoanCOBPartitionerStepDefinitions implements En {
COBBusinessStepService cobBusinessStepService = mock(COBBusinessStepService.class);
JobOperator jobOperator = mock(JobOperator.class);
JobExplorer jobExplorer = mock(JobExplorer.class);
private final Gson gson = GoogleGsonSerializerHelper.createSimpleGson();
List<Long> loanIds;
private LoanCOBPartitioner loanCOBPartitioner;
private TreeMap<Long, String> cobBusinessMap = new TreeMap<>();
private Set<BusinessStepNameAndOrder> cobBusinessSteps = new HashSet<>();
private Map<String, ExecutionContext> resultItem;
private String action;
@@ -61,20 +66,20 @@ public class LoanCOBPartitionerStepDefinitions implements En {
this.action = action;
lenient().when(propertyService.getPartitionSize(LoanCOBConstant.JOB_NAME)).thenReturn(2);
if ("empty steps".equals(action)) {
lenient().when(cobBusinessStepService.getCOBBusinessStepMap(LoanCOBBusinessStep.class, LoanCOBConstant.LOAN_COB_JOB_NAME))
.thenReturn(new TreeMap<>());
lenient().when(cobBusinessStepService.getCOBBusinessSteps(LoanCOBBusinessStep.class, LoanCOBConstant.LOAN_COB_JOB_NAME))
.thenReturn(Collections.emptySet());
lenient().when(jobExplorer.findRunningJobExecutions(JobName.LOAN_COB.name())).thenReturn(Set.of(new JobExecution(3L)));
lenient().when(jobOperator.stop(3L)).thenReturn(Boolean.TRUE);
} else if ("empty loanIds".equals(action)) {
cobBusinessMap.put(1L, "Business step");
lenient().when(cobBusinessStepService.getCOBBusinessStepMap(LoanCOBBusinessStep.class, LoanCOBConstant.LOAN_COB_JOB_NAME))
.thenReturn(cobBusinessMap);
cobBusinessSteps.add(new BusinessStepNameAndOrder("Business step", 1L));
lenient().when(cobBusinessStepService.getCOBBusinessSteps(LoanCOBBusinessStep.class, LoanCOBConstant.LOAN_COB_JOB_NAME))
.thenReturn(cobBusinessSteps);
loanIds = new ArrayList<>();
lenient().when(jobExplorer.findRunningJobExecutions(JobName.LOAN_COB.name())).thenThrow(new RuntimeException("fail"));
} else if ("good".equals(action)) {
cobBusinessMap.put(1L, "Business step");
lenient().when(cobBusinessStepService.getCOBBusinessStepMap(LoanCOBBusinessStep.class, LoanCOBConstant.LOAN_COB_JOB_NAME))
.thenReturn(cobBusinessMap);
cobBusinessSteps.add(new BusinessStepNameAndOrder("Business step", 1L));
lenient().when(cobBusinessStepService.getCOBBusinessSteps(LoanCOBBusinessStep.class, LoanCOBConstant.LOAN_COB_JOB_NAME))
.thenReturn(cobBusinessSteps);
loanIds = List.of(1L, 2L, 3L);
}
loanCOBPartitioner = new LoanCOBPartitioner(propertyService, cobBusinessStepService, jobOperator, jobExplorer, loanIds);
@@ -92,14 +97,20 @@ public class LoanCOBPartitionerStepDefinitions implements En {
verify(jobOperator, Mockito.times(0)).stop(Mockito.anyLong());
assertEquals(2, resultItem.size());
assertTrue(resultItem.containsKey(LoanCOBPartitioner.PARTITION_PREFIX + "1"));
assertEquals(cobBusinessMap,
resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "1").get(LoanCOBConstant.BUSINESS_STEP_MAP));
Set<BusinessStepNameAndOrder> businessSteps = (Set<BusinessStepNameAndOrder>) resultItem
.get(LoanCOBPartitioner.PARTITION_PREFIX + "1").get(LoanCOBConstant.BUSINESS_STEPS);
assertEquals(cobBusinessSteps.stream().findFirst().get().getStepOrder(),
businessSteps.stream().findFirst().get().getStepOrder());
assertEquals(cobBusinessSteps.stream().findFirst().get().getStepName(),
businessSteps.stream().findFirst().get().getStepName());
assertEquals(2, ((List) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "1").get(LoanCOBConstant.LOAN_IDS)).size());
assertEquals(1L, ((List) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "1").get(LoanCOBConstant.LOAN_IDS)).get(0));
assertEquals(2L, ((List) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "1").get(LoanCOBConstant.LOAN_IDS)).get(1));
assertTrue(resultItem.containsKey(LoanCOBPartitioner.PARTITION_PREFIX + "2"));
assertEquals(cobBusinessMap,
resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "2").get(LoanCOBConstant.BUSINESS_STEP_MAP));
assertEquals(cobBusinessSteps.stream().findFirst().get().getStepOrder(),
businessSteps.stream().findFirst().get().getStepOrder());
assertEquals(cobBusinessSteps.stream().findFirst().get().getStepName(),
businessSteps.stream().findFirst().get().getStepName());
assertEquals(1, ((List) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "2").get(LoanCOBConstant.LOAN_IDS)).size());
assertEquals(3L, ((List) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "2").get(LoanCOBConstant.LOAN_IDS)).get(0));
}
@@ -20,12 +20,15 @@ package org.apache.fineract.cob.loan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import io.cucumber.java8.En;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Collections;
import java.util.TreeMap;
import org.apache.fineract.cob.COBBusinessStepService;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
@@ -46,8 +49,6 @@ public class LoanItemProcessorStepDefinitions implements En {
private Loan resultItem;
private TreeMap<Long, String> treeMap = mock(TreeMap.class);
public LoanItemProcessorStepDefinitions() {
Given("/^The LoanItemProcessor.process method with item (.*)$/", (String loanItem) -> {
JobExecution jobExecution = new JobExecution(1L);
@@ -55,7 +56,7 @@ public class LoanItemProcessorStepDefinitions implements En {
LocalDate.now(ZoneId.systemDefault()).toString());
StepExecution stepExecution = new StepExecution("test", jobExecution);
ExecutionContext stepExecutionContext = new ExecutionContext();
stepExecutionContext.put(LoanCOBConstant.BUSINESS_STEP_MAP, treeMap);
stepExecutionContext.put(LoanCOBConstant.BUSINESS_STEPS, Collections.emptySet());
stepExecution.setExecutionContext(stepExecutionContext);
loanItemProcessor.beforeStep(stepExecution);
@@ -65,8 +66,8 @@ public class LoanItemProcessorStepDefinitions implements En {
this.loanItem = loan;
}
lenient().when(this.cobBusinessStepService.run(treeMap, null)).thenThrow(new RuntimeException("fail"));
lenient().when(this.cobBusinessStepService.run(treeMap, loan)).thenReturn(processedLoan);
lenient().when(this.cobBusinessStepService.run(any(TreeMap.class), eq(null))).thenThrow(new RuntimeException("fail"));
lenient().when(this.cobBusinessStepService.run(any(TreeMap.class), eq(loan))).thenReturn(processedLoan);
});