From e7268997bc573f73e4f3b55e86d3895b9c293ebb Mon Sep 17 00:00:00 2001 From: Adam Saghy Date: Thu, 30 Mar 2023 23:31:56 +0200 Subject: [PATCH] FINERACT-1678: Improvements around locking --- .../InternalLoanAccountLockApiResource.java | 5 ++- .../fineract/cob/domain/LoanAccountLock.java | 7 ++-- .../cob/loan/AbstractLoanItemReader.java | 4 --- .../cob/loan/ApplyLoanLockTasklet.java | 28 +++++++++------ .../cob/loan/LoanCOBWorkerConfiguration.java | 17 ++++----- .../fineract/cob/loan/LoanItemReader.java | 3 -- .../InlineLoanCOBExecutorServiceImpl.java | 10 +++--- .../LoanItemListenerStepDefinitions.java | 8 +++-- ...eriodicAccrualEntriesBusinessStepTest.java | 2 ++ .../ApplyLoanLockTaskletStepDefinitions.java | 36 +++++++++++-------- ...CheckLoanRepaymentDueBusinessStepTest.java | 2 ++ ...kLoanRepaymentOverdueBusinessStepTest.java | 2 ++ .../loan/FetchAndLockLoanStepDefinitions.java | 12 +++---- .../loan/LoanItemReaderStepDefinitions.java | 11 +----- ...etLoanDelinquencyTagsBusinessStepTest.java | 2 ++ .../COBBulkEventConfigurationTest.java | 1 + .../PurgeProcessedCommandsTaskletTest.java | 2 ++ .../jobs/PurgeExternalEventsTaskletTest.java | 2 ++ .../SendAsynchronousEventsTaskletTest.java | 2 ++ ...ntDelinquencyRangeEventSerializerTest.java | 2 ++ ...nRepaymentBusinessEventSerializerTest.java | 2 ++ ...tePlatformServiceRangeChangeEventTest.java | 2 ++ .../LoanDelinquencyDomainServiceTest.java | 2 ++ ...nCalculateRepaymentPastDueServiceTest.java | 2 ++ .../features/cob/loan/cob.loan.reader.feature | 23 ++++++------ 25 files changed, 105 insertions(+), 84 deletions(-) diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/api/InternalLoanAccountLockApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/cob/api/InternalLoanAccountLockApiResource.java index 8b8f7eedd..07447a2c3 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/api/InternalLoanAccountLockApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/api/InternalLoanAccountLockApiResource.java @@ -32,6 +32,8 @@ import lombok.extern.slf4j.Slf4j; import org.apache.fineract.cob.domain.LoanAccountLock; import org.apache.fineract.cob.domain.LoanAccountLockRepository; import org.apache.fineract.cob.domain.LockOwner; +import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -69,7 +71,8 @@ public class InternalLoanAccountLockApiResource implements InitializingBean { log.warn(" "); log.warn("------------------------------------------------------------"); - LoanAccountLock loanAccountLock = new LoanAccountLock(loanId, LockOwner.valueOf(lockOwner)); + LoanAccountLock loanAccountLock = new LoanAccountLock(loanId, LockOwner.valueOf(lockOwner), + ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE)); loanAccountLockRepository.save(loanAccountLock); return Response.status(Response.Status.ACCEPTED).build(); } diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLock.java b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLock.java index 7d6266b3d..d8bc192c5 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLock.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/domain/LoanAccountLock.java @@ -29,9 +29,7 @@ import javax.persistence.Table; import javax.persistence.Version; import lombok.Getter; import lombok.NoArgsConstructor; -import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.core.service.DateUtils; -import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @Entity @Table(name = "m_loan_account_locks") @@ -63,11 +61,11 @@ public class LoanAccountLock { @Column(name = "lock_placed_on_cob_business_date") private LocalDate lockPlacedOnCobBusinessDate; - public LoanAccountLock(Long loanId, LockOwner lockOwner) { + public LoanAccountLock(Long loanId, LockOwner lockOwner, LocalDate lockPlacedOnCobBusinessDate) { this.loanId = loanId; this.lockOwner = lockOwner; this.lockPlacedOn = DateUtils.getOffsetDateTimeOfTenant(); - this.lockPlacedOnCobBusinessDate = ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE); + this.lockPlacedOnCobBusinessDate = lockPlacedOnCobBusinessDate; } public void setError(String errorMessage, String stacktrace) { @@ -78,6 +76,5 @@ public class LoanAccountLock { public void setNewLockOwner(LockOwner newLockOwner) { this.lockOwner = newLockOwner; this.lockPlacedOn = DateUtils.getOffsetDateTimeOfTenant(); - this.lockPlacedOnCobBusinessDate = ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemReader.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemReader.java index 1c795065c..13ca8d34c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemReader.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemReader.java @@ -23,7 +23,6 @@ import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.cob.exceptions.LoanAccountWasAlreadyLockedOrProcessed; import org.apache.fineract.cob.exceptions.LoanReadException; import org.apache.fineract.portfolio.loanaccount.domain.Loan; import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository; @@ -51,9 +50,6 @@ public abstract class AbstractLoanItemReader implements ItemReader { try { if (remainingData.size() > 0) { loanId = remainingData.remove(0); - if (alreadyLockedOrProcessedAccounts != null && alreadyLockedOrProcessedAccounts.remove(loanId)) { - throw new LoanAccountWasAlreadyLockedOrProcessed(loanId); - } return loanRepository.findById(loanId).orElseThrow(() -> new LoanNotFoundException(loanId)); } } catch (Exception e) { diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/ApplyLoanLockTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/ApplyLoanLockTasklet.java index 35183807c..66049cf9b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/ApplyLoanLockTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/ApplyLoanLockTasklet.java @@ -30,12 +30,14 @@ import org.apache.fineract.cob.domain.LoanAccountLock; import org.apache.fineract.cob.domain.LoanAccountLockRepository; import org.apache.fineract.cob.domain.LockOwner; import org.apache.fineract.infrastructure.core.config.FineractProperties; +import org.apache.fineract.infrastructure.core.service.DateUtils; import org.jetbrains.annotations.NotNull; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.jdbc.core.JdbcTemplate; @Slf4j @RequiredArgsConstructor @@ -43,6 +45,7 @@ public class ApplyLoanLockTasklet implements Tasklet { private final LoanAccountLockRepository accountLockRepository; private final FineractProperties fineractProperties; + private final JdbcTemplate jdbcTemplate; @Override public RepeatStatus execute(@NotNull StepContribution contribution, @NotNull ChunkContext chunkContext) throws Exception { @@ -61,23 +64,28 @@ public class ApplyLoanLockTasklet implements Tasklet { List toBeProcessedLoanIds = new ArrayList<>(alreadySoftLockedAccountsMap.keySet()); - for (Long loanId : toBeProcessedLoanIds) { - upgradeToHardLock(loanId, alreadySoftLockedAccountsMap); - } + upgradeToHardLock(toBeProcessedLoanIds); toBeProcessedLoanIds.addAll(alreadyLockedByChunkProcessingAccountIds); List alreadyLockedByInlineCOBOrProcessedLoanIds = new ArrayList<>(loanIds); alreadyLockedByInlineCOBOrProcessedLoanIds.removeAll(toBeProcessedLoanIds); - executionContext.put(LoanCOBConstant.ALREADY_LOCKED_BY_INLINE_COB_OR_PROCESSED_LOAN_IDS, - new ArrayList<>(alreadyLockedByInlineCOBOrProcessedLoanIds)); + loanIds.removeAll(alreadyLockedByInlineCOBOrProcessedLoanIds); + return RepeatStatus.FINISHED; } - private void upgradeToHardLock(Long loanId, Map alreadySoftLockedAccountsMap) { - LoanAccountLock loanAccountLock = alreadySoftLockedAccountsMap.get(loanId); - // Upgrade lock - loanAccountLock.setNewLockOwner(LockOwner.LOAN_COB_CHUNK_PROCESSING); - accountLockRepository.save(loanAccountLock); + private void upgradeToHardLock(List accountsToLock) { + jdbcTemplate.batchUpdate(""" + UPDATE m_loan_account_locks SET version= version + 1, lock_owner = ?, lock_placed_on = ? WHERE loan_id = ? + """, accountsToLock, getInClauseParameterSizeLimit(), (ps, id) -> { + ps.setString(1, LockOwner.LOAN_COB_CHUNK_PROCESSING.name()); + ps.setObject(2, DateUtils.getOffsetDateTimeOfTenant()); + ps.setLong(3, id); + }); + } + + private int getInClauseParameterSizeLimit() { + return fineractProperties.getQuery().getInClauseParameterSizeLimit(); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBWorkerConfiguration.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBWorkerConfiguration.java index f9bcd4ea2..9e240bec1 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBWorkerConfiguration.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanCOBWorkerConfiguration.java @@ -38,7 +38,6 @@ import org.springframework.batch.core.configuration.annotation.StepBuilderFactor import org.springframework.batch.core.configuration.annotation.StepScope; import org.springframework.batch.core.job.builder.FlowBuilder; import org.springframework.batch.core.job.flow.Flow; -import org.springframework.batch.core.listener.ExecutionContextPromotionListener; import org.springframework.batch.integration.partition.RemotePartitioningWorkerStepBuilderFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -46,6 +45,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.integration.channel.QueueChannel; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.transaction.support.TransactionTemplate; @Configuration @@ -78,6 +78,8 @@ public class LoanCOBWorkerConfiguration { @Autowired private FineractProperties fineractProperties; + @Autowired + private JdbcTemplate jdbcTemplate; @Bean(name = LoanCOBConstant.LOAN_COB_WORKER_STEP) public Step loanCOBWorkerStep() { @@ -103,13 +105,13 @@ public class LoanCOBWorkerConfiguration { .chunk(propertyService.getChunkSize(JobName.LOAN_COB.name())).reader(cobWorkerItemReader()) .processor(cobWorkerItemProcessor()).writer(cobWorkerItemWriter()).faultTolerant().skip(Exception.class) .skipLimit(propertyService.getChunkSize(JobName.LOAN_COB.name()) + 1).listener(loanItemListener()) - .listener(promotionListener()).listener(samplingStepExecutionListener()).build(); + .listener(samplingStepExecutionListener()).build(); } @Bean @StepScope public Step applyLockStep(@Value("#{stepExecutionContext['partition']}") String partitionName) { - return localStepBuilderFactory.get("Apply lock - Step:" + partitionName).tasklet(applyLock()).listener(promotionListener()).build(); + return localStepBuilderFactory.get("Apply lock - Step:" + partitionName).tasklet(applyLock()).build(); } @Bean @@ -130,7 +132,7 @@ public class LoanCOBWorkerConfiguration { @Bean public ApplyLoanLockTasklet applyLock() { - return new ApplyLoanLockTasklet(accountLockRepository, fineractProperties); + return new ApplyLoanLockTasklet(accountLockRepository, fineractProperties, jdbcTemplate); } @Bean @@ -158,13 +160,6 @@ public class LoanCOBWorkerConfiguration { return repositoryItemWriter; } - @Bean - public ExecutionContextPromotionListener promotionListener() { - ExecutionContextPromotionListener listener = new ExecutionContextPromotionListener(); - listener.setKeys(new String[] { LoanCOBConstant.ALREADY_LOCKED_BY_INLINE_COB_OR_PROCESSED_LOAN_IDS }); - return listener; - } - @Bean public SamplingStepExecutionListener samplingStepExecutionListener() { SamplingStepExecutionListener listener = new SamplingStepExecutionListener(samplingServiceFactory, samplingDataPrinter); diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java index 36bdad5ea..ecb737e83 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java @@ -36,10 +36,7 @@ public class LoanItemReader extends AbstractLoanItemReader { @SuppressWarnings({ "unchecked" }) public void beforeStep(@NotNull StepExecution stepExecution) { ExecutionContext executionContext = stepExecution.getExecutionContext(); - ExecutionContext jobExecutionContext = stepExecution.getJobExecution().getExecutionContext(); List loanIds = (List) executionContext.get(LoanCOBConstant.LOAN_IDS); - setAlreadyLockedOrProcessedAccounts( - (List) jobExecutionContext.get(LoanCOBConstant.ALREADY_LOCKED_BY_INLINE_COB_OR_PROCESSED_LOAN_IDS)); setRemainingData(new ArrayList<>(loanIds)); } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/service/InlineLoanCOBExecutorServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/cob/service/InlineLoanCOBExecutorServiceImpl.java index 661eb001c..d378133fe 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/service/InlineLoanCOBExecutorServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/service/InlineLoanCOBExecutorServiceImpl.java @@ -129,7 +129,7 @@ public class InlineLoanCOBExecutorServiceImpl implements InlineExecutorService loanIds, String jobName, LocalDate businessDate) { - lockLoanAccounts(loanIds); + lockLoanAccounts(loanIds, businessDate); Job inlineLoanCOBJob; try { inlineLoanCOBJob = jobLocator.getJob(jobName); @@ -167,7 +167,7 @@ public class InlineLoanCOBExecutorServiceImpl implements InlineExecutorService getLoanAccountLocks(List loanIds) { + private List getLoanAccountLocks(List loanIds, LocalDate businessDate) { List loanAccountLocks = new ArrayList<>(); List alreadyLockedLoanIds = new ArrayList<>(); loanIds.forEach(loanId -> { @@ -180,7 +180,7 @@ public class InlineLoanCOBExecutorServiceImpl implements InlineExecutorService loanIds) { + private void lockLoanAccounts(List loanIds, LocalDate businessDate) { transactionTemplate.setPropagationBehavior(PROPAGATION_REQUIRES_NEW); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(@NotNull TransactionStatus status) { - List loanAccountLocks = getLoanAccountLocks(loanIds); + List loanAccountLocks = getLoanAccountLocks(loanIds, businessDate); loanAccountLocks.forEach(loanAccountLock -> { loanAccountLock.setNewLockOwner(LockOwner.LOAN_INLINE_COB_PROCESSING); loanAccountLockRepository.save(loanAccountLock); diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/listener/LoanItemListenerStepDefinitions.java b/fineract-provider/src/test/java/org/apache/fineract/cob/listener/LoanItemListenerStepDefinitions.java index b855d7060..773b52180 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/listener/LoanItemListenerStepDefinitions.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/listener/LoanItemListenerStepDefinitions.java @@ -27,6 +27,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.cucumber.java8.En; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.List; import java.util.Optional; import org.apache.fineract.cob.domain.LoanAccountLock; @@ -58,7 +60,7 @@ public class LoanItemListenerStepDefinitions implements En { Given("/^The LoanItemListener.onReadError method (.*)$/", (String action) -> { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); exception = new LoanReadException(1L, new RuntimeException("fail")); - loanAccountLock = new LoanAccountLock(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING); + loanAccountLock = new LoanAccountLock(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING, LocalDate.now(ZoneId.systemDefault())); when(accountLockRepository.findByLoanIdAndLockOwner(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING)) .thenReturn(Optional.of(loanAccountLock)); transactionTemplate.setTransactionManager(mock(PlatformTransactionManager.class)); @@ -80,7 +82,7 @@ public class LoanItemListenerStepDefinitions implements En { Given("/^The LoanItemListener.onProcessError method (.*)$/", (String action) -> { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); exception = new LoanReadException(1L, new RuntimeException("fail")); - loanAccountLock = new LoanAccountLock(2L, LockOwner.LOAN_COB_CHUNK_PROCESSING); + loanAccountLock = new LoanAccountLock(2L, LockOwner.LOAN_COB_CHUNK_PROCESSING, LocalDate.now(ZoneId.systemDefault())); when(accountLockRepository.findByLoanIdAndLockOwner(2L, LockOwner.LOAN_COB_CHUNK_PROCESSING)) .thenReturn(Optional.of(loanAccountLock)); when(loan.getId()).thenReturn(2L); @@ -102,7 +104,7 @@ public class LoanItemListenerStepDefinitions implements En { Given("/^The LoanItemListener.onWriteError method (.*)$/", (String action) -> { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); exception = new LoanReadException(3L, new RuntimeException("fail")); - loanAccountLock = new LoanAccountLock(3L, LockOwner.LOAN_COB_CHUNK_PROCESSING); + loanAccountLock = new LoanAccountLock(3L, LockOwner.LOAN_COB_CHUNK_PROCESSING, LocalDate.now(ZoneId.systemDefault())); when(accountLockRepository.findByLoanIdAndLockOwner(3L, LockOwner.LOAN_COB_CHUNK_PROCESSING)) .thenReturn(Optional.of(loanAccountLock)); when(loan.getId()).thenReturn(3L); diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/AddPeriodicAccrualEntriesBusinessStepTest.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/AddPeriodicAccrualEntriesBusinessStepTest.java index a77f4f0da..0e9cef6b2 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/AddPeriodicAccrualEntriesBusinessStepTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/AddPeriodicAccrualEntriesBusinessStepTest.java @@ -35,6 +35,7 @@ import java.util.Map; import org.apache.commons.lang3.RandomUtils; import org.apache.fineract.cob.exceptions.BusinessStepException; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.exception.MultiException; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -59,6 +60,7 @@ public class AddPeriodicAccrualEntriesBusinessStepTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); underTest = new AddPeriodicAccrualEntriesBusinessStep(loanAccrualPlatformService); diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/ApplyLoanLockTaskletStepDefinitions.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/ApplyLoanLockTaskletStepDefinitions.java index 78b014cff..bc7271c8e 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/ApplyLoanLockTaskletStepDefinitions.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/ApplyLoanLockTaskletStepDefinitions.java @@ -25,10 +25,15 @@ import static org.mockito.Mockito.mock; 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.domain.LoanAccountLock; import org.apache.fineract.cob.domain.LoanAccountLockRepository; import org.apache.fineract.cob.domain.LockOwner; +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; @@ -38,23 +43,29 @@ import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter; public class ApplyLoanLockTaskletStepDefinitions implements En { - ArgumentCaptor valueCaptor = ArgumentCaptor.forClass(LoanAccountLock.class); + ArgumentCaptor valueCaptor = ArgumentCaptor.forClass(List.class); private LoanAccountLockRepository accountLockRepository = mock(LoanAccountLockRepository.class); 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); + private ApplyLoanLockTasklet applyLoanLockTasklet = new ApplyLoanLockTasklet(accountLockRepository, fineractProperties, jdbcTemplate); private RepeatStatus resultItem; private StepContribution stepContribution; public ApplyLoanLockTaskletStepDefinitions() { Given("/^The ApplyLoanLockTasklet.execute method with action (.*)$/", (String action) -> { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + HashMap businessDateMap = new HashMap<>(); + businessDateMap.put(BusinessDateType.COB_DATE, LocalDate.now(ZoneId.systemDefault())); + ThreadLocalContextUtil.setBusinessDates(businessDateMap); StepExecution stepExecution = new StepExecution("test", null); ExecutionContext executionContext = new ExecutionContext(); - executionContext.put(LoanCOBConstant.LOAN_IDS, List.of(1L, 2L, 3L, 4L)); + executionContext.put(LoanCOBConstant.LOAN_IDS, new ArrayList<>(List.of(1L, 2L, 3L, 4L))); stepExecution.setExecutionContext(executionContext); this.stepContribution = new StepContribution(stepExecution); @@ -63,9 +74,10 @@ public class ApplyLoanLockTaskletStepDefinitions implements En { lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000); lenient().when(this.accountLockRepository.findAllByLoanIdIn(Mockito.anyList())).thenThrow(new RuntimeException("fail")); } else { - LoanAccountLock lock1 = new LoanAccountLock(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING); - LoanAccountLock lock2 = new LoanAccountLock(2L, LockOwner.LOAN_COB_PARTITIONING); - LoanAccountLock lock3 = new LoanAccountLock(3L, LockOwner.LOAN_INLINE_COB_PROCESSING); + LoanAccountLock lock1 = new LoanAccountLock(1L, LockOwner.LOAN_COB_CHUNK_PROCESSING, LocalDate.now(ZoneId.systemDefault())); + LoanAccountLock lock2 = new LoanAccountLock(2L, LockOwner.LOAN_COB_PARTITIONING, LocalDate.now(ZoneId.systemDefault())); + LoanAccountLock lock3 = new LoanAccountLock(3L, LockOwner.LOAN_INLINE_COB_PROCESSING, + LocalDate.now(ZoneId.systemDefault())); List accountLocks = List.of(lock1, lock2, lock3); lenient().when(fineractProperties.getQuery()).thenReturn(fineractQueryProperties); lenient().when(fineractQueryProperties.getInClauseParameterSizeLimit()).thenReturn(65000); @@ -80,14 +92,10 @@ public class ApplyLoanLockTaskletStepDefinitions implements En { Then("ApplyLoanLockTasklet.execute result should match", () -> { assertEquals(RepeatStatus.FINISHED, resultItem); - assertEquals(3L, ((List) stepContribution.getStepExecution().getExecutionContext() - .get(LoanCOBConstant.ALREADY_LOCKED_BY_INLINE_COB_OR_PROCESSED_LOAN_IDS)).get(0)); - assertEquals(4L, ((List) stepContribution.getStepExecution().getExecutionContext() - .get(LoanCOBConstant.ALREADY_LOCKED_BY_INLINE_COB_OR_PROCESSED_LOAN_IDS)).get(1)); - verify(this.accountLockRepository, Mockito.times(1)).save(valueCaptor.capture()); - List values = valueCaptor.getAllValues(); - assertEquals(2L, values.get(0).getLoanId()); - assertEquals(LockOwner.LOAN_COB_CHUNK_PROCESSING, values.get(0).getLockOwner()); + verify(this.jdbcTemplate, Mockito.times(1)).batchUpdate(Mockito.anyString(), valueCaptor.capture(), Mockito.anyInt(), + Mockito.any(ParameterizedPreparedStatementSetter.class)); + List values = valueCaptor.getValue(); + assertEquals(2L, values.get(0)); }); Then("throw exception ApplyLoanLockTasklet.execute method", () -> { diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStepTest.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStepTest.java index 828a461be..f21a1754d 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStepTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentDueBusinessStepTest.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Map; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -61,6 +62,7 @@ public class CheckLoanRepaymentDueBusinessStepTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); underTest = new CheckLoanRepaymentDueBusinessStep(configurationDomainService, businessEventNotifierService); diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStepTest.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStepTest.java index 4d117789f..216199b09 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStepTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/CheckLoanRepaymentOverdueBusinessStepTest.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Map; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -61,6 +62,7 @@ public class CheckLoanRepaymentOverdueBusinessStepTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); underTest = new CheckLoanRepaymentOverdueBusinessStep(configurationDomainService, businessEventNotifierService); diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/FetchAndLockLoanStepDefinitions.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/FetchAndLockLoanStepDefinitions.java index 3e82aef45..3f5afdab0 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/FetchAndLockLoanStepDefinitions.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/FetchAndLockLoanStepDefinitions.java @@ -80,20 +80,20 @@ public class FetchAndLockLoanStepDefinitions implements En { lenient().when(retrieveLoanIdService.retrieveLoanIdsNDaysBehind(anyLong(), any())).thenReturn(List.of(1L, 2L, 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))); + 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)); 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))); + 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)); 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))); + 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); diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemReaderStepDefinitions.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemReaderStepDefinitions.java index f8f1758ad..c2b0a8700 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemReaderStepDefinitions.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemReaderStepDefinitions.java @@ -47,18 +47,9 @@ public class LoanItemReaderStepDefinitions implements En { private Loan resultItem; public LoanItemReaderStepDefinitions() { - Given("/^The LoanItemReader.read method with loanIds (.*), lockedAccounts (.*)$/", (String loanIds, String lockedAccounts) -> { + Given("/^The LoanItemReader.read method with loanIds (.*)$/", (String loanIds) -> { JobExecution jobExecution = new JobExecution(1L); ExecutionContext jobExecutionContext = new ExecutionContext(); - List splitLockedAccounts; - if (lockedAccounts.isEmpty()) { - splitLockedAccounts = new ArrayList<>(); - } else { - List splitLockedAccountsStr = Splitter.on(',').splitToList(lockedAccounts); - splitLockedAccounts = splitLockedAccountsStr.stream().map(Long::parseLong).toList(); - } - jobExecutionContext.put(LoanCOBConstant.ALREADY_LOCKED_BY_INLINE_COB_OR_PROCESSED_LOAN_IDS, - new ArrayList<>(splitLockedAccounts)); jobExecution.setExecutionContext(jobExecutionContext); StepExecution stepExecution = new StepExecution("test", jobExecution); ExecutionContext stepExecutionContext = new ExecutionContext(); diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/SetLoanDelinquencyTagsBusinessStepTest.java b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/SetLoanDelinquencyTagsBusinessStepTest.java index 584dde251..555b0bc42 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/SetLoanDelinquencyTagsBusinessStepTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/SetLoanDelinquencyTagsBusinessStepTest.java @@ -37,6 +37,7 @@ import java.util.Map; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomUtils; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.ExternalId; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -82,6 +83,7 @@ public class SetLoanDelinquencyTagsBusinessStepTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); underTest = new SetLoanDelinquencyTagsBusinessStep(loanAccountDomainService); diff --git a/fineract-provider/src/test/java/org/apache/fineract/cob/service/COBBulkEventConfigurationTest.java b/fineract-provider/src/test/java/org/apache/fineract/cob/service/COBBulkEventConfigurationTest.java index 15c0c048c..2f250e3e4 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/cob/service/COBBulkEventConfigurationTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/cob/service/COBBulkEventConfigurationTest.java @@ -79,6 +79,7 @@ public class COBBulkEventConfigurationTest { @BeforeEach public void setUp() throws Exception { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); when(reloaderService.reload(any())).thenAnswer(invocation -> invocation.getArgument(0)); diff --git a/fineract-provider/src/test/java/org/apache/fineract/commands/jobs/PurgeProcessedCommandsTaskletTest.java b/fineract-provider/src/test/java/org/apache/fineract/commands/jobs/PurgeProcessedCommandsTaskletTest.java index c172dfa96..bf02873f4 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/commands/jobs/PurgeProcessedCommandsTaskletTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/commands/jobs/PurgeProcessedCommandsTaskletTest.java @@ -32,6 +32,7 @@ import java.util.Map; import org.apache.fineract.commands.domain.CommandSourceRepository; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -63,6 +64,7 @@ public class PurgeProcessedCommandsTaskletTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); underTest = new PurgeProcessedCommandsTasklet(repository, configurationDomainService); diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/PurgeExternalEventsTaskletTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/PurgeExternalEventsTaskletTest.java index 3aa5e61e9..a956ba405 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/PurgeExternalEventsTaskletTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/PurgeExternalEventsTaskletTest.java @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.Map; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -62,6 +63,7 @@ public class PurgeExternalEventsTaskletTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); underTest = new PurgeExternalEventsTasklet(repository, configurationDomainService); diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTaskletTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTaskletTest.java index f505856d9..a2fe79b97 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTaskletTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTaskletTest.java @@ -38,6 +38,7 @@ import org.apache.fineract.avro.MessageV1; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.apache.fineract.infrastructure.core.config.FineractProperties; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; import org.apache.fineract.infrastructure.event.external.exception.AcknowledgementTimeoutException; @@ -88,6 +89,7 @@ class SendAsynchronousEventsTaskletTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); configureExternalEventsProducerReadBatchSizeProperty(); diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanAccountDelinquencyRangeEventSerializerTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanAccountDelinquencyRangeEventSerializerTest.java index 22995aaa7..008b2d96c 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanAccountDelinquencyRangeEventSerializerTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanAccountDelinquencyRangeEventSerializerTest.java @@ -39,6 +39,7 @@ import java.util.Set; import java.util.stream.Collectors; import org.apache.fineract.avro.loan.v1.LoanAccountDelinquencyRangeDataV1; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.ExternalId; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.ExternalIdFactory; @@ -94,6 +95,7 @@ public class LoanAccountDelinquencyRangeEventSerializerTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); } diff --git a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanRepaymentBusinessEventSerializerTest.java b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanRepaymentBusinessEventSerializerTest.java index c78c714d1..7293afd4a 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanRepaymentBusinessEventSerializerTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/infrastructure/event/external/service/serialization/serializer/loan/LoanRepaymentBusinessEventSerializerTest.java @@ -39,6 +39,7 @@ import org.apache.fineract.avro.loan.v1.LoanRepaymentDueDataV1; import org.apache.fineract.avro.loan.v1.RepaymentDueDataV1; import org.apache.fineract.avro.loan.v1.RepaymentPastDueDataV1; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ExternalIdFactory; @@ -82,6 +83,7 @@ public class LoanRepaymentBusinessEventSerializerTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); moneyHelper.when(() -> MoneyHelper.getRoundingMode()).thenReturn(RoundingMode.UP); diff --git a/fineract-provider/src/test/java/org/apache/fineract/portfolio/deliquency/DelinquencyWritePlatformServiceRangeChangeEventTest.java b/fineract-provider/src/test/java/org/apache/fineract/portfolio/deliquency/DelinquencyWritePlatformServiceRangeChangeEventTest.java index 93d648dcb..866c87d4a 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/portfolio/deliquency/DelinquencyWritePlatformServiceRangeChangeEventTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/portfolio/deliquency/DelinquencyWritePlatformServiceRangeChangeEventTest.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -93,6 +94,7 @@ public class DelinquencyWritePlatformServiceRangeChangeEventTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); } diff --git a/fineract-provider/src/test/java/org/apache/fineract/portfolio/deliquency/LoanDelinquencyDomainServiceTest.java b/fineract-provider/src/test/java/org/apache/fineract/portfolio/deliquency/LoanDelinquencyDomainServiceTest.java index 09dfeb1fe..054021e56 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/portfolio/deliquency/LoanDelinquencyDomainServiceTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/portfolio/deliquency/LoanDelinquencyDomainServiceTest.java @@ -34,6 +34,7 @@ import java.util.Map; import java.util.function.Predicate; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -85,6 +86,7 @@ public class LoanDelinquencyDomainServiceTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); diff --git a/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/LoanCalculateRepaymentPastDueServiceTest.java b/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/LoanCalculateRepaymentPastDueServiceTest.java index 4270d19c4..eae0bfa69 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/LoanCalculateRepaymentPastDueServiceTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/LoanCalculateRepaymentPastDueServiceTest.java @@ -31,6 +31,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; +import org.apache.fineract.infrastructure.core.domain.ActionContext; import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant; import org.apache.fineract.infrastructure.core.service.DateUtils; import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil; @@ -59,6 +60,7 @@ public class LoanCalculateRepaymentPastDueServiceTest { @BeforeEach public void setUp() { ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null)); + ThreadLocalContextUtil.setActionContext(ActionContext.DEFAULT); ThreadLocalContextUtil .setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault())))); underTest = new LoanCalculateRepaymentPastDueService(); diff --git a/fineract-provider/src/test/resources/features/cob/loan/cob.loan.reader.feature b/fineract-provider/src/test/resources/features/cob/loan/cob.loan.reader.feature index 01e472c8a..e775f3a86 100644 --- a/fineract-provider/src/test/resources/features/cob/loan/cob.loan.reader.feature +++ b/fineract-provider/src/test/resources/features/cob/loan/cob.loan.reader.feature @@ -21,32 +21,31 @@ Feature: COB Reader @cob Scenario Outline: LoanItemReader - run test - Given The LoanItemReader.read method with loanIds , lockedAccounts + Given The LoanItemReader.read method with loanIds When LoanItemReader.read method executed Then The LoanItemReader.read result should match Examples: - |loanIds|lockedAccounts| - |1 | | - |1,2 |3,4 | + |loanIds| + |1 | + |1,2 | @cob Scenario Outline: LoanItemReader - run test: null - Given The LoanItemReader.read method with loanIds , lockedAccounts + Given The LoanItemReader.read method with loanIds When LoanItemReader.read method executed Then The LoanItemReader.read result null Examples: - |loanIds|lockedAccounts| - | | | + |loanIds| + | | @cob Scenario Outline: LoanItemReader - run test: exception - Given The LoanItemReader.read method with loanIds , lockedAccounts + Given The LoanItemReader.read method with loanIds Then throw exception LoanItemReader.read method Examples: - |loanIds|lockedAccounts| - |-1 | | - |1 | 1 | - |0 | | \ No newline at end of file + |loanIds| + |-1 | + |0 |