FINERACT-1971: Delinquency evaluation should be happen only for Active Loans

This commit is contained in:
Jose Alberto Hernandez
2024-01-18 14:07:19 +01:00
committed by Adam Saghy
parent 189b94bd19
commit e169b5cd61
2 changed files with 69 additions and 2 deletions
@@ -126,6 +126,11 @@ public class DelinquencyReadPlatformServiceImpl implements DelinquencyReadPlatfo
if (optLoan.isPresent()) {
final Loan loan = optLoan.get();
// If the Loan is not Active yet, return template data
if (loan.isSubmittedAndPendingApproval() || loan.isApproved()) {
return CollectionData.template();
}
final List<LoanDelinquencyAction> savedDelinquencyList = retrieveLoanDelinquencyActions(loanId);
List<LoanDelinquencyActionData> effectiveDelinquencyList = delinquencyEffectivePauseHelper
.calculateEffectiveDelinquencyList(savedDelinquencyList);
@@ -1571,6 +1571,58 @@ public class DelinquencyBucketsIntegrationTest {
}
}
@Test
public void testLoanClassificationOnyForActiveLoan() {
// Given
final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
ArrayList<Integer> rangeIds = new ArrayList<>();
// First Range
String jsonRange = DelinquencyRangesHelper.getAsJSON(4, 30);
PostDelinquencyRangeResponse delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec,
jsonRange);
rangeIds.add(delinquencyRangeResponse.getResourceId());
String jsonBucket = DelinquencyBucketsHelper.getAsJSON(rangeIds);
PostDelinquencyBucketResponse delinquencyBucketResponse = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec,
responseSpec, jsonBucket);
assertNotNull(delinquencyBucketResponse);
final GetDelinquencyBucketsResponse delinquencyBucket = DelinquencyBucketsHelper.getDelinquencyBucket(requestSpec, responseSpec,
delinquencyBucketResponse.getResourceId());
// Client and Loan account creation
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper,
Math.toIntExact(delinquencyBucket.getId()), null);
assertNotNull(getLoanProductsProductResponse);
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
// Older date to have more than one overdue installment
LocalDate transactionDate = todaysDate.minusDays(37);
String operationDate = Utils.dateFormatter.format(transactionDate);
// Create Loan Application
final Integer loanId = createLoanApplication(loanTransactionHelper, clientId.toString(),
getLoanProductsProductResponse.getId().toString(), operationDate, null);
// Evaluate default delinquent values in No Active Loan
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getDelinquent());
assertEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentDays());
assertEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentAmount());
// Loan Disbursement
disburseLoanAccount(loanTransactionHelper, loanId, operationDate);
// Evaluate default delinquent values in No Active Loan
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getDelinquent());
assertNotEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentDays());
assertNotEquals(0, getLoansLoanIdResponse.getDelinquent().getDelinquentAmount());
}
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
final Integer delinquencyBucketId, final String inArrearsTolerance) {
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().withInArrearsTolerance(inArrearsTolerance).build(null,
@@ -1595,8 +1647,8 @@ public class DelinquencyBucketsIntegrationTest {
return loanTransactionHelper.updateLoanProduct(id, requestModifyLoan);
}
private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId,
final String operationDate, final String inArrearsTolerance) {
private Integer createLoanApplication(final LoanTransactionHelper loanTransactionHelper, final String clientId,
final String loanProductId, final String operationDate, final String inArrearsTolerance) {
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(principalAmount).withLoanTermFrequency("12")
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("12").withRepaymentEveryAfter("1")
.withRepaymentFrequencyTypeAsMonths() //
@@ -1608,7 +1660,17 @@ public class DelinquencyBucketsIntegrationTest {
.build(clientId, loanProductId, null);
final Integer loanId = loanTransactionHelper.getLoanId(loanApplicationJSON);
loanTransactionHelper.approveLoan(operationDate, principalAmount, loanId, null);
return loanId;
}
private void disburseLoanAccount(final LoanTransactionHelper loanTransactionHelper, final Integer loanId, final String operationDate) {
loanTransactionHelper.disburseLoanWithNetDisbursalAmount(operationDate, loanId, principalAmount);
}
private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId,
final String operationDate, final String inArrearsTolerance) {
final Integer loanId = createLoanApplication(loanTransactionHelper, clientId, loanProductId, operationDate, inArrearsTolerance);
disburseLoanAccount(loanTransactionHelper, loanId, operationDate);
return loanId;
}