FINERACT-1971: Loan re-aging foundational implementation
This commit is contained in:
committed by
Arnold Gálovics
parent
0d06e2bb2c
commit
4d4502fbe0
+35
-5
@@ -40,6 +40,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
@@ -54,6 +55,7 @@ import org.apache.fineract.client.models.BusinessDateRequest;
|
||||
import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdTransactions;
|
||||
import org.apache.fineract.client.models.PaymentAllocationOrder;
|
||||
import org.apache.fineract.client.models.PostChargesResponse;
|
||||
import org.apache.fineract.client.models.PostLoanProductsRequest;
|
||||
@@ -317,10 +319,18 @@ public abstract class BaseLoanIntegrationTest {
|
||||
} else {
|
||||
Assertions.assertEquals(transactions.length, loanDetails.getTransactions().size());
|
||||
Arrays.stream(transactions).forEach(tr -> {
|
||||
boolean found = loanDetails.getTransactions().stream()
|
||||
.anyMatch(item -> Objects.equals(item.getAmount(), tr.amount) && Objects.equals(item.getType().getValue(), tr.type)
|
||||
&& Objects.equals(item.getDate(), LocalDate.parse(tr.date, dateTimeFormatter)));
|
||||
Assertions.assertTrue(found, "Required transaction not found: " + tr);
|
||||
Optional<GetLoansLoanIdTransactions> optTx = loanDetails.getTransactions().stream()
|
||||
.filter(item -> Objects.equals(item.getAmount(), tr.amount) //
|
||||
&& Objects.equals(item.getType().getValue(), tr.type) //
|
||||
&& Objects.equals(item.getDate(), LocalDate.parse(tr.date, dateTimeFormatter)))
|
||||
.findFirst();
|
||||
Assertions.assertTrue(optTx.isPresent(), "Required transaction not found: " + tr);
|
||||
|
||||
GetLoansLoanIdTransactions tx = optTx.get();
|
||||
|
||||
if (tr.reversed != null) {
|
||||
Assertions.assertEquals(tr.reversed, tx.getManuallyReversed(), "Transaction is not reversed: " + tr);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -355,6 +365,20 @@ public abstract class BaseLoanIntegrationTest {
|
||||
inlineLoanCOBHelper.executeInlineCOB(List.of(loanId));
|
||||
}
|
||||
|
||||
protected void reAgeLoan(Long loanId, String frequency, String startDate, Integer numberOfInstallments) {
|
||||
PostLoansLoanIdTransactionsRequest request = new PostLoansLoanIdTransactionsRequest();
|
||||
request.setDateFormat(DATETIME_PATTERN);
|
||||
request.setLocale("en");
|
||||
request.setFrequency(frequency);
|
||||
request.setStartDate(startDate);
|
||||
request.setNumberOfInstallments(numberOfInstallments);
|
||||
loanTransactionHelper.reAge(loanId, request);
|
||||
}
|
||||
|
||||
protected void undoReAgeLoan(Long loanId) {
|
||||
loanTransactionHelper.undoReAge(loanId, new PostLoansLoanIdTransactionsRequest());
|
||||
}
|
||||
|
||||
protected void verifyLastClosedBusinessDate(Long loanId, String lastClosedBusinessDate) {
|
||||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId);
|
||||
Assertions.assertNotNull(loanDetails.getLastClosedBusinessDate());
|
||||
@@ -554,7 +578,11 @@ public abstract class BaseLoanIntegrationTest {
|
||||
}
|
||||
|
||||
protected Transaction transaction(double principalAmount, String type, String date) {
|
||||
return new Transaction(principalAmount, type, date);
|
||||
return new Transaction(principalAmount, type, date, null);
|
||||
}
|
||||
|
||||
protected Transaction reversedTransaction(double principalAmount, String type, String date) {
|
||||
return new Transaction(principalAmount, type, date, true);
|
||||
}
|
||||
|
||||
protected TransactionExt transaction(double amount, String type, String date, double outstandingAmount, double principalPortion,
|
||||
@@ -657,6 +685,7 @@ public abstract class BaseLoanIntegrationTest {
|
||||
Double amount;
|
||||
String type;
|
||||
String date;
|
||||
Boolean reversed;
|
||||
}
|
||||
|
||||
@ToString
|
||||
@@ -711,6 +740,7 @@ public abstract class BaseLoanIntegrationTest {
|
||||
public static class RepaymentFrequencyType {
|
||||
|
||||
public static final Integer MONTHS = 2;
|
||||
public static final String MONTHS_STRING = "MONTHS";
|
||||
}
|
||||
|
||||
public static class InterestCalculationPeriodType {
|
||||
|
||||
+10
@@ -500,6 +500,16 @@ public class ExternalEventConfigurationHelper {
|
||||
loanAccountCustomSnapshotBusinessEvent.put("enabled", false);
|
||||
defaults.add(loanAccountCustomSnapshotBusinessEvent);
|
||||
|
||||
Map<String, Object> loanReAgeTransactionBusinessEvent = new HashMap<>();
|
||||
loanReAgeTransactionBusinessEvent.put("type", "LoanReAgeTransactionBusinessEvent");
|
||||
loanReAgeTransactionBusinessEvent.put("enabled", false);
|
||||
defaults.add(loanReAgeTransactionBusinessEvent);
|
||||
|
||||
Map<String, Object> loanUndoReAgeTransactionBusinessEvent = new HashMap<>();
|
||||
loanUndoReAgeTransactionBusinessEvent.put("type", "LoanUndoReAgeTransactionBusinessEvent");
|
||||
loanUndoReAgeTransactionBusinessEvent.put("enabled", false);
|
||||
defaults.add(loanUndoReAgeTransactionBusinessEvent);
|
||||
|
||||
return defaults;
|
||||
|
||||
}
|
||||
|
||||
+8
@@ -589,6 +589,14 @@ public class LoanTransactionHelper extends IntegrationTest {
|
||||
return ok(fineract().loanTransactions.executeLoanTransaction(loanId, request, "repayment"));
|
||||
}
|
||||
|
||||
public PostLoansLoanIdTransactionsResponse reAge(final Long loanId, final PostLoansLoanIdTransactionsRequest request) {
|
||||
return ok(fineract().loanTransactions.executeLoanTransaction(loanId, request, "reAge"));
|
||||
}
|
||||
|
||||
public PostLoansLoanIdTransactionsResponse undoReAge(final Long loanId, final PostLoansLoanIdTransactionsRequest request) {
|
||||
return ok(fineract().loanTransactions.executeLoanTransaction(loanId, request, "undoReAge"));
|
||||
}
|
||||
|
||||
public PutChargeTransactionChangesResponse undoWaiveLoanCharge(final Long loanId, final Long transactionId,
|
||||
final PutChargeTransactionChangesRequest request) {
|
||||
log.info("--------------------------------- UNDO WAIVE CHARGES FOR LOAN --------------------------------");
|
||||
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.loan.reaging;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import org.apache.fineract.client.models.PostLoanProductsRequest;
|
||||
import org.apache.fineract.client.models.PostLoanProductsResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.PostLoansRequest;
|
||||
import org.apache.fineract.client.models.PostLoansResponse;
|
||||
import org.apache.fineract.integrationtests.BaseLoanIntegrationTest;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class LoanReAgingIntegrationTest extends BaseLoanIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void test_LoanReAgeTransaction_Works() {
|
||||
AtomicLong createdLoanId = new AtomicLong();
|
||||
|
||||
runAt("01 January 2023", () -> {
|
||||
// Create Client
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
|
||||
int numberOfRepayments = 1;
|
||||
int repaymentEvery = 1;
|
||||
|
||||
// Create Loan Product
|
||||
PostLoanProductsRequest product = createOnePeriod30DaysLongNoInterestPeriodicAccrualProduct() //
|
||||
.numberOfRepayments(numberOfRepayments) //
|
||||
.repaymentEvery(repaymentEvery) //
|
||||
.repaymentFrequencyType(RepaymentFrequencyType.MONTHS.longValue()); //
|
||||
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(product);
|
||||
Long loanProductId = loanProductResponse.getResourceId();
|
||||
|
||||
// Apply and Approve Loan
|
||||
double amount = 1250.0;
|
||||
|
||||
PostLoansRequest applicationRequest = applyLoanRequest(clientId, loanProductId, "01 January 2023", amount, numberOfRepayments)//
|
||||
.repaymentEvery(repaymentEvery)//
|
||||
.loanTermFrequency(numberOfRepayments)//
|
||||
.repaymentFrequencyType(RepaymentFrequencyType.MONTHS)//
|
||||
.loanTermFrequencyType(RepaymentFrequencyType.MONTHS);
|
||||
|
||||
PostLoansResponse postLoansResponse = loanTransactionHelper.applyLoan(applicationRequest);
|
||||
|
||||
PostLoansLoanIdResponse approvedLoanResult = loanTransactionHelper.approveLoan(postLoansResponse.getResourceId(),
|
||||
approveLoanRequest(amount, "01 January 2023"));
|
||||
|
||||
Long loanId = approvedLoanResult.getLoanId();
|
||||
|
||||
// disburse Loan
|
||||
disburseLoan(loanId, BigDecimal.valueOf(1250.0), "01 January 2023");
|
||||
|
||||
// verify transactions
|
||||
verifyTransactions(loanId, //
|
||||
transaction(1250.0, "Disbursement", "01 January 2023") //
|
||||
);
|
||||
|
||||
// verify schedule
|
||||
verifyRepaymentSchedule(loanId, //
|
||||
installment(0, null, "01 January 2023"), //
|
||||
installment(1250.0, false, "01 February 2023") //
|
||||
);
|
||||
|
||||
createdLoanId.set(loanId);
|
||||
});
|
||||
|
||||
runAt("02 February 2023", () -> {
|
||||
long loanId = createdLoanId.get();
|
||||
|
||||
// create re-age transaction
|
||||
reAgeLoan(loanId, RepaymentFrequencyType.MONTHS_STRING, "02 February 2023", 6);
|
||||
|
||||
// verify transactions
|
||||
verifyTransactions(loanId, //
|
||||
transaction(1250.0, "Disbursement", "01 January 2023"), //
|
||||
transaction(1250.0, "Re-age", "02 February 2023") //
|
||||
);
|
||||
|
||||
// TODO: verify installments when schedule generation is implemented
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_LoanUndoReAgeTransaction_Works() {
|
||||
AtomicLong createdLoanId = new AtomicLong();
|
||||
|
||||
runAt("01 January 2023", () -> {
|
||||
// Create Client
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
|
||||
int numberOfRepayments = 1;
|
||||
int repaymentEvery = 1;
|
||||
|
||||
// Create Loan Product
|
||||
PostLoanProductsRequest product = createOnePeriod30DaysLongNoInterestPeriodicAccrualProduct() //
|
||||
.numberOfRepayments(numberOfRepayments) //
|
||||
.repaymentEvery(repaymentEvery) //
|
||||
.repaymentFrequencyType(RepaymentFrequencyType.MONTHS.longValue()); //
|
||||
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(product);
|
||||
Long loanProductId = loanProductResponse.getResourceId();
|
||||
|
||||
// Apply and Approve Loan
|
||||
double amount = 1250.0;
|
||||
|
||||
PostLoansRequest applicationRequest = applyLoanRequest(clientId, loanProductId, "01 January 2023", amount, numberOfRepayments)//
|
||||
.repaymentEvery(repaymentEvery)//
|
||||
.loanTermFrequency(numberOfRepayments)//
|
||||
.repaymentFrequencyType(RepaymentFrequencyType.MONTHS)//
|
||||
.loanTermFrequencyType(RepaymentFrequencyType.MONTHS);
|
||||
|
||||
PostLoansResponse postLoansResponse = loanTransactionHelper.applyLoan(applicationRequest);
|
||||
|
||||
PostLoansLoanIdResponse approvedLoanResult = loanTransactionHelper.approveLoan(postLoansResponse.getResourceId(),
|
||||
approveLoanRequest(amount, "01 January 2023"));
|
||||
|
||||
Long loanId = approvedLoanResult.getLoanId();
|
||||
|
||||
// disburse Loan
|
||||
disburseLoan(loanId, BigDecimal.valueOf(1250.0), "01 January 2023");
|
||||
|
||||
// verify transactions
|
||||
verifyTransactions(loanId, //
|
||||
transaction(1250.0, "Disbursement", "01 January 2023") //
|
||||
);
|
||||
|
||||
// verify schedule
|
||||
verifyRepaymentSchedule(loanId, //
|
||||
installment(0, null, "01 January 2023"), //
|
||||
installment(1250.0, false, "01 February 2023") //
|
||||
);
|
||||
|
||||
createdLoanId.set(loanId);
|
||||
});
|
||||
|
||||
runAt("02 February 2023", () -> {
|
||||
long loanId = createdLoanId.get();
|
||||
|
||||
// create re-age transaction
|
||||
reAgeLoan(loanId, RepaymentFrequencyType.MONTHS_STRING, "02 February 2023", 6);
|
||||
|
||||
// verify transactions
|
||||
verifyTransactions(loanId, //
|
||||
transaction(1250.0, "Disbursement", "01 January 2023"), //
|
||||
transaction(1250.0, "Re-age", "02 February 2023") //
|
||||
);
|
||||
});
|
||||
|
||||
runAt("03 February 2023", () -> {
|
||||
long loanId = createdLoanId.get();
|
||||
|
||||
// create re-age transaction
|
||||
undoReAgeLoan(loanId);
|
||||
|
||||
// verify transactions
|
||||
verifyTransactions(loanId, //
|
||||
transaction(1250.0, "Disbursement", "01 January 2023"), //
|
||||
reversedTransaction(1250.0, "Re-age", "02 February 2023") //
|
||||
);
|
||||
|
||||
// TODO: verify installments when schedule generation is implemented
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user