FINERACT-2117: Early and late payment - In advance payment strategy: Adjust last, unpaid period

This commit is contained in:
Jose Alberto Hernandez
2024-08-19 13:20:47 +02:00
committed by Adam Saghy
parent 3e923bf483
commit 04533f03c6
9 changed files with 120 additions and 9 deletions
@@ -44,6 +44,7 @@ import org.apache.fineract.client.models.AdvancedPaymentData;
import org.apache.fineract.client.models.BusinessDateRequest;
import org.apache.fineract.client.models.CreditAllocationData;
import org.apache.fineract.client.models.CreditAllocationOrder;
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
import org.apache.fineract.client.models.GetLoansLoanIdLoanChargeData;
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
@@ -5095,6 +5096,69 @@ public class AdvancedPaymentAllocationLoanRepaymentScheduleTest extends BaseLoan
});
}
// uc148a: Advanced payment allocation, with Interest Recalculation in Loan Product and Adjust last, unpaid period
// ADVANCED_PAYMENT_ALLOCATION_STRATEGY
// 1. Create a Loan product with Adv. Pment. Alloc. with Interest Recalculation enabled and Adjust last, unpaid
// period
@Test
public void uc148a() {
runAt("23 March 2024", () -> {
final Integer rescheduleStrategyMethod = 4; // Adjust last, unpaid period
PostLoanProductsRequest loanProduct = createOnePeriod30DaysPeriodicAccrualProductWithAdvancedPaymentAllocationAndInterestRecalculation(
(double) 80.0, rescheduleStrategyMethod);
final PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProduct);
assertNotNull(loanProductResponse);
final GetLoanProductsProductIdResponse loanProductDetails = loanProductHelper
.retrieveLoanProductById(loanProductResponse.getResourceId());
assertNotNull(loanProductDetails);
assertTrue(loanProductDetails.getIsInterestRecalculationEnabled());
assertEquals(rescheduleStrategyMethod.longValue(),
loanProductDetails.getInterestRecalculationData().getRescheduleStrategyType().getId());
});
}
// uc148b: Negative Test: Advanced payment allocation, with Interest Recalculation in Loan Product but try to use
// Reduce EMI amount
// ADVANCED_PAYMENT_ALLOCATION_STRATEGY
// 1. Try to Create a Loan product with Adv. Pment. Alloc. with Interest Recalculation enabled and use Reduce EMI
// amount
@Test
public void uc148b() {
runAt("23 March 2024", () -> {
final Integer rescheduleStrategyMethod = 3; // Reduce EMI amount
PostLoanProductsRequest loanProduct = createOnePeriod30DaysPeriodicAccrualProductWithAdvancedPaymentAllocationAndInterestRecalculation(
(double) 80.0, rescheduleStrategyMethod);
CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class,
() -> loanProductHelper.createLoanProduct(loanProduct));
Assertions.assertTrue(callFailedRuntimeException.getMessage().contains("is not supported for Progressive loan schedule type"));
});
}
// uc148c: Negative Test: Comulative, with Interest Recalculation in Loan Product but try to use
// Adjust last, unpaid period
// COMULATIVE
// 1. Try to Create a Loan product with Comulative with Interest Recalculation enabled and use Adjust last, unpaid
// period
@Test
public void uc148c() {
runAt("23 March 2024", () -> {
final Integer rescheduleStrategyMethod = 4; // Adjust last, unpaid period
PostLoanProductsRequest loanProduct = createOnePeriod30DaysPeriodicAccrualProductWithAdvancedPaymentAllocationAndInterestRecalculation(
(double) 80.0, rescheduleStrategyMethod).transactionProcessingStrategyCode(LoanProductTestBuilder.DEFAULT_STRATEGY)//
.loanScheduleType(LoanScheduleType.CUMULATIVE.toString());
CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class,
() -> loanProductHelper.createLoanProduct(loanProduct));
Assertions.assertTrue(callFailedRuntimeException.getMessage()
.contains("Adjust last, unpaid period is only supported for Progressive loan schedule type"));
});
}
private Long applyAndApproveLoanProgressiveAdvancedPaymentAllocationStrategyMonthlyRepayments(Long clientId, Long loanProductId,
Integer numberOfRepayments, String loanDisbursementDate, double amount) {
LOG.info("------------------------------APPLY AND APPROVE LOAN ---------------------------------------");
@@ -205,8 +205,12 @@ public abstract class BaseLoanIntegrationTest {
return Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey();
}
// Loan product with proper accounting setup
protected PostLoanProductsRequest createOnePeriod30DaysLongNoInterestPeriodicAccrualProduct() {
return createOnePeriod30DaysPeriodicAccrualProduct((double) 0);
}
// Loan product with proper accounting setup
protected PostLoanProductsRequest createOnePeriod30DaysPeriodicAccrualProduct(double interestRatePerPeriod) {
return new PostLoanProductsRequest().name(Utils.uniqueRandomStringGenerator("LOAN_PRODUCT_", 6))//
.shortName(Utils.uniqueRandomStringGenerator("", 4))//
.description("Loan Product Description")//
@@ -224,7 +228,7 @@ public abstract class BaseLoanIntegrationTest {
.maxNumberOfRepayments(30)//
.isLinkedToFloatingInterestRates(false)//
.minInterestRatePerPeriod((double) 0)//
.interestRatePerPeriod((double) 0)//
.interestRatePerPeriod(interestRatePerPeriod)//
.maxInterestRatePerPeriod((double) 100)//
.interestRateFrequencyType(2)//
.repaymentEvery(30)//
@@ -302,6 +306,21 @@ public abstract class BaseLoanIntegrationTest {
.addPaymentAllocationItem(defaultAllocation);
}
protected PostLoanProductsRequest createOnePeriod30DaysPeriodicAccrualProductWithAdvancedPaymentAllocationAndInterestRecalculation(
final double interestRatePerPeriod, final Integer rescheduleStrategyMethod) {
String futureInstallmentAllocationRule = "NEXT_INSTALLMENT";
AdvancedPaymentData defaultAllocation = createDefaultPaymentAllocation(futureInstallmentAllocationRule);
return createOnePeriod30DaysPeriodicAccrualProduct(interestRatePerPeriod) //
.transactionProcessingStrategyCode("advanced-payment-allocation-strategy")//
.loanScheduleType(LoanScheduleType.PROGRESSIVE.toString()) //
.loanScheduleProcessingType(LoanScheduleProcessingType.HORIZONTAL.toString()) //
.addPaymentAllocationItem(defaultAllocation).enableDownPayment(false) //
.isInterestRecalculationEnabled(true).interestRecalculationCompoundingMethod(0) //
.preClosureInterestCalculationStrategy(1).recalculationRestFrequencyType(1).allowPartialPeriodInterestCalcualtion(true) //
.rescheduleStrategyMethod(rescheduleStrategyMethod);
}
private List<PaymentAllocationOrder> getPaymentAllocationOrder(PaymentAllocationType... paymentAllocationTypes) {
AtomicInteger integer = new AtomicInteger(1);
return Arrays.stream(paymentAllocationTypes).map(pat -> {