[FINERACT-1678] Exclude loan IDs from execution context
This commit is contained in:
+10
-3
@@ -20,6 +20,8 @@ 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.anyLong;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -27,9 +29,9 @@ import static org.mockito.Mockito.verify;
|
||||
import io.cucumber.java8.En;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.cob.data.LoanCOBParameter;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLockRepository;
|
||||
import org.apache.fineract.cob.domain.LockOwner;
|
||||
@@ -37,6 +39,7 @@ import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.config.FineractProperties;
|
||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
@@ -53,7 +56,9 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
|
||||
private FineractProperties fineractProperties = mock(FineractProperties.class);
|
||||
private JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||
private FineractProperties.FineractQueryProperties fineractQueryProperties = mock(FineractProperties.FineractQueryProperties.class);
|
||||
private ApplyLoanLockTasklet applyLoanLockTasklet = new ApplyLoanLockTasklet(accountLockRepository, fineractProperties, jdbcTemplate);
|
||||
private LoanRepository loanRepository = mock(LoanRepository.class);
|
||||
private ApplyLoanLockTasklet applyLoanLockTasklet = new ApplyLoanLockTasklet(accountLockRepository, fineractProperties, jdbcTemplate,
|
||||
loanRepository);
|
||||
private RepeatStatus resultItem;
|
||||
private StepContribution stepContribution;
|
||||
|
||||
@@ -65,7 +70,9 @@ public class ApplyLoanLockTaskletStepDefinitions implements En {
|
||||
ThreadLocalContextUtil.setBusinessDates(businessDateMap);
|
||||
StepExecution stepExecution = new StepExecution("test", null);
|
||||
ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.put(LoanCOBConstant.LOAN_IDS, new ArrayList<>(List.of(1L, 2L, 3L, 4L)));
|
||||
executionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, new LoanCOBParameter(1L, 4L));
|
||||
lenient().when(this.loanRepository.findAllNonClosedLoansBehindOrNullByMinAndMaxLoanId(anyLong(), anyLong(), any()))
|
||||
.thenReturn(List.of(1L, 2L, 3L, 4L));
|
||||
stepExecution.setExecutionContext(executionContext);
|
||||
this.stepContribution = new StepContribution(stepExecution);
|
||||
|
||||
|
||||
+45
-64
@@ -20,8 +20,6 @@ package org.apache.fineract.cob.loan;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -33,6 +31,7 @@ import java.time.ZoneId;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.cob.data.LoanCOBParameter;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLock;
|
||||
import org.apache.fineract.cob.domain.LoanAccountLockRepository;
|
||||
import org.apache.fineract.cob.domain.LockOwner;
|
||||
@@ -46,17 +45,17 @@ import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
|
||||
public class FetchAndLockLoanStepDefinitions implements En {
|
||||
|
||||
private final LoanAccountLockRepository loanAccountLockRepository = mock(LoanAccountLockRepository.class);
|
||||
|
||||
private final RetrieveLoanIdService retrieveLoanIdService = mock(RetrieveLoanIdService.class);
|
||||
private final FineractProperties fineractProperties = mock(FineractProperties.class);
|
||||
private final FineractProperties.FineractQueryProperties fineractQueryProperties = mock(
|
||||
FineractProperties.FineractQueryProperties.class);
|
||||
StepContribution contribution;
|
||||
private FetchAndLockLoanTasklet fetchAndLockLoanTasklet;
|
||||
private LockLoanTasklet lockLoanTasklet;
|
||||
private String action;
|
||||
private RepeatStatus result;
|
||||
private JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||
@@ -69,105 +68,87 @@ public class FetchAndLockLoanStepDefinitions implements En {
|
||||
ThreadLocalContextUtil.setBusinessDates(businessDateMap);
|
||||
this.action = action;
|
||||
|
||||
JobExecution jobExecution = new JobExecution(1L);
|
||||
StepExecution stepExecution = new StepExecution("step", jobExecution);
|
||||
contribution = new StepContribution(stepExecution);
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.BUSINESS_DATE_PARAMETER_NAME,
|
||||
LocalDate.now(ZoneId.systemDefault()).toString());
|
||||
|
||||
if ("empty loanIds".equals(action)) {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(Collections.emptyList());
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.LOAN_COB_PARAMETER,
|
||||
new LoanCOBParameter(0L, 0L));
|
||||
} else if ("good".equals(action)) {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(List.of(1L, 2L, 3L));
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.LOAN_COB_PARAMETER,
|
||||
new LoanCOBParameter(1L, 3L));
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(loanAccountLockRepository.findAllByLoanIdIn(Mockito.anyList())).thenReturn(Collections.emptyList());
|
||||
} else if ("soft lock".equals(action)) {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(List.of(1L, 2L, 3L));
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.LOAN_COB_PARAMETER,
|
||||
new LoanCOBParameter(1L, 3L));
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(loanAccountLockRepository.findAllByLoanIdIn(Mockito.anyList())).thenReturn(
|
||||
List.of(new LoanAccountLock(1L, LockOwner.LOAN_COB_PARTITIONING, LocalDate.now(ZoneId.systemDefault()))));
|
||||
} else if ("inline cob".equals(action)) {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(List.of(1L, 2L, 3L));
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.LOAN_COB_PARAMETER,
|
||||
new LoanCOBParameter(1L, 3L));
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(loanAccountLockRepository.findAllByLoanIdIn(Mockito.anyList())).thenReturn(
|
||||
List.of(new LoanAccountLock(2L, LockOwner.LOAN_INLINE_COB_PROCESSING, LocalDate.now(ZoneId.systemDefault()))));
|
||||
} else if ("chunk processing".equals(action)) {
|
||||
lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(List.of(1L, 2L, 3L));
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.LOAN_COB_PARAMETER,
|
||||
new LoanCOBParameter(1L, 3L));
|
||||
lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties);
|
||||
lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000);
|
||||
lenient().when(loanAccountLockRepository.findAllByLoanIdIn(Mockito.anyList())).thenReturn(
|
||||
List.of(new LoanAccountLock(3L, LockOwner.LOAN_COB_CHUNK_PROCESSING, LocalDate.now(ZoneId.systemDefault()))));
|
||||
}
|
||||
|
||||
JobExecution jobExecution = new JobExecution(1L);
|
||||
StepExecution stepExecution = new StepExecution("step", jobExecution);
|
||||
contribution = new StepContribution(stepExecution);
|
||||
contribution.getStepExecution().getJobExecution().getExecutionContext().put(LoanCOBConstant.BUSINESS_DATE_PARAMETER_NAME,
|
||||
LocalDate.now(ZoneId.systemDefault()).toString());
|
||||
fetchAndLockLoanTasklet = new FetchAndLockLoanTasklet(loanAccountLockRepository, retrieveLoanIdService, fineractProperties,
|
||||
jdbcTemplate);
|
||||
lockLoanTasklet = new LockLoanTasklet(jdbcTemplate);
|
||||
});
|
||||
|
||||
When("FetchAndLockLoanTasklet.execute method executed", () -> {
|
||||
result = this.fetchAndLockLoanTasklet.execute(contribution, null);
|
||||
result = this.lockLoanTasklet.execute(contribution, null);
|
||||
});
|
||||
|
||||
Then("FetchAndLockLoanTasklet.execute result should match", () -> {
|
||||
if ("empty steps".equals(action)) {
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
} else if ("good".equals(action)) {
|
||||
verify(jdbcTemplate).batchUpdate(anyString(), any(), anyInt(), any());
|
||||
verify(jdbcTemplate).update(anyString(), (PreparedStatementSetter) any());
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
assertEquals(3,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.size());
|
||||
assertEquals(1L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(0));
|
||||
assertEquals(2L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(1));
|
||||
assertEquals(3L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(2));
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) contribution.getStepExecution().getJobExecution()
|
||||
.getExecutionContext().get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(2, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
assertEquals(1L, loanCOBParameter.getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameter.getMaxLoanId());
|
||||
} else if ("soft lock".equals(action)) {
|
||||
verify(jdbcTemplate).batchUpdate(anyString(), any(), anyInt(), any());
|
||||
verify(jdbcTemplate).update(anyString(), (PreparedStatementSetter) any());
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
assertEquals(3,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.size());
|
||||
assertEquals(1L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(0));
|
||||
assertEquals(2L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(1));
|
||||
assertEquals(3L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(2));
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) contribution.getStepExecution().getJobExecution()
|
||||
.getExecutionContext().get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(2, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
assertEquals(1L, loanCOBParameter.getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameter.getMaxLoanId());
|
||||
} else if ("inline cob".equals(action)) {
|
||||
verify(jdbcTemplate).batchUpdate(anyString(), any(), anyInt(), any());
|
||||
verify(jdbcTemplate).update(anyString(), (PreparedStatementSetter) any());
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
assertEquals(2,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.size());
|
||||
assertEquals(1L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(0));
|
||||
assertEquals(3L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(1));
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) contribution.getStepExecution().getJobExecution()
|
||||
.getExecutionContext().get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(2, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
assertEquals(1L, loanCOBParameter.getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameter.getMaxLoanId());
|
||||
} else if ("chunk processing".equals(action)) {
|
||||
verify(jdbcTemplate).batchUpdate(anyString(), any(), anyInt(), any());
|
||||
verify(jdbcTemplate).update(anyString(), (PreparedStatementSetter) any());
|
||||
assertEquals(RepeatStatus.FINISHED, result);
|
||||
assertEquals(2,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.size());
|
||||
assertEquals(1L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(0));
|
||||
assertEquals(2L,
|
||||
((List) contribution.getStepExecution().getJobExecution().getExecutionContext().get(LoanCOBConstant.LOAN_IDS))
|
||||
.get(1));
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) contribution.getStepExecution().getJobExecution()
|
||||
.getExecutionContext().get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(2, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
assertEquals(1L, loanCOBParameter.getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameter.getMaxLoanId());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+18
-11
@@ -28,11 +28,11 @@ import com.google.gson.Gson;
|
||||
import io.cucumber.java8.En;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.apache.fineract.cob.COBBusinessStepService;
|
||||
import org.apache.fineract.cob.data.BusinessStepNameAndOrder;
|
||||
import org.apache.fineract.cob.data.LoanCOBParameter;
|
||||
import org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper;
|
||||
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
||||
import org.apache.fineract.infrastructure.springbatch.PropertyService;
|
||||
@@ -50,7 +50,7 @@ public class LoanCOBPartitionerStepDefinitions implements En {
|
||||
JobExplorer jobExplorer = mock(JobExplorer.class);
|
||||
private final Gson gson = GoogleGsonSerializerHelper.createSimpleGson();
|
||||
|
||||
List<Long> loanIds;
|
||||
LoanCOBParameter loanIds;
|
||||
private LoanCOBPartitioner loanCOBPartitioner;
|
||||
|
||||
private Set<BusinessStepNameAndOrder> cobBusinessSteps = new HashSet<>();
|
||||
@@ -68,17 +68,17 @@ public class LoanCOBPartitionerStepDefinitions implements En {
|
||||
.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);
|
||||
loanIds = Collections.emptyList();
|
||||
loanIds = null;
|
||||
} else if ("empty loanIds".equals(action)) {
|
||||
cobBusinessSteps.add(new BusinessStepNameAndOrder("Business step", 1L));
|
||||
lenient().when(cobBusinessStepService.getCOBBusinessSteps(LoanCOBBusinessStep.class, LoanCOBConstant.LOAN_COB_JOB_NAME))
|
||||
.thenReturn(cobBusinessSteps);
|
||||
loanIds = Collections.emptyList();
|
||||
loanIds = null;
|
||||
} else if ("good".equals(action)) {
|
||||
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);
|
||||
loanIds = new LoanCOBParameter(1L, 3L);
|
||||
}
|
||||
loanCOBPartitioner = new LoanCOBPartitioner(propertyService, cobBusinessStepService, jobOperator, jobExplorer, loanIds);
|
||||
});
|
||||
@@ -101,16 +101,21 @@ public class LoanCOBPartitionerStepDefinitions implements En {
|
||||
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));
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "1")
|
||||
.get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(1, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
assertEquals(1L, loanCOBParameter.getMinLoanId());
|
||||
assertEquals(2L, loanCOBParameter.getMaxLoanId());
|
||||
assertTrue(resultItem.containsKey(LoanCOBPartitioner.PARTITION_PREFIX + "2"));
|
||||
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));
|
||||
loanCOBParameter = (LoanCOBParameter) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "2")
|
||||
.get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(0, loanCOBParameter.getMaxLoanId() - loanCOBParameter.getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameter.getMinLoanId());
|
||||
assertEquals(3L, loanCOBParameter.getMaxLoanId());
|
||||
} else if ("empty loanIds".equals(action)) {
|
||||
verify(jobOperator, Mockito.times(0)).stop(Mockito.anyLong());
|
||||
assertEquals(1, resultItem.size());
|
||||
@@ -121,7 +126,9 @@ public class LoanCOBPartitionerStepDefinitions implements En {
|
||||
businessSteps.stream().findFirst().get().getStepOrder());
|
||||
assertEquals(cobBusinessSteps.stream().findFirst().get().getStepName(),
|
||||
businessSteps.stream().findFirst().get().getStepName());
|
||||
assertEquals(0, ((List) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "1").get(LoanCOBConstant.LOAN_IDS)).size());
|
||||
LoanCOBParameter loanCOBParameter = (LoanCOBParameter) resultItem.get(LoanCOBPartitioner.PARTITION_PREFIX + "1")
|
||||
.get(LoanCOBConstant.LOAN_COB_PARAMETER);
|
||||
assertEquals(null, loanCOBParameter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+26
-7
@@ -21,15 +21,23 @@ package org.apache.fineract.cob.loan;
|
||||
import static org.junit.Assert.assertNull;
|
||||
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.anyLong;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import io.cucumber.java8.En;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.apache.fineract.cob.data.LoanCOBParameter;
|
||||
import org.apache.fineract.cob.exceptions.LoanReadException;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
@@ -53,18 +61,29 @@ public class LoanItemReaderStepDefinitions implements En {
|
||||
jobExecution.setExecutionContext(jobExecutionContext);
|
||||
StepExecution stepExecution = new StepExecution("test", jobExecution);
|
||||
ExecutionContext stepExecutionContext = new ExecutionContext();
|
||||
List<Long> splitAccounts;
|
||||
if (loanIds.isEmpty()) {
|
||||
splitAccounts = new ArrayList<>();
|
||||
} else {
|
||||
Long minLoanId = null;
|
||||
Long maxLoanId = null;
|
||||
List<Long> splitAccounts = new ArrayList<>();
|
||||
if (!loanIds.isEmpty()) {
|
||||
List<String> splitStr = Splitter.on(',').splitToList(loanIds);
|
||||
splitAccounts = splitStr.stream().map(Long::parseLong).toList();
|
||||
minLoanId = splitAccounts.get(0);
|
||||
maxLoanId = splitAccounts.get(splitAccounts.size() - 1);
|
||||
}
|
||||
stepExecutionContext.put(LoanCOBConstant.LOAN_IDS, new ArrayList<>(splitAccounts));
|
||||
stepExecution.setExecutionContext(stepExecutionContext);
|
||||
stepExecutionContext.put(LoanCOBConstant.LOAN_COB_PARAMETER, new LoanCOBParameter(minLoanId, maxLoanId));
|
||||
jobExecution.setExecutionContext(stepExecutionContext);
|
||||
|
||||
lenient().when(this.loanRepository.findAllNonClosedLoansBehindOrNullByMinAndMaxLoanId(anyLong(), anyLong(), any()))
|
||||
.thenReturn(splitAccounts);
|
||||
|
||||
HashMap<BusinessDateType, LocalDate> businessDates = new HashMap<>();
|
||||
LocalDate businessDate = LocalDate.now(ZoneId.systemDefault());
|
||||
businessDates.put(BusinessDateType.BUSINESS_DATE, businessDate);
|
||||
businessDates.put(BusinessDateType.COB_DATE, businessDate.minusDays(1));
|
||||
ThreadLocalContextUtil.setBusinessDates(businessDates);
|
||||
|
||||
loanItemReader.beforeStep(stepExecution);
|
||||
|
||||
lenient().when(this.loanRepository.findById(0L)).thenReturn(Optional.empty());
|
||||
lenient().when(this.loanRepository.findById(1L)).thenReturn(Optional.of(loan));
|
||||
lenient().when(this.loanRepository.findById(-1L)).thenThrow(new RuntimeException("fail"));
|
||||
|
||||
|
||||
@@ -48,4 +48,3 @@ Feature: COB Reader
|
||||
Examples:
|
||||
|loanIds|
|
||||
|-1 |
|
||||
|0 |
|
||||
|
||||
Reference in New Issue
Block a user