FINERACT-2065: Schedule handling for fixed length configuration
This commit is contained in:
committed by
Adam Saghy
parent
6458094a5e
commit
b64b4b7105
+277
@@ -3542,6 +3542,283 @@ public class AdvancedPaymentAllocationLoanRepaymentScheduleTest extends BaseLoan
|
||||
});
|
||||
}
|
||||
|
||||
// UC126: Advanced payment allocation with Fixed Length for 40 days and Loan Term for 45 days (3 repayments every 15
|
||||
// days)
|
||||
// ADVANCED_PAYMENT_ALLOCATION_STRATEGY
|
||||
// 1. Create a Loan product with Adv. Pment. Alloc. and No Interest
|
||||
// 2. Submit Loan and approve
|
||||
// 3. Disburse
|
||||
// 4. Validate Repayment Schedule
|
||||
@Test
|
||||
public void uc126() {
|
||||
runAt("22 November 2023", () -> {
|
||||
final Integer fixedLength = 40; // 40 days
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
PostLoanProductsRequest product = createOnePeriod30DaysLongNoInterestPeriodicAccrualProductWithAdvancedPaymentAllocation()
|
||||
.numberOfRepayments(3).repaymentEvery(15).fixedLength(fixedLength);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(product);
|
||||
PostLoansRequest applicationRequest = applyLoanRequest(clientId, loanProductResponse.getResourceId(), "22 November 2023",
|
||||
1000.0, 4);
|
||||
|
||||
applicationRequest = applicationRequest.numberOfRepayments(3).loanTermFrequency(45)
|
||||
.transactionProcessingStrategyCode(LoanProductTestBuilder.ADVANCED_PAYMENT_ALLOCATION_STRATEGY).repaymentEvery(15);
|
||||
|
||||
PostLoansResponse loanResponse = loanTransactionHelper.applyLoan(applicationRequest);
|
||||
|
||||
loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
|
||||
new PostLoansLoanIdRequest().approvedLoanAmount(BigDecimal.valueOf(1000)).dateFormat(DATETIME_PATTERN)
|
||||
.approvedOnDate("22 November 2023").locale("en"));
|
||||
|
||||
loanTransactionHelper.disburseLoan(loanResponse.getLoanId(),
|
||||
new PostLoansLoanIdRequest().actualDisbursementDate("22 November 2023").dateFormat(DATETIME_PATTERN)
|
||||
.transactionAmount(BigDecimal.valueOf(100.0)).locale("en"));
|
||||
|
||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanResponse.getLoanId());
|
||||
validateLoanSummaryBalances(loanDetails, 100.0, 0.0, 100.0, 0.0, null);
|
||||
validateRepaymentPeriod(loanDetails, 1, LocalDate.of(2023, 12, 7), 33.0, 0.0, 33.0, 0.0, 0.0);
|
||||
validateRepaymentPeriod(loanDetails, 2, LocalDate.of(2023, 12, 22), 33.0, 0.0, 33.0, 0.0, 0.0);
|
||||
validateRepaymentPeriod(loanDetails, 3, LocalDate.of(2024, 1, 01), 34.0, 0.0, 34.0, 0.0, 0.0);
|
||||
assertEquals(loanDetails.getNumberOfRepayments(), 3);
|
||||
assertEquals(
|
||||
Utils.getDifferenceInDays(loanDetails.getTimeline().getActualDisbursementDate(), loanDetails.getRepaymentSchedule()
|
||||
.getPeriods().get(loanDetails.getRepaymentSchedule().getPeriods().size() - 1).getDueDate()),
|
||||
fixedLength.longValue());
|
||||
assertTrue(loanDetails.getStatus().getActive());
|
||||
});
|
||||
}
|
||||
|
||||
// UC127: Advanced payment allocation with Fixed Length for 5 weeks and Loan Term for 6 weeks (3 repayments every 2
|
||||
// weeks)
|
||||
// ADVANCED_PAYMENT_ALLOCATION_STRATEGY
|
||||
// 1. Create a Loan product with Adv. Pment. Alloc. and No Interest
|
||||
// 2. Submit Loan and approve
|
||||
// 3. Disburse
|
||||
// 4. Validate Repayment Schedule
|
||||
@Test
|
||||
public void uc127() {
|
||||
runAt("22 November 2023", () -> {
|
||||
final Integer fixedLength = 5; // 5 weeks
|
||||
final Integer repaymentFrequencyType = 1; // week
|
||||
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
PostLoanProductsRequest product = createOnePeriod30DaysLongNoInterestPeriodicAccrualProductWithAdvancedPaymentAllocation()
|
||||
.numberOfRepayments(3).repaymentEvery(2).repaymentFrequencyType(repaymentFrequencyType.longValue())
|
||||
.fixedLength(fixedLength);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(product);
|
||||
PostLoansRequest applicationRequest = applyLoanRequest(clientId, loanProductResponse.getResourceId(), "22 November 2023",
|
||||
1000.0, 4);
|
||||
|
||||
applicationRequest = applicationRequest.numberOfRepayments(3).loanTermFrequency(6).loanTermFrequencyType(repaymentFrequencyType)
|
||||
.transactionProcessingStrategyCode(LoanProductTestBuilder.ADVANCED_PAYMENT_ALLOCATION_STRATEGY).repaymentEvery(2)
|
||||
.repaymentFrequencyType(repaymentFrequencyType);
|
||||
|
||||
PostLoansResponse loanResponse = loanTransactionHelper.applyLoan(applicationRequest);
|
||||
|
||||
loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
|
||||
new PostLoansLoanIdRequest().approvedLoanAmount(BigDecimal.valueOf(1000)).dateFormat(DATETIME_PATTERN)
|
||||
.approvedOnDate("22 November 2023").locale("en"));
|
||||
|
||||
loanTransactionHelper.disburseLoan(loanResponse.getLoanId(),
|
||||
new PostLoansLoanIdRequest().actualDisbursementDate("22 November 2023").dateFormat(DATETIME_PATTERN)
|
||||
.transactionAmount(BigDecimal.valueOf(100.0)).locale("en"));
|
||||
|
||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanResponse.getLoanId());
|
||||
validateLoanSummaryBalances(loanDetails, 100.0, 0.0, 100.0, 0.0, null);
|
||||
validateRepaymentPeriod(loanDetails, 1, LocalDate.of(2023, 12, 6), 33.0, 0.0, 33.0, 0.0, 0.0);
|
||||
validateRepaymentPeriod(loanDetails, 2, LocalDate.of(2023, 12, 20), 33.0, 0.0, 33.0, 0.0, 0.0);
|
||||
validateRepaymentPeriod(loanDetails, 3, LocalDate.of(2023, 12, 27), 34.0, 0.0, 34.0, 0.0, 0.0);
|
||||
assertEquals(loanDetails.getNumberOfRepayments(), 3);
|
||||
assertEquals(
|
||||
Utils.getDifferenceInWeeks(loanDetails.getTimeline().getActualDisbursementDate(), loanDetails.getRepaymentSchedule()
|
||||
.getPeriods().get(loanDetails.getRepaymentSchedule().getPeriods().size() - 1).getDueDate()),
|
||||
fixedLength.longValue());
|
||||
assertTrue(loanDetails.getStatus().getActive());
|
||||
});
|
||||
}
|
||||
|
||||
// UC128: Advanced payment allocation with Fixed Length for 11 months and Loan Term for 12 months (6 repayments each
|
||||
// 2 months)
|
||||
// every 2 months)
|
||||
// ADVANCED_PAYMENT_ALLOCATION_STRATEGY
|
||||
// 1. Create a Loan product with Adv. Pment. Alloc. and No Interest
|
||||
// 2. Submit Loan and approve
|
||||
// 3. Disburse
|
||||
// 4. Validate Repayment Schedule
|
||||
@Test
|
||||
public void uc128() {
|
||||
runAt("22 November 2023", () -> {
|
||||
final Integer fixedLength = 11; // 11 months
|
||||
final Integer repaymentFrequencyType = 2; // month
|
||||
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
PostLoanProductsRequest product = createOnePeriod30DaysLongNoInterestPeriodicAccrualProductWithAdvancedPaymentAllocation()
|
||||
.numberOfRepayments(6).repaymentEvery(2).repaymentFrequencyType(repaymentFrequencyType.longValue())
|
||||
.fixedLength(fixedLength);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(product);
|
||||
PostLoansRequest applicationRequest = applyLoanRequest(clientId, loanProductResponse.getResourceId(), "22 November 2023",
|
||||
1000.0, 4);
|
||||
|
||||
applicationRequest = applicationRequest.numberOfRepayments(6).loanTermFrequency(12)
|
||||
.loanTermFrequencyType(repaymentFrequencyType)
|
||||
.transactionProcessingStrategyCode(LoanProductTestBuilder.ADVANCED_PAYMENT_ALLOCATION_STRATEGY).repaymentEvery(2)
|
||||
.repaymentFrequencyType(repaymentFrequencyType);
|
||||
|
||||
PostLoansResponse loanResponse = loanTransactionHelper.applyLoan(applicationRequest);
|
||||
|
||||
loanTransactionHelper.approveLoan(loanResponse.getLoanId(),
|
||||
new PostLoansLoanIdRequest().approvedLoanAmount(BigDecimal.valueOf(1000)).dateFormat(DATETIME_PATTERN)
|
||||
.approvedOnDate("22 November 2023").locale("en"));
|
||||
|
||||
loanTransactionHelper.disburseLoan(loanResponse.getLoanId(),
|
||||
new PostLoansLoanIdRequest().actualDisbursementDate("22 November 2023").dateFormat(DATETIME_PATTERN)
|
||||
.transactionAmount(BigDecimal.valueOf(100.0)).locale("en"));
|
||||
|
||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanResponse.getLoanId());
|
||||
validateLoanSummaryBalances(loanDetails, 100.0, 0.0, 100.0, 0.0, null);
|
||||
validateRepaymentPeriod(loanDetails, 1, LocalDate.of(2024, 1, 22), 17.0, 0.0, 17.0, 0.0, 0.0);
|
||||
validateRepaymentPeriod(loanDetails, 2, LocalDate.of(2024, 3, 22), 17.0, 0.0, 17.0, 0.0, 0.0);
|
||||
validateRepaymentPeriod(loanDetails, 3, LocalDate.of(2024, 5, 22), 17.0, 0.0, 17.0, 0.0, 0.0);
|
||||
validateRepaymentPeriod(loanDetails, 4, LocalDate.of(2024, 7, 22), 17.0, 0.0, 17.0, 0.0, 0.0);
|
||||
validateRepaymentPeriod(loanDetails, 5, LocalDate.of(2024, 9, 22), 17.0, 0.0, 17.0, 0.0, 0.0);
|
||||
validateRepaymentPeriod(loanDetails, 6, LocalDate.of(2024, 10, 22), 15.0, 0.0, 15.0, 0.0, 0.0);
|
||||
assertEquals(loanDetails.getNumberOfRepayments(), 6);
|
||||
assertEquals(
|
||||
Utils.getDifferenceInMonths(loanDetails.getTimeline().getActualDisbursementDate(), loanDetails.getRepaymentSchedule()
|
||||
.getPeriods().get(loanDetails.getRepaymentSchedule().getPeriods().size() - 1).getDueDate()),
|
||||
fixedLength.longValue());
|
||||
assertTrue(loanDetails.getStatus().getActive());
|
||||
});
|
||||
}
|
||||
|
||||
// UC129: Advanced payment allocation with Fixed Length for 5 months and Loan Term for 6 months (6 repayments
|
||||
// every month)
|
||||
// ADVANCED_PAYMENT_ALLOCATION_STRATEGY
|
||||
// 1. Create a Loan product with Adv. Pment. Alloc. and No Interest
|
||||
// 2. Submit Loan and approve -> expect validation error
|
||||
@Test
|
||||
public void uc129() {
|
||||
final String operationDate = "22 November 2023";
|
||||
runAt(operationDate, () -> {
|
||||
final Integer fixedLength = 5; // 5 months
|
||||
final Integer repaymentFrequencyType = 2; // month
|
||||
|
||||
// Try to create a Loan Product using Fixed Length with a wrong Loan Term setup
|
||||
LOG.info("Try to create a Loan Product using Fixed Length with a wrong Loan Term setup");
|
||||
CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class,
|
||||
() -> loanProductHelper
|
||||
.createLoanProduct(createOnePeriod30DaysLongNoInterestPeriodicAccrualProductWithAdvancedPaymentAllocation()
|
||||
.interestRatePerPeriod(0.0).numberOfRepayments(6).repaymentEvery(1)
|
||||
.repaymentFrequencyType(repaymentFrequencyType.longValue()).fixedLength(fixedLength)));
|
||||
assertEquals(403, exception.getResponse().code());
|
||||
assertTrue(exception.getMessage().contains("error.msg.number.repayments.and.fixed.length.configuration.not.valid"));
|
||||
});
|
||||
}
|
||||
|
||||
// UC130: Advanced payment allocation with Fixed Length for 5 months and Loan Term for 6 months (6 repayments
|
||||
// every month)
|
||||
// ADVANCED_PAYMENT_ALLOCATION_STRATEGY
|
||||
// 1. Create a Loan product with Adv. Pment. Alloc. and No Interest
|
||||
// 2. Submit Loan and approve -> expect validation error - Fixed Length without Advanced Payment Allocation
|
||||
@Test
|
||||
public void uc130() {
|
||||
final String operationDate = "22 November 2023";
|
||||
runAt(operationDate, () -> {
|
||||
final Integer fixedLength = 5; // 5 months
|
||||
final Integer repaymentFrequencyType = 2; // month
|
||||
|
||||
PostLoanProductsRequest product = createOnePeriod30DaysLongNoInterestPeriodicAccrualProductWithAdvancedPaymentAllocation()
|
||||
.numberOfRepayments(6).repaymentEvery(1).repaymentFrequencyType(repaymentFrequencyType.longValue()).fixedLength(6);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(product);
|
||||
|
||||
// Try to use Fixed Length without Advanced Payment Allocation as transaction processing strategy code
|
||||
LOG.info("Try to use Fixed Length without Advanced Payment Allocation as transaction processing strategy code");
|
||||
CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class,
|
||||
() -> loanTransactionHelper.applyLoan(new PostLoansRequest().clientId(client.getClientId())
|
||||
.productId(loanProductResponse.getResourceId()).loanType("individual").locale("en")
|
||||
.submittedOnDate(operationDate).expectedDisbursementDate(operationDate).dateFormat(DATETIME_PATTERN)
|
||||
.amortizationType(1).interestRatePerPeriod(BigDecimal.ZERO).interestCalculationPeriodType(1).interestType(0)
|
||||
.repaymentEvery(1).repaymentFrequencyType(repaymentFrequencyType).numberOfRepayments(6).loanTermFrequency(6)
|
||||
.loanTermFrequencyType(repaymentFrequencyType).principal(BigDecimal.valueOf(1000.0))
|
||||
.maxOutstandingLoanBalance(BigDecimal.valueOf(35000)).fixedLength(fixedLength)
|
||||
.transactionProcessingStrategyCode(FineractStyleLoanRepaymentScheduleTransactionProcessor.STRATEGY_CODE)
|
||||
.loanScheduleProcessingType(LoanScheduleProcessingType.HORIZONTAL.name())));
|
||||
|
||||
assertEquals(403, exception.getResponse().code());
|
||||
assertTrue(exception.getMessage()
|
||||
.contains("error.msg.loan.repayment.strategy.can.not.be.different.than.advanced.payment.allocation"));
|
||||
});
|
||||
}
|
||||
|
||||
// UC131: Advanced payment allocation with Fixed Length for 5 months and Loan Term for 6 months (6 repayments
|
||||
// every month)
|
||||
// ADVANCED_PAYMENT_ALLOCATION_STRATEGY
|
||||
// 1. Create a Loan product with Adv. Pment. Alloc. and No Interest
|
||||
// 2. Submit Loan and approve -> expect validation error - Interest Rate value higher than Zero
|
||||
@Test
|
||||
public void uc131() {
|
||||
final String operationDate = "22 November 2023";
|
||||
runAt(operationDate, () -> {
|
||||
final Integer fixedLength = 5; // 5 months
|
||||
final Integer repaymentFrequencyType = 2; // month
|
||||
|
||||
PostLoanProductsRequest product = createOnePeriod30DaysLongNoInterestPeriodicAccrualProductWithAdvancedPaymentAllocation()
|
||||
.numberOfRepayments(6).repaymentEvery(1).repaymentFrequencyType(repaymentFrequencyType.longValue()).fixedLength(6);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(product);
|
||||
|
||||
// Try to use Fixed Length with an Interest Rate value higher than Zero
|
||||
LOG.info("Try to use Fixed Length with an Interest Rate value higher than Zero");
|
||||
CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class,
|
||||
() -> loanTransactionHelper.applyLoan(new PostLoansRequest().clientId(client.getClientId())
|
||||
.productId(loanProductResponse.getResourceId()).loanType("individual").locale("en")
|
||||
.submittedOnDate(operationDate).expectedDisbursementDate(operationDate).dateFormat(DATETIME_PATTERN)
|
||||
.amortizationType(1).interestRatePerPeriod(BigDecimal.ONE).interestCalculationPeriodType(1).interestType(0)
|
||||
.repaymentEvery(1).repaymentFrequencyType(repaymentFrequencyType).numberOfRepayments(6).loanTermFrequency(6)
|
||||
.loanTermFrequencyType(repaymentFrequencyType).principal(BigDecimal.valueOf(1000.0))
|
||||
.maxOutstandingLoanBalance(BigDecimal.valueOf(35000)).fixedLength(fixedLength)
|
||||
.transactionProcessingStrategyCode(
|
||||
AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY)
|
||||
.loanScheduleProcessingType(LoanScheduleProcessingType.HORIZONTAL.name())));
|
||||
|
||||
assertEquals(403, exception.getResponse().code());
|
||||
assertTrue(exception.getMessage().contains("error.msg.fixed.length.only.supported.for.zero.interest"));
|
||||
});
|
||||
}
|
||||
|
||||
// UC132: Advanced payment allocation with Fixed Length for 5 months and Loan Term for 6 months (3 repayments
|
||||
// every 2 months)
|
||||
// ADVANCED_PAYMENT_ALLOCATION_STRATEGY
|
||||
// 1. Create a Loan product with Adv. Pment. Alloc. and No Interest
|
||||
// 2. Submit Loan and approve -> expect validation error - Loan acount Fixed Length with a wrong Loan Term setup
|
||||
@Test
|
||||
public void uc132() {
|
||||
final String operationDate = "22 November 2023";
|
||||
runAt(operationDate, () -> {
|
||||
final Integer fixedLength = 5; // 5 months
|
||||
final Integer repaymentFrequencyType = 2; // month
|
||||
|
||||
PostLoanProductsRequest product = createOnePeriod30DaysLongNoInterestPeriodicAccrualProductWithAdvancedPaymentAllocation()
|
||||
.numberOfRepayments(6).repaymentEvery(1).repaymentFrequencyType(repaymentFrequencyType.longValue()).fixedLength(6);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(product);
|
||||
|
||||
// Try to use Fixed Length with a wrong Loan Term setup
|
||||
LOG.info("Try to use Fixed Length with a wrong Loan Term setup");
|
||||
CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class,
|
||||
() -> loanTransactionHelper.applyLoan(new PostLoansRequest().clientId(client.getClientId())
|
||||
.productId(loanProductResponse.getResourceId()).loanType("individual").locale("en")
|
||||
.submittedOnDate(operationDate).expectedDisbursementDate(operationDate).dateFormat(DATETIME_PATTERN)
|
||||
.amortizationType(1).interestRatePerPeriod(BigDecimal.ZERO).interestCalculationPeriodType(1).interestType(0)
|
||||
.repaymentEvery(2).repaymentFrequencyType(repaymentFrequencyType).numberOfRepayments(6).loanTermFrequency(6)
|
||||
.loanTermFrequencyType(repaymentFrequencyType).principal(BigDecimal.valueOf(1000.0))
|
||||
.maxOutstandingLoanBalance(BigDecimal.valueOf(35000)).fixedLength(fixedLength)
|
||||
.transactionProcessingStrategyCode(
|
||||
AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY)
|
||||
.loanScheduleProcessingType(LoanScheduleProcessingType.HORIZONTAL.name())));
|
||||
|
||||
assertEquals(403, exception.getResponse().code());
|
||||
assertTrue(exception.getMessage().contains("error.msg.number.repayments.and.fixed.length.configuration.not.valid"));
|
||||
});
|
||||
}
|
||||
|
||||
private static List<PaymentAllocationOrder> getPaymentAllocationOrder(PaymentAllocationType... paymentAllocationTypes) {
|
||||
AtomicInteger integer = new AtomicInteger(1);
|
||||
return Arrays.stream(paymentAllocationTypes).map(pat -> {
|
||||
|
||||
+36
-17
@@ -22,10 +22,16 @@ import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.PostLoanProductsRequest;
|
||||
import org.apache.fineract.client.models.PostLoanProductsResponse;
|
||||
import org.apache.fineract.client.models.PostLoansRequest;
|
||||
import org.apache.fineract.client.models.PostLoansResponse;
|
||||
import org.apache.fineract.client.models.PutLoanProductsProductIdRequest;
|
||||
import org.apache.fineract.client.models.PutLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.transactionprocessor.impl.AdvancedPaymentScheduleTransactionProcessor;
|
||||
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleProcessingType;
|
||||
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleType;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -35,25 +41,25 @@ public class FixedLengthLoanProductIntegrationTest extends BaseLoanIntegrationTe
|
||||
|
||||
@Test
|
||||
public void testCreateReadUpdateReadLoanProductWithFixedLength() {
|
||||
// create with 5
|
||||
PostLoanProductsRequest loanProductsRequest = fixedLengthLoanProduct(5);
|
||||
// create with 4
|
||||
PostLoanProductsRequest loanProductsRequest = fixedLengthLoanProduct(4);
|
||||
PostLoanProductsResponse loanProduct = loanProductHelper.createLoanProduct(loanProductsRequest);
|
||||
Assertions.assertNotNull(loanProduct.getResourceId());
|
||||
|
||||
// read
|
||||
GetLoanProductsProductIdResponse getLoanProductsProductIdResponse = loanProductHelper
|
||||
.retrieveLoanProductById(loanProduct.getResourceId());
|
||||
Assertions.assertEquals(5, getLoanProductsProductIdResponse.getFixedLength());
|
||||
Assertions.assertEquals(4, getLoanProductsProductIdResponse.getFixedLength());
|
||||
|
||||
// update to 6
|
||||
PutLoanProductsProductIdRequest updateRequest = new PutLoanProductsProductIdRequest().fixedLength(6).locale("en");
|
||||
// update to 5
|
||||
PutLoanProductsProductIdRequest updateRequest = new PutLoanProductsProductIdRequest().fixedLength(5).locale("en");
|
||||
PutLoanProductsProductIdResponse putLoanProductsProductIdResponse = loanProductHelper
|
||||
.updateLoanProductById(loanProduct.getResourceId(), updateRequest);
|
||||
Assertions.assertNotNull(putLoanProductsProductIdResponse.getResourceId());
|
||||
|
||||
// read again
|
||||
getLoanProductsProductIdResponse = loanProductHelper.retrieveLoanProductById(loanProduct.getResourceId());
|
||||
Assertions.assertEquals(6, getLoanProductsProductIdResponse.getFixedLength());
|
||||
Assertions.assertEquals(5, getLoanProductsProductIdResponse.getFixedLength());
|
||||
|
||||
// update to null
|
||||
loanTransactionHelper.updateLoanProduct(putLoanProductsProductIdResponse.getResourceId(), """
|
||||
@@ -73,12 +79,18 @@ public class FixedLengthLoanProductIntegrationTest extends BaseLoanIntegrationTe
|
||||
runAt("01 January 2023", () -> {
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
|
||||
PostLoanProductsResponse loanProduct = loanProductHelper.createLoanProduct(fixedLengthLoanProduct(6));
|
||||
PostLoanProductsResponse loanProduct = loanProductHelper.createLoanProduct(fixedLengthLoanProduct(4));
|
||||
Assertions.assertNotNull(loanProduct.getResourceId());
|
||||
|
||||
Long loanId = applyAndApproveLoan(clientId, loanProduct.getResourceId(), "01 January 2023", 1000.0);
|
||||
PostLoansRequest applicationRequest = applyLoanRequest(clientId, loanProduct.getResourceId(), "01 January 2023", 1000.0, 4);
|
||||
applicationRequest = applicationRequest
|
||||
.transactionProcessingStrategyCode(LoanProductTestBuilder.ADVANCED_PAYMENT_ALLOCATION_STRATEGY);
|
||||
|
||||
PostLoansResponse loanResponse = loanTransactionHelper.applyLoan(applicationRequest);
|
||||
Long loanId = loanResponse.getLoanId();
|
||||
|
||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId);
|
||||
Assertions.assertEquals(6, loanDetails.getFixedLength());
|
||||
Assertions.assertEquals(4, loanDetails.getFixedLength());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -87,22 +99,29 @@ public class FixedLengthLoanProductIntegrationTest extends BaseLoanIntegrationTe
|
||||
runAt("01 January 2023", () -> {
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
|
||||
PostLoanProductsResponse loanProduct = loanProductHelper.createLoanProduct(fixedLengthLoanProduct(6));
|
||||
PostLoanProductsResponse loanProduct = loanProductHelper.createLoanProduct(fixedLengthLoanProduct(4));
|
||||
Assertions.assertNotNull(loanProduct.getResourceId());
|
||||
|
||||
Long loanId = applyAndApproveLoan(clientId, loanProduct.getResourceId(), "01 January 2023", 1000.0, 1, //
|
||||
loanApplication -> loanApplication.fixedLength(5) //
|
||||
);
|
||||
PostLoansRequest applicationRequest = applyLoanRequest(clientId, loanProduct.getResourceId(), "01 January 2023", 1000.0, 4);
|
||||
applicationRequest = applicationRequest.fixedLength(5).repaymentEvery(1).repaymentFrequencyType(2).loanTermFrequencyType(2)
|
||||
.loanTermFrequency(4).transactionProcessingStrategyCode(LoanProductTestBuilder.ADVANCED_PAYMENT_ALLOCATION_STRATEGY);
|
||||
|
||||
PostLoansResponse loanResponse = loanTransactionHelper.applyLoan(applicationRequest);
|
||||
Long loanId = loanResponse.getLoanId();
|
||||
|
||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId);
|
||||
Assertions.assertEquals(5, loanDetails.getFixedLength());
|
||||
});
|
||||
}
|
||||
|
||||
private PostLoanProductsRequest fixedLengthLoanProduct(Integer fixedLength) {
|
||||
return createOnePeriod30DaysLongNoInterestPeriodicAccrualProduct().numberOfRepayments(4)//
|
||||
.repaymentEvery(1)//
|
||||
.repaymentFrequencyType(RepaymentFrequencyType.MONTHS.longValue())//
|
||||
.transactionProcessingStrategyCode("mifos-standard-strategy").fixedLength(fixedLength);
|
||||
return createOnePeriod30DaysLongNoInterestPeriodicAccrualProductWithAdvancedPaymentAllocation() //
|
||||
.numberOfRepayments(4).repaymentEvery(1) //
|
||||
.repaymentFrequencyType(RepaymentFrequencyType.MONTHS.longValue()) //
|
||||
.loanScheduleType(LoanScheduleType.PROGRESSIVE.toString()) //
|
||||
.transactionProcessingStrategyCode(AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY) //
|
||||
.loanScheduleProcessingType(LoanScheduleProcessingType.HORIZONTAL.name()) //
|
||||
.interestRatePerPeriod(0.0).fixedLength(fixedLength);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+15
@@ -19,6 +19,9 @@
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static java.time.temporal.ChronoUnit.DAYS;
|
||||
import static java.time.temporal.ChronoUnit.MONTHS;
|
||||
import static java.time.temporal.ChronoUnit.WEEKS;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
@@ -520,4 +523,16 @@ public final class Utils {
|
||||
public static LocalDate getDateAsLocalDate(String dateAsString) {
|
||||
return LocalDate.parse(dateAsString, dateFormatter);
|
||||
}
|
||||
|
||||
public static long getDifferenceInDays(final LocalDate localDateBefore, final LocalDate localDateAfter) {
|
||||
return DAYS.between(localDateBefore, localDateAfter);
|
||||
}
|
||||
|
||||
public static long getDifferenceInWeeks(final LocalDate localDateBefore, final LocalDate localDateAfter) {
|
||||
return WEEKS.between(localDateBefore, localDateAfter);
|
||||
}
|
||||
|
||||
public static long getDifferenceInMonths(final LocalDate localDateBefore, final LocalDate localDateAfter) {
|
||||
return MONTHS.between(localDateBefore, localDateAfter);
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -343,6 +343,11 @@ public class LoanTransactionHelper extends IntegrationTest {
|
||||
return ok(fineract().loanCharges.retrieveTemplate9(loanExternalId));
|
||||
}
|
||||
|
||||
public HashMap applyLoan(final String payload, final ResponseSpecification responseSpec) {
|
||||
final String postURLForLoan = "/fineract-provider/api/v1/loans?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForLoan, payload, null);
|
||||
}
|
||||
|
||||
public List getRepaymentTemplate(final Integer loanId) {
|
||||
final String GET_REPAYMENTS_URL = "/fineract-provider/api/v1/loans/" + loanId + "/transactions/template?command=repayment&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
|
||||
Reference in New Issue
Block a user