FINERACT-1734-Repayment-due-event
This commit is contained in:
committed by
Arnold Gálovics
parent
6ba5d7d5c4
commit
1331073679
+10
-11
@@ -19,22 +19,20 @@
|
|||||||
package org.apache.fineract.cob.loan;
|
package org.apache.fineract.cob.loan;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Collection;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
|
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||||
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRepaymentOverdueBusinessEvent;
|
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRepaymentOverdueBusinessEvent;
|
||||||
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||||
import org.apache.fineract.portfolio.loanaccount.loanschedule.data.OverdueLoanScheduleData;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||||
import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CheckLoanRepaymentOverdueBusinessStep implements LoanCOBBusinessStep {
|
public class CheckLoanRepaymentOverdueBusinessStep implements LoanCOBBusinessStep {
|
||||||
|
|
||||||
private final LoanReadPlatformService loanReadPlatformService;
|
|
||||||
private final ConfigurationDomainService configurationDomainService;
|
private final ConfigurationDomainService configurationDomainService;
|
||||||
private final BusinessEventNotifierService businessEventNotifierService;
|
private final BusinessEventNotifierService businessEventNotifierService;
|
||||||
|
|
||||||
@@ -42,13 +40,14 @@ public class CheckLoanRepaymentOverdueBusinessStep implements LoanCOBBusinessSte
|
|||||||
public Loan execute(Loan loan) {
|
public Loan execute(Loan loan) {
|
||||||
Long numberOfDaysAfterDueDateToRaiseEvent = configurationDomainService.retrieveRepaymentOverdueDays();
|
Long numberOfDaysAfterDueDateToRaiseEvent = configurationDomainService.retrieveRepaymentOverdueDays();
|
||||||
final LocalDate currentDate = DateUtils.getBusinessLocalDate();
|
final LocalDate currentDate = DateUtils.getBusinessLocalDate();
|
||||||
final Collection<OverdueLoanScheduleData> overdueInstallmentsForLoan = loanReadPlatformService
|
final List<LoanRepaymentScheduleInstallment> loanRepaymentScheduleInstallments = loan.getRepaymentScheduleInstallments();
|
||||||
.retrieveAllOverdueInstallmentsForLoan(loan);
|
for (LoanRepaymentScheduleInstallment repaymentSchedule : loanRepaymentScheduleInstallments) {
|
||||||
for (OverdueLoanScheduleData overdueInstallment : overdueInstallmentsForLoan) {
|
if (!repaymentSchedule.isObligationsMet()) {
|
||||||
LocalDate installmentDueDate = LocalDate.parse(overdueInstallment.getDueDate());
|
LocalDate installmentDueDate = repaymentSchedule.getDueDate();
|
||||||
if (installmentDueDate.plusDays(numberOfDaysAfterDueDateToRaiseEvent).equals(currentDate)) {
|
if (installmentDueDate.plusDays(numberOfDaysAfterDueDateToRaiseEvent).equals(currentDate)) {
|
||||||
businessEventNotifierService.notifyPostBusinessEvent(new LoanRepaymentOverdueBusinessEvent(loan));
|
businessEventNotifierService.notifyPostBusinessEvent(new LoanRepaymentOverdueBusinessEvent(loan));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return loan;
|
return loan;
|
||||||
|
|||||||
+40
-15
@@ -28,8 +28,9 @@ import java.math.BigDecimal;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||||
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
|
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||||
@@ -39,8 +40,7 @@ import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
|||||||
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRepaymentOverdueBusinessEvent;
|
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanRepaymentOverdueBusinessEvent;
|
||||||
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||||
import org.apache.fineract.portfolio.loanaccount.loanschedule.data.OverdueLoanScheduleData;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
|
||||||
import org.apache.fineract.portfolio.loanaccount.service.LoanReadPlatformService;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
@@ -52,8 +52,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class CheckLoanRepaymentOverdueBusinessStepTest {
|
public class CheckLoanRepaymentOverdueBusinessStepTest {
|
||||||
|
|
||||||
@Mock
|
|
||||||
private LoanReadPlatformService loanReadPlatformService;
|
|
||||||
@Mock
|
@Mock
|
||||||
private ConfigurationDomainService configurationDomainService;
|
private ConfigurationDomainService configurationDomainService;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -65,8 +63,7 @@ public class CheckLoanRepaymentOverdueBusinessStepTest {
|
|||||||
ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null));
|
ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null));
|
||||||
ThreadLocalContextUtil
|
ThreadLocalContextUtil
|
||||||
.setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault()))));
|
.setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, LocalDate.now(ZoneId.systemDefault()))));
|
||||||
underTest = new CheckLoanRepaymentOverdueBusinessStep(loanReadPlatformService, configurationDomainService,
|
underTest = new CheckLoanRepaymentOverdueBusinessStep(configurationDomainService, businessEventNotifierService);
|
||||||
businessEventNotifierService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -76,11 +73,13 @@ public class CheckLoanRepaymentOverdueBusinessStepTest {
|
|||||||
// given
|
// given
|
||||||
when(configurationDomainService.retrieveRepaymentOverdueDays()).thenReturn(1L);
|
when(configurationDomainService.retrieveRepaymentOverdueDays()).thenReturn(1L);
|
||||||
LocalDate loanInstallmentRepaymentDueDate = DateUtils.getBusinessLocalDate().minusDays(1);
|
LocalDate loanInstallmentRepaymentDueDate = DateUtils.getBusinessLocalDate().minusDays(1);
|
||||||
Collection<OverdueLoanScheduleData> overdueInstallmentsForLoan = Arrays
|
|
||||||
.asList(new OverdueLoanScheduleData(1L, 1L, loanInstallmentRepaymentDueDate.toString(), BigDecimal.valueOf(0.0), "", "",
|
|
||||||
BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), 1));
|
|
||||||
when(loanReadPlatformService.retrieveAllOverdueInstallmentsForLoan(any())).thenReturn(overdueInstallmentsForLoan);
|
|
||||||
Loan loanForProcessing = Mockito.mock(Loan.class);
|
Loan loanForProcessing = Mockito.mock(Loan.class);
|
||||||
|
List<LoanRepaymentScheduleInstallment> loanRepaymentScheduleInstallments = Arrays
|
||||||
|
.asList(new LoanRepaymentScheduleInstallment(loanForProcessing, 1, LocalDate.now(ZoneId.systemDefault()),
|
||||||
|
loanInstallmentRepaymentDueDate, BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0),
|
||||||
|
BigDecimal.valueOf(0.0), false, new HashSet<>(), BigDecimal.valueOf(0.0)));
|
||||||
|
when(loanForProcessing.getRepaymentScheduleInstallments()).thenReturn(loanRepaymentScheduleInstallments);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Loan processedLoan = underTest.execute(loanForProcessing);
|
Loan processedLoan = underTest.execute(loanForProcessing);
|
||||||
// then
|
// then
|
||||||
@@ -95,11 +94,12 @@ public class CheckLoanRepaymentOverdueBusinessStepTest {
|
|||||||
// given
|
// given
|
||||||
when(configurationDomainService.retrieveRepaymentOverdueDays()).thenReturn(1L);
|
when(configurationDomainService.retrieveRepaymentOverdueDays()).thenReturn(1L);
|
||||||
LocalDate loanInstallmentRepaymentDueDateBefore5Days = DateUtils.getBusinessLocalDate().minusDays(5);
|
LocalDate loanInstallmentRepaymentDueDateBefore5Days = DateUtils.getBusinessLocalDate().minusDays(5);
|
||||||
Collection<OverdueLoanScheduleData> overdueInstallmentsForLoan = Arrays
|
|
||||||
.asList(new OverdueLoanScheduleData(1L, 1L, loanInstallmentRepaymentDueDateBefore5Days.toString(), BigDecimal.valueOf(0.0),
|
|
||||||
"", "", BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), 1));
|
|
||||||
when(loanReadPlatformService.retrieveAllOverdueInstallmentsForLoan(any())).thenReturn(overdueInstallmentsForLoan);
|
|
||||||
Loan loanForProcessing = Mockito.mock(Loan.class);
|
Loan loanForProcessing = Mockito.mock(Loan.class);
|
||||||
|
List<LoanRepaymentScheduleInstallment> loanRepaymentScheduleInstallments = Arrays
|
||||||
|
.asList(new LoanRepaymentScheduleInstallment(loanForProcessing, 1, LocalDate.now(ZoneId.systemDefault()),
|
||||||
|
loanInstallmentRepaymentDueDateBefore5Days, BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0),
|
||||||
|
BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), false, new HashSet<>(), BigDecimal.valueOf(0.0)));
|
||||||
|
when(loanForProcessing.getRepaymentScheduleInstallments()).thenReturn(loanRepaymentScheduleInstallments);
|
||||||
// when
|
// when
|
||||||
Loan processedLoan = underTest.execute(loanForProcessing);
|
Loan processedLoan = underTest.execute(loanForProcessing);
|
||||||
// then
|
// then
|
||||||
@@ -107,4 +107,29 @@ public class CheckLoanRepaymentOverdueBusinessStepTest {
|
|||||||
assertEquals(processedLoan, loanForProcessing);
|
assertEquals(processedLoan, loanForProcessing);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLoanWithInstallmentOverdueAfterConfiguredDaysButInstallmentPaidOffWhenStepExecutionThenNoBusinessEvent() {
|
||||||
|
ArgumentCaptor<LoanRepaymentOverdueBusinessEvent> loanRepaymentOverdueBusinessEventArgumentCaptor = ArgumentCaptor
|
||||||
|
.forClass(LoanRepaymentOverdueBusinessEvent.class);
|
||||||
|
// given
|
||||||
|
when(configurationDomainService.retrieveRepaymentOverdueDays()).thenReturn(1L);
|
||||||
|
LocalDate loanInstallmentRepaymentDueDate = DateUtils.getBusinessLocalDate().minusDays(1);
|
||||||
|
Loan loanForProcessing = Mockito.mock(Loan.class);
|
||||||
|
LoanRepaymentScheduleInstallment repaymentInstallmentPaidOff = new LoanRepaymentScheduleInstallment(loanForProcessing, 1,
|
||||||
|
LocalDate.now(ZoneId.systemDefault()), loanInstallmentRepaymentDueDate, BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0),
|
||||||
|
BigDecimal.valueOf(0.0), BigDecimal.valueOf(0.0), false, new HashSet<>(), BigDecimal.valueOf(0.0));
|
||||||
|
|
||||||
|
repaymentInstallmentPaidOff.updateObligationMet(true);
|
||||||
|
|
||||||
|
List<LoanRepaymentScheduleInstallment> loanRepaymentScheduleInstallments = Arrays.asList(repaymentInstallmentPaidOff);
|
||||||
|
when(loanForProcessing.getRepaymentScheduleInstallments()).thenReturn(loanRepaymentScheduleInstallments);
|
||||||
|
|
||||||
|
// when
|
||||||
|
Loan processedLoan = underTest.execute(loanForProcessing);
|
||||||
|
// then
|
||||||
|
verify(businessEventNotifierService, times(0)).notifyPostBusinessEvent(any());
|
||||||
|
assertEquals(processedLoan, loanForProcessing);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user