Delinquency classification including Chargeback transactions
This commit is contained in:
committed by
Arnold Gálovics
parent
cce7902054
commit
90f1eccd4b
+192
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.GetDelinquencyBucketsResponse;
|
||||
import org.apache.fineract.client.models.GetDelinquencyRangesResponse;
|
||||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.products.DelinquencyBucketsHelper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Slf4j
|
||||
public class DelinquencyAndChargebackIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private static final String principalAmount = "1200.00";
|
||||
private static final Double doubleZERO = Double.valueOf("0.00");
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
|
||||
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
|
||||
loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationStepAsPartOfCOB() {
|
||||
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
LocalDate businessDate = todaysDate.minusDays(57);
|
||||
log.info("Current Business date {}", businessDate);
|
||||
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, businessDate);
|
||||
|
||||
final SchedulerJobHelper schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
// Delinquency Bucket
|
||||
final Integer delinquencyBucketId = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, responseSpec);
|
||||
final GetDelinquencyBucketsResponse delinquencyBucket = DelinquencyBucketsHelper.getDelinquencyBucket(requestSpec, responseSpec,
|
||||
delinquencyBucketId);
|
||||
|
||||
// Client and Loan account creation
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
|
||||
final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper,
|
||||
delinquencyBucket.getId());
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
// Older date to have more than one overdue installment
|
||||
LocalDate transactionDate = businessDate;
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
log.info("Operation date {}", transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
// Run first time the Loan COB Job
|
||||
final String jobName = "Loan COB";
|
||||
schedulerJobHelper.executeAndAwaitJob(jobName);
|
||||
|
||||
// Get loan details expecting to have not a delinquency classification
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
validateLoanAccount(getLoansLoanIdResponse, "0.00", principalAmount, 0, doubleZERO);
|
||||
|
||||
// Move the Business date to get older the loan and to have an overdue loan
|
||||
businessDate = businessDate.plusDays(43);
|
||||
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, businessDate);
|
||||
log.info("Current Business date {}", businessDate);
|
||||
|
||||
String amountVal = "100.00";
|
||||
Float transactionAmount = Float.valueOf(amountVal);
|
||||
PostLoansLoanIdTransactionsResponse loanIdTransactionsResponse = loanTransactionHelper.makeLoanRepayment(operationDate,
|
||||
transactionAmount, loanId);
|
||||
assertNotNull(loanIdTransactionsResponse);
|
||||
final Integer transactionId = loanIdTransactionsResponse.getResourceId();
|
||||
loanTransactionHelper.reviewLoanTransactionRelations(loanId, transactionId, 0);
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
validateLoanAccount(getLoansLoanIdResponse, "0.00", "1100.00", 0, doubleZERO);
|
||||
|
||||
final Integer chargebackTransactionId = loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, amountVal, 0,
|
||||
responseSpec);
|
||||
loanTransactionHelper.reviewLoanTransactionRelations(loanId, transactionId, 1);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// Past Due Days in Zero because the Charge back transaction exists and It was done with the current date
|
||||
validateLoanAccount(getLoansLoanIdResponse, amountVal, principalAmount, 0, Double.valueOf("100.00"));
|
||||
|
||||
// Move the Business date to get older the loan and to have an overdue loan
|
||||
businessDate = businessDate.plusDays(9);
|
||||
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, businessDate);
|
||||
log.info("Current Business date {}", businessDate);
|
||||
// Run Second time the Job
|
||||
schedulerJobHelper.executeAndAwaitJob(jobName);
|
||||
|
||||
// Get loan details expecting to have a delinquency classification
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
|
||||
// The value is lower due the 3 grace days
|
||||
validateLoanAccount(getLoansLoanIdResponse, "100.00", principalAmount, 9, Double.valueOf("100.00"));
|
||||
|
||||
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
|
||||
}
|
||||
|
||||
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
|
||||
final Integer delinquencyBucketId) {
|
||||
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId);
|
||||
final Integer loanProductId = loanTransactionHelper.getLoanProductId(Utils.convertToJson(loanProductMap));
|
||||
return loanTransactionHelper.getLoanProduct(loanProductId);
|
||||
}
|
||||
|
||||
private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId,
|
||||
final String operationDate) {
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(principalAmount).withLoanTermFrequency("12")
|
||||
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("12").withRepaymentEveryAfter("1")
|
||||
.withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("0") //
|
||||
.withExpectedDisbursementDate(operationDate) //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withSubmittedOnDate(operationDate) //
|
||||
.build(clientId, loanProductId, null);
|
||||
final Integer loanId = loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
loanTransactionHelper.approveLoan(operationDate, principalAmount, loanId, null);
|
||||
loanTransactionHelper.disburseLoanWithNetDisbursalAmount(operationDate, loanId, principalAmount);
|
||||
return loanId;
|
||||
}
|
||||
|
||||
private GetDelinquencyRangesResponse validateLoanAccount(GetLoansLoanIdResponse getLoansLoanIdResponse, final String adjustments,
|
||||
final String outstanding, Integer pastDueDays, Double delinquentAmount) {
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
final GetDelinquencyRangesResponse delinquencyRange = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
|
||||
log.info("Loan Delinquency Range is null {}", (delinquencyRange == null));
|
||||
if (delinquencyRange != null) {
|
||||
log.info("Loan Delinquency Range is {}", delinquencyRange.getClassification());
|
||||
}
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
loanTransactionHelper.evaluateLoanSummaryAdjustments(getLoansLoanIdResponse, Double.valueOf(adjustments));
|
||||
DelinquencyBucketsHelper.evaluateLoanCollectionData(getLoansLoanIdResponse, pastDueDays, delinquentAmount);
|
||||
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, Double.valueOf(outstanding));
|
||||
|
||||
return delinquencyRange;
|
||||
}
|
||||
|
||||
}
|
||||
+394
-397
@@ -234,12 +234,394 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, response403Spec, jsonBucket);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationRealtime() {
|
||||
// Given
|
||||
final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
ArrayList<Integer> rangeIds = new ArrayList<>();
|
||||
// First Range
|
||||
String jsonRange = DelinquencyRangesHelper.getAsJSON(1, 3);
|
||||
PostDelinquencyRangeResponse delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec,
|
||||
jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
jsonRange = DelinquencyRangesHelper.getAsJSON(4, 60);
|
||||
|
||||
GetDelinquencyRangesResponse range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec,
|
||||
delinquencyRangeResponse.getResourceId());
|
||||
|
||||
// Second Range
|
||||
delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
|
||||
range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec, delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after Disbursement {}", classificationExpected);
|
||||
|
||||
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,
|
||||
delinquencyBucket.getId());
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
// Older date to have more than one overdue installment
|
||||
final LocalDate transactionDate = todaysDate.minusDays(50);
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange().getClassification());
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// First Loan Delinquency Classification after Disbursement command
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
// Apply a partial repayment
|
||||
operationDate = Utils.dateFormatter.format(todaysDate);
|
||||
loanTransactionHelper.makeLoanRepayment(operationDate, 100.0f, loanId);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// First Loan Delinquency Classification remains after Repayment because the installment is not fully paid
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
|
||||
// Apply a repayment to get a full paid installment
|
||||
loanTransactionHelper.makeLoanRepayment(operationDate, 1000.0f, loanId);
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// The Loan Delinquency Classification after Repayment command must be null
|
||||
assertNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// Get the Delinquency Tags
|
||||
ArrayList<GetDelinquencyTagHistoryResponse> getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec,
|
||||
responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
assertEquals(1, getDelinquencyTagsHistory.size());
|
||||
assertNotNull(getDelinquencyTagsHistory.get(0).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getLiftedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getDelinquencyRange().getClassification(), classificationExpected);
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(0).getLiftedOnDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationRealtimeWithCharges() {
|
||||
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
|
||||
|
||||
// Given
|
||||
final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
ArrayList<Integer> rangeIds = new ArrayList<>();
|
||||
// First Range
|
||||
String jsonRange = DelinquencyRangesHelper.getAsJSON(1, 3);
|
||||
PostDelinquencyRangeResponse delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec,
|
||||
jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
jsonRange = DelinquencyRangesHelper.getAsJSON(4, 60);
|
||||
|
||||
GetDelinquencyRangesResponse range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec,
|
||||
delinquencyRangeResponse.getResourceId());
|
||||
|
||||
// Second Range
|
||||
delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
|
||||
range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec, delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after Disbursement {}", classificationExpected);
|
||||
|
||||
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,
|
||||
delinquencyBucket.getId());
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
// Older date to have more than one overdue installment
|
||||
LocalDate transactionDate = todaysDate.minusMonths(2).minusDays(5);
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange().getClassification());
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// First Loan Delinquency Classification after Disbursement command
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
// Apply a repayment to get a full paid installment
|
||||
operationDate = Utils.dateFormatter.format(todaysDate);
|
||||
loanTransactionHelper.makeLoanRepayment(operationDate, 2049.99f, loanId);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// The Loan Delinquency Classification after Repayment command must be null
|
||||
log.info("Loan Delinquency Range after Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
transactionDate = todaysDate.minusDays(18);
|
||||
operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create and apply Charge for Specific Due Date
|
||||
final Integer chargeId = ChargesHelper.createCharges(requestSpec, responseSpec,
|
||||
ChargesHelper.getLoanSpecifiedDueDateJSON(1, "30", false));
|
||||
assertNotNull(chargeId);
|
||||
final Integer loanChargeId = loanTransactionHelper.addChargesForLoan(loanId, getChargeApplyJSON(chargeId, operationDate),
|
||||
responseSpec);
|
||||
assertNotNull(loanChargeId);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
log.info("Loan Delinquency Range after add Loan Charge {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// Evaluate a Delinquency Tag set after add charge to the Loan
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationRealtimeOlderLoan() {
|
||||
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
|
||||
|
||||
// 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());
|
||||
GetDelinquencyRangesResponse range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec,
|
||||
delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected02 = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after first repayment {}", classificationExpected02);
|
||||
|
||||
// Second Range
|
||||
jsonRange = DelinquencyRangesHelper.getAsJSON(31, 60);
|
||||
delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
|
||||
range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec, delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected01 = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after Disbursement {}", classificationExpected01);
|
||||
|
||||
// Third Range
|
||||
jsonRange = DelinquencyRangesHelper.getAsJSON(61, 90);
|
||||
delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
|
||||
range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec, 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,
|
||||
delinquencyBucket.getId());
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
// Older date to have more than one overdue installment
|
||||
LocalDate transactionDate = todaysDate.minusDays(85);
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
log.info("Loan Delinquency Range after Disbursement in null? {}", (getLoansLoanIdResponse.getDelinquencyRange() == null));
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// First Loan Delinquency Classification after Disbursement command
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected01);
|
||||
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
// Apply a repayment to get a first full paid installment
|
||||
transactionDate = todaysDate.minusDays(1);
|
||||
operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
PostLoansLoanIdTransactionsResponse loansLoanIdTransactions = loanTransactionHelper.makeLoanRepayment(operationDate, 1050.0f,
|
||||
loanId);
|
||||
assertNotNull(loansLoanIdTransactions);
|
||||
log.info("Loan repayment transaction id {}", loansLoanIdTransactions.getResourceId());
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after first Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// First Loan Delinquency Classification remains after Repayment because the installment is not fully paid
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected02);
|
||||
|
||||
ArrayList<GetDelinquencyTagHistoryResponse> getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec,
|
||||
responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(0).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getLiftedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getDelinquencyRange().getClassification(), classificationExpected01);
|
||||
log.info("Loan Id {} with Loan status {}", getLoansLoanIdResponse.getId(), getLoansLoanIdResponse.getStatus().getCode());
|
||||
|
||||
// Apply a repayment to get a second full paid installment
|
||||
loansLoanIdTransactions = loanTransactionHelper.makeLoanRepayment(operationDate, 1020.0f, loanId);
|
||||
assertNotNull(loansLoanIdTransactions);
|
||||
log.info("Loan repayment transaction id {}", loansLoanIdTransactions.getResourceId());
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after second Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// The Loan Delinquency Classification after Repayment command must be null
|
||||
assertNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
|
||||
getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(1).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getLiftedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getDelinquencyRange().getClassification(), classificationExpected02);
|
||||
log.info("Loan Id {} with final Loan status {}", getLoansLoanIdResponse.getId(), getLoansLoanIdResponse.getStatus().getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationRealtimeWithReversedRepayment() {
|
||||
// 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());
|
||||
GetDelinquencyRangesResponse range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec,
|
||||
delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after first repayment {}", classificationExpected);
|
||||
|
||||
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,
|
||||
delinquencyBucket.getId());
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
log.info("Local date of Tenant: {}", todaysDate);
|
||||
|
||||
// Older date to have more than one overdue installment
|
||||
final LocalDate transactionDate = todaysDate.minusDays(50);
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
loanTransactionHelper.printDelinquencyData(getLoansLoanIdResponse);
|
||||
|
||||
log.info("Loan Delinquency Range after Disbursement in null? {}", (getLoansLoanIdResponse.getDelinquencyRange() == null));
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// First Loan Delinquency Classification after Disbursement command
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
// Apply a repayment to get a full paid installment
|
||||
operationDate = Utils.dateFormatter.format(todaysDate);
|
||||
PostLoansLoanIdTransactionsResponse loansLoanIdTransactions = loanTransactionHelper.makeLoanRepayment(operationDate, 1050.0f,
|
||||
loanId);
|
||||
assertNotNull(loansLoanIdTransactions);
|
||||
log.info("Loan repayment transaction id {}", loansLoanIdTransactions.getResourceId());
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// Loan Delinquency Classification removed after Repayment because the installment is fully paid
|
||||
assertNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
|
||||
ArrayList<GetDelinquencyTagHistoryResponse> getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec,
|
||||
responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(0).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getLiftedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getDelinquencyRange().getClassification(), classificationExpected);
|
||||
log.info("Loan Id {} with Loan status {}", getLoansLoanIdResponse.getId(), getLoansLoanIdResponse.getStatus().getCode());
|
||||
|
||||
// Reverse the Previous Loan Repayment
|
||||
PostLoansLoanIdTransactionsResponse loansLoanIdReverseTransactions = loanTransactionHelper.reverseLoanTransaction(loanId,
|
||||
loansLoanIdTransactions.getResourceId(), operationDate, responseSpec);
|
||||
assertNotNull(loansLoanIdReverseTransactions);
|
||||
log.info("Loan repayment reverse transaction id {}", loansLoanIdReverseTransactions.getResourceId());
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Reverse Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// Loan Delinquency Classification goes back after Repayment because the installment is not paid
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
|
||||
getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(1).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
// Second record is open with liftedOn in null
|
||||
assertNull(getDelinquencyTagsHistory.get(1).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getDelinquencyRange().getClassification(), classificationExpected);
|
||||
log.info("Loan Id {} with final Loan status {}", getLoansLoanIdResponse.getId(), getLoansLoanIdResponse.getStatus().getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationJob() {
|
||||
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
|
||||
|
||||
LocalDate businessDate = Utils.getLocalDateOfTenant();
|
||||
businessDate = businessDate.minusDays(57);
|
||||
businessDate = businessDate.minusDays(37);
|
||||
log.info("Current date {}", businessDate);
|
||||
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, businessDate);
|
||||
|
||||
@@ -277,7 +659,7 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
// Older date to have more than one overdue installment
|
||||
final LocalDate transactionDate = todaysDate.minusDays(65);
|
||||
final LocalDate transactionDate = todaysDate.minusDays(57);
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
@@ -290,19 +672,13 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
|
||||
// Get loan details expecting to have not a delinquency classification
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
loanTransactionHelper.printDelinquencyData(getLoansLoanIdResponse);
|
||||
final GetDelinquencyRangesResponse firstTestCase = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
log.info("Loan Delinquency Range is null {}", (firstTestCase == null));
|
||||
GetLoansLoanIdRepaymentSchedule getLoanRepaymentSchedule = getLoansLoanIdResponse.getRepaymentSchedule();
|
||||
if (getLoanRepaymentSchedule != null) {
|
||||
log.info("Loan with {} periods", getLoanRepaymentSchedule.getPeriods().size());
|
||||
for (GetLoansLoanIdRepaymentPeriod period : getLoanRepaymentSchedule.getPeriods()) {
|
||||
log.info("Period number {} for due date {} and outstanding {}", period.getPeriod(), period.getDueDate(),
|
||||
period.getTotalOutstandingForPeriod());
|
||||
}
|
||||
}
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
// Move the Business date to get older the loan and to have an overdue loan
|
||||
businessDate = businessDate.plusDays(40);
|
||||
businessDate = businessDate.plusMonths(1);
|
||||
log.info("Current date {}", businessDate);
|
||||
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, businessDate);
|
||||
// Run Second time the Job
|
||||
@@ -310,7 +686,11 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
|
||||
// Get loan details expecting to have a delinquency classification
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
loanTransactionHelper.printDelinquencyData(getLoansLoanIdResponse);
|
||||
|
||||
final GetDelinquencyRangesResponse secondTestCase = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
assertNotNull(secondTestCase);
|
||||
log.info("Loan Delinquency Range is {}", secondTestCase.getClassification());
|
||||
|
||||
// Then
|
||||
@@ -318,7 +698,6 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
assertNull(firstTestCase);
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
assertNotNull(secondTestCase);
|
||||
assertEquals(secondTestCase.getClassification(), classificationExpected);
|
||||
|
||||
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
|
||||
@@ -402,7 +781,7 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
}
|
||||
|
||||
// Move the Business date to get older the loan and to have an overdue loan
|
||||
businessDate = businessDate.plusDays(40);
|
||||
businessDate = businessDate.plusDays(50);
|
||||
log.info("Current date {}", businessDate);
|
||||
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, businessDate);
|
||||
// Run Second time the Job
|
||||
@@ -410,7 +789,9 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
|
||||
// Get loan details expecting to have a delinquency classification
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
final GetDelinquencyRangesResponse secondTestCase = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
assertNotNull(secondTestCase);
|
||||
log.info("Loan Delinquency Range is {}", secondTestCase.getClassification());
|
||||
|
||||
// Then
|
||||
@@ -418,384 +799,11 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
assertNull(firstTestCase);
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
assertNotNull(secondTestCase);
|
||||
assertEquals(secondTestCase.getClassification(), classificationExpected);
|
||||
|
||||
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationRealtime() {
|
||||
// Given
|
||||
final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
ArrayList<Integer> rangeIds = new ArrayList<>();
|
||||
// First Range
|
||||
String jsonRange = DelinquencyRangesHelper.getAsJSON(1, 3);
|
||||
PostDelinquencyRangeResponse delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec,
|
||||
jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
jsonRange = DelinquencyRangesHelper.getAsJSON(4, 60);
|
||||
|
||||
GetDelinquencyRangesResponse range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec,
|
||||
delinquencyRangeResponse.getResourceId());
|
||||
|
||||
// Second Range
|
||||
delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
|
||||
range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec, delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after Disbursement {}", classificationExpected);
|
||||
|
||||
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,
|
||||
delinquencyBucket.getId());
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
// Older date to have more than one overdue installment
|
||||
final LocalDate transactionDate = todaysDate.minusDays(45);
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange().getClassification());
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// First Loan Delinquency Classification after Disbursement command
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
// Apply a partial repayment
|
||||
operationDate = Utils.dateFormatter.format(todaysDate);
|
||||
loanTransactionHelper.makeLoanRepayment(operationDate, 100.0f, loanId);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// First Loan Delinquency Classification remains after Repayment because the installment is not fully paid
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
|
||||
// Apply a repayment to get a full paid installment
|
||||
loanTransactionHelper.makeLoanRepayment(operationDate, 1000.0f, loanId);
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// The Loan Delinquency Classification after Repayment command must be null
|
||||
assertNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// Get the Delinquency Tags
|
||||
ArrayList<GetDelinquencyTagHistoryResponse> getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec,
|
||||
responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
assertEquals(1, getDelinquencyTagsHistory.size());
|
||||
assertNotNull(getDelinquencyTagsHistory.get(0).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getLiftedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getDelinquencyRange().getClassification(), classificationExpected);
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(0).getLiftedOnDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationRealtimeWithCharges() {
|
||||
// Given
|
||||
final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
ArrayList<Integer> rangeIds = new ArrayList<>();
|
||||
// First Range
|
||||
String jsonRange = DelinquencyRangesHelper.getAsJSON(1, 3);
|
||||
PostDelinquencyRangeResponse delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec,
|
||||
jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
jsonRange = DelinquencyRangesHelper.getAsJSON(4, 60);
|
||||
|
||||
GetDelinquencyRangesResponse range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec,
|
||||
delinquencyRangeResponse.getResourceId());
|
||||
|
||||
// Second Range
|
||||
delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
|
||||
range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec, delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after Disbursement {}", classificationExpected);
|
||||
|
||||
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,
|
||||
delinquencyBucket.getId());
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
// Older date to have more than one overdue installment
|
||||
LocalDate transactionDate = todaysDate.minusDays(45);
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange().getClassification());
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// First Loan Delinquency Classification after Disbursement command
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
// Apply a repayment to get a full paid installment
|
||||
operationDate = Utils.dateFormatter.format(todaysDate);
|
||||
loanTransactionHelper.makeLoanRepayment(operationDate, 1033.33f, loanId);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// The Loan Delinquency Classification after Repayment command must be null
|
||||
assertNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
transactionDate = todaysDate.minusDays(18);
|
||||
operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create and apply Charge for Specific Due Date
|
||||
final Integer chargeId = ChargesHelper.createCharges(requestSpec, responseSpec,
|
||||
ChargesHelper.getLoanSpecifiedDueDateJSON(1, "30", false));
|
||||
assertNotNull(chargeId);
|
||||
final Integer loanChargeId = loanTransactionHelper.addChargesForLoan(loanId, getChargeApplyJSON(chargeId, operationDate),
|
||||
responseSpec);
|
||||
assertNotNull(loanChargeId);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
log.info("Loan Delinquency Range after add Loan Charge {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// Evaluate a Delinquency Tag set after add charge to the Loan
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationRealtimeOlderLoan() {
|
||||
// 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());
|
||||
GetDelinquencyRangesResponse range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec,
|
||||
delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected02 = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after first repayment {}", classificationExpected02);
|
||||
|
||||
// Second Range
|
||||
jsonRange = DelinquencyRangesHelper.getAsJSON(31, 60);
|
||||
delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
|
||||
range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec, delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected01 = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after Disbursement {}", classificationExpected01);
|
||||
|
||||
// Third Range
|
||||
jsonRange = DelinquencyRangesHelper.getAsJSON(61, 90);
|
||||
delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
|
||||
range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec, 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,
|
||||
delinquencyBucket.getId());
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
// Older date to have more than one overdue installment
|
||||
final LocalDate transactionDate = todaysDate.minusDays(85);
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
log.info("Loan Delinquency Range after Disbursement in null? {}", (getLoansLoanIdResponse.getDelinquencyRange() == null));
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// First Loan Delinquency Classification after Disbursement command
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected01);
|
||||
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
// Apply a repayment to get a first full paid installment
|
||||
operationDate = Utils.dateFormatter.format(todaysDate);
|
||||
PostLoansLoanIdTransactionsResponse loansLoanIdTransactions = loanTransactionHelper.makeLoanRepayment(operationDate, 1050.0f,
|
||||
loanId);
|
||||
assertNotNull(loansLoanIdTransactions);
|
||||
log.info("Loan repayment transaction id {}", loansLoanIdTransactions.getResourceId());
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after first Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// First Loan Delinquency Classification remains after Repayment because the installment is not fully paid
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected02);
|
||||
|
||||
ArrayList<GetDelinquencyTagHistoryResponse> getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec,
|
||||
responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(0).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getLiftedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getDelinquencyRange().getClassification(), classificationExpected01);
|
||||
log.info("Loan Id {} with Loan status {}", getLoansLoanIdResponse.getId(), getLoansLoanIdResponse.getStatus().getCode());
|
||||
|
||||
// Apply a repayment to get a second full paid installment
|
||||
loansLoanIdTransactions = loanTransactionHelper.makeLoanRepayment(operationDate, 1020.0f, loanId);
|
||||
assertNotNull(loansLoanIdTransactions);
|
||||
log.info("Loan repayment transaction id {}", loansLoanIdTransactions.getResourceId());
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after second Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
// The Loan Delinquency Classification after Repayment command must be null
|
||||
assertNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
|
||||
getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(1).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getLiftedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getDelinquencyRange().getClassification(), classificationExpected02);
|
||||
log.info("Loan Id {} with final Loan status {}", getLoansLoanIdResponse.getId(), getLoansLoanIdResponse.getStatus().getCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanClassificationRealtimeWithReversedRepayment() {
|
||||
// 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());
|
||||
GetDelinquencyRangesResponse range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec,
|
||||
delinquencyRangeResponse.getResourceId());
|
||||
final String classificationExpected = range.getClassification();
|
||||
log.info("Expected Delinquency Range classification after first repayment {}", classificationExpected);
|
||||
|
||||
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,
|
||||
delinquencyBucket.getId());
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
final LocalDate todaysDate = Utils.getLocalDateOfTenant();
|
||||
// Older date to have more than one overdue installment
|
||||
final LocalDate transactionDate = todaysDate.minusDays(45);
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
// Create Loan Account
|
||||
final Integer loanId = createLoanAccount(loanTransactionHelper, clientId.toString(),
|
||||
getLoanProductsProductResponse.getId().toString(), operationDate);
|
||||
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
log.info("Loan Delinquency Range after Disbursement in null? {}", (getLoansLoanIdResponse.getDelinquencyRange() == null));
|
||||
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// First Loan Delinquency Classification after Disbursement command
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
// Apply a repayment to get a full paid installment
|
||||
operationDate = Utils.dateFormatter.format(todaysDate);
|
||||
PostLoansLoanIdTransactionsResponse loansLoanIdTransactions = loanTransactionHelper.makeLoanRepayment(operationDate, 1050.0f,
|
||||
loanId);
|
||||
assertNotNull(loansLoanIdTransactions);
|
||||
log.info("Loan repayment transaction id {}", loansLoanIdTransactions.getResourceId());
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// Loan Delinquency Classification removed after Repayment because the installment is fully paid
|
||||
assertNull(getLoansLoanIdResponse.getDelinquencyRange());
|
||||
|
||||
ArrayList<GetDelinquencyTagHistoryResponse> getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec,
|
||||
responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(0).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getLiftedOnDate(), Utils.getLocalDateOfTenant());
|
||||
assertEquals(getDelinquencyTagsHistory.get(0).getDelinquencyRange().getClassification(), classificationExpected);
|
||||
log.info("Loan Id {} with Loan status {}", getLoansLoanIdResponse.getId(), getLoansLoanIdResponse.getStatus().getCode());
|
||||
|
||||
// Reverse the Previous Loan Repayment
|
||||
PostLoansLoanIdTransactionsResponse loansLoanIdReverseTransactions = loanTransactionHelper.reverseLoanTransaction(loanId,
|
||||
loansLoanIdTransactions.getResourceId(), operationDate, responseSpec);
|
||||
assertNotNull(loansLoanIdReverseTransactions);
|
||||
log.info("Loan repayment reverse transaction id {}", loansLoanIdReverseTransactions.getResourceId());
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
log.info("Loan Delinquency Range after Reverse Repayment {}", getLoansLoanIdResponse.getDelinquencyRange());
|
||||
// Loan Delinquency Classification goes back after Repayment because the installment is not paid
|
||||
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
|
||||
|
||||
getDelinquencyTagsHistory = loanTransactionHelper.getLoanDelinquencyTags(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getDelinquencyTagsHistory);
|
||||
log.info("Delinquency Tag History items {}", getDelinquencyTagsHistory.size());
|
||||
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(1).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getAddedOnDate(), Utils.getLocalDateOfTenant());
|
||||
// Second record is open with liftedOn in null
|
||||
assertNull(getDelinquencyTagsHistory.get(1).getLiftedOnDate());
|
||||
assertEquals(getDelinquencyTagsHistory.get(1).getDelinquencyRange().getClassification(), classificationExpected);
|
||||
log.info("Loan Id {} with final Loan status {}", getLoansLoanIdResponse.getId(), getLoansLoanIdResponse.getStatus().getCode());
|
||||
}
|
||||
|
||||
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
|
||||
final Integer delinquencyBucketId) {
|
||||
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId);
|
||||
@@ -819,17 +827,6 @@ public class DelinquencyBucketsIntegrationTest {
|
||||
return loanId;
|
||||
}
|
||||
|
||||
private void printRepaymentSchedule(GetLoansLoanIdResponse getLoansLoanIdResponse) {
|
||||
GetLoansLoanIdRepaymentSchedule getLoanRepaymentSchedule = getLoansLoanIdResponse.getRepaymentSchedule();
|
||||
if (getLoanRepaymentSchedule != null) {
|
||||
log.info("Loan with {} periods", getLoanRepaymentSchedule.getPeriods().size());
|
||||
for (GetLoansLoanIdRepaymentPeriod period : getLoanRepaymentSchedule.getPeriods()) {
|
||||
log.info("Period number {} for due date {} and outstanding {}", period.getPeriod(), period.getDueDate(),
|
||||
period.getTotalOutstandingForPeriod());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getChargeApplyJSON(final Integer chargeId, final String dueDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("chargeId", chargeId);
|
||||
|
||||
+68
-62
@@ -20,9 +20,8 @@ package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
@@ -30,26 +29,23 @@ import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.GetDelinquencyBucketsResponse;
|
||||
import org.apache.fineract.client.models.GetDelinquencyRangesResponse;
|
||||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentSchedule;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdSummary;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdTransactions;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionIdResponse;
|
||||
import org.apache.fineract.client.models.GetPaymentTypesResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsTransactionIdResponse;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.products.DelinquencyBucketsHelper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -99,7 +95,8 @@ public class LoanTransactionChargebackTest {
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 0, Double.valueOf("0.00"));
|
||||
|
||||
final Integer chargebackTransactionId = applyChargebackTransaction(loanId, transactionId, "1000.00", 0, responseSpec);
|
||||
final Integer chargebackTransactionId = loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, "1000.00", 0,
|
||||
responseSpec);
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 1, Double.valueOf("0.00"));
|
||||
reviewLoanTransactionRelations(loanId, chargebackTransactionId, 0, Double.valueOf("1000.00"));
|
||||
@@ -141,7 +138,8 @@ public class LoanTransactionChargebackTest {
|
||||
final Integer transactionId = loanIdTransactionsResponse.getResourceId();
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 0, Double.valueOf("666.67"));
|
||||
|
||||
final Integer chargebackTransactionId = applyChargebackTransaction(loanId, transactionId, amount.toString(), 0, responseSpec);
|
||||
final Integer chargebackTransactionId = loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, amount.toString(),
|
||||
0, responseSpec);
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 1, Double.valueOf("666.67"));
|
||||
reviewLoanTransactionRelations(loanId, chargebackTransactionId, 0, Double.valueOf("1000.00"));
|
||||
|
||||
@@ -160,7 +158,8 @@ public class LoanTransactionChargebackTest {
|
||||
}
|
||||
}
|
||||
|
||||
evaluateLoanSummaryAdjustments(getLoansLoanIdResponse, Double.valueOf(baseAmount));
|
||||
loanTransactionHelper.evaluateLoanSummaryAdjustments(getLoansLoanIdResponse, Double.valueOf(baseAmount));
|
||||
DelinquencyBucketsHelper.evaluateLoanCollectionData(getLoansLoanIdResponse, 0, Double.valueOf("333.33"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -179,7 +178,7 @@ public class LoanTransactionChargebackTest {
|
||||
log.info("Try to apply the Charge back over transaction Id {} with type {}", loanTransaction.getId(),
|
||||
loanTransaction.getType().getCode());
|
||||
|
||||
applyChargebackTransaction(loanId, loanTransaction.getId().intValue(), amountVal, 0, responseSpecError);
|
||||
loanTransactionHelper.applyChargebackTransaction(loanId, loanTransaction.getId().intValue(), amountVal, 0, responseSpecError);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,6 +190,11 @@ public class LoanTransactionChargebackTest {
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
GetDelinquencyRangesResponse delinquencyRange = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
assertNotNull(delinquencyRange);
|
||||
log.info("Loan Delinquency Range is {}", delinquencyRange.getClassification());
|
||||
|
||||
GetLoansLoanIdRepaymentSchedule getLoanRepaymentSchedule = getLoansLoanIdResponse.getRepaymentSchedule();
|
||||
log.info("Loan with {} periods", getLoanRepaymentSchedule.getPeriods().size());
|
||||
assertEquals(2, getLoanRepaymentSchedule.getPeriods().size());
|
||||
@@ -207,7 +211,8 @@ public class LoanTransactionChargebackTest {
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 0, Double.valueOf("0.00"));
|
||||
|
||||
Integer chargebackTransactionId = applyChargebackTransaction(loanId, transactionId, "500.00", 0, responseSpec);
|
||||
Integer chargebackTransactionId = loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, "500.00", 0,
|
||||
responseSpec);
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 1, Double.valueOf("0.00"));
|
||||
reviewLoanTransactionRelations(loanId, chargebackTransactionId, 0, Double.valueOf("500.00"));
|
||||
@@ -232,7 +237,7 @@ public class LoanTransactionChargebackTest {
|
||||
}
|
||||
}
|
||||
|
||||
chargebackTransactionId = applyChargebackTransaction(loanId, transactionId, "300.00", 0, responseSpec);
|
||||
chargebackTransactionId = loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, "300.00", 0, responseSpec);
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 2, Double.valueOf("0.00"));
|
||||
reviewLoanTransactionRelations(loanId, chargebackTransactionId, 0, Double.valueOf("800.00"));
|
||||
@@ -241,6 +246,10 @@ public class LoanTransactionChargebackTest {
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
loanTransactionHelper.validateLoanStatus(getLoansLoanIdResponse, "loanStatusType.active");
|
||||
|
||||
delinquencyRange = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
assertNull(delinquencyRange);
|
||||
log.info("Loan Delinquency Range is null {}", (delinquencyRange == null));
|
||||
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, Double.valueOf("800.00"));
|
||||
|
||||
// N+1 Scenario -- Remains the same periods number
|
||||
@@ -280,7 +289,8 @@ public class LoanTransactionChargebackTest {
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 0, Double.valueOf("0.00"));
|
||||
|
||||
final Integer chargebackTransactionId = applyChargebackTransaction(loanId, transactionId, "200.00", 0, responseSpec);
|
||||
final Integer chargebackTransactionId = loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, "200.00", 0,
|
||||
responseSpec);
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 1, Double.valueOf("0.00"));
|
||||
reviewLoanTransactionRelations(loanId, chargebackTransactionId, 0, Double.valueOf("100.00"));
|
||||
@@ -290,6 +300,10 @@ public class LoanTransactionChargebackTest {
|
||||
loanTransactionHelper.validateLoanStatus(getLoansLoanIdResponse, "loanStatusType.active");
|
||||
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, Double.valueOf("100.00"));
|
||||
|
||||
final GetDelinquencyRangesResponse delinquencyRange = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
assertNull(delinquencyRange);
|
||||
log.info("Loan Delinquency Range is null {}", (delinquencyRange == null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -314,7 +328,8 @@ public class LoanTransactionChargebackTest {
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 0, Double.valueOf("0.00"));
|
||||
|
||||
final Integer chargebackTransactionId = applyChargebackTransaction(loanId, transactionId, "100.00", 0, responseSpec);
|
||||
final Integer chargebackTransactionId = loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, "100.00", 0,
|
||||
responseSpec);
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 1, Double.valueOf("0.00"));
|
||||
reviewLoanTransactionRelations(loanId, chargebackTransactionId, 0, Double.valueOf("0.00"));
|
||||
@@ -348,8 +363,11 @@ public class LoanTransactionChargebackTest {
|
||||
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 0, Double.valueOf("0.00"));
|
||||
|
||||
final Integer chargebackTransactionId = applyChargebackTransaction(loanId, transactionId, "50.00", 0, responseSpec);
|
||||
|
||||
GetDelinquencyRangesResponse delinquencyRange = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
assertNull(delinquencyRange);
|
||||
log.info("Loan Delinquency Range is null {}", (delinquencyRange == null));
|
||||
final Integer chargebackTransactionId = loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, "50.00", 0,
|
||||
responseSpec);
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 1, Double.valueOf("0.00"));
|
||||
reviewLoanTransactionRelations(loanId, chargebackTransactionId, 0, Double.valueOf("0.00"));
|
||||
|
||||
@@ -357,6 +375,10 @@ public class LoanTransactionChargebackTest {
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
loanTransactionHelper.validateLoanStatus(getLoansLoanIdResponse, "loanStatusType.overpaid");
|
||||
|
||||
delinquencyRange = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
assertNull(delinquencyRange);
|
||||
log.info("Loan Delinquency Range is null {}", (delinquencyRange == null));
|
||||
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, Double.valueOf("0.00"));
|
||||
}
|
||||
|
||||
@@ -383,38 +405,56 @@ public class LoanTransactionChargebackTest {
|
||||
// First round, empty array
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 0, Double.valueOf("0.00"));
|
||||
|
||||
applyChargebackTransaction(loanId, transactionId, "200.00", 0, responseSpec);
|
||||
loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, "200.00", 0, responseSpec);
|
||||
|
||||
Double expectedAmount = Double.valueOf("200.00");
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, Double.valueOf("200.00"));
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, expectedAmount);
|
||||
|
||||
evaluateLoanSummaryAdjustments(getLoansLoanIdResponse, Double.valueOf("200.00"));
|
||||
loanTransactionHelper.evaluateLoanSummaryAdjustments(getLoansLoanIdResponse, expectedAmount);
|
||||
loanTransactionHelper.printDelinquencyData(getLoansLoanIdResponse);
|
||||
DelinquencyBucketsHelper.evaluateLoanCollectionData(getLoansLoanIdResponse, 0, expectedAmount);
|
||||
|
||||
// Second round, array size equal to 1
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 1, Double.valueOf("0.00"));
|
||||
|
||||
applyChargebackTransaction(loanId, transactionId, "300.00", 1, responseSpec);
|
||||
loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, "300.00", 1, responseSpec);
|
||||
|
||||
expectedAmount = Double.valueOf("500.00");
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, Double.valueOf("500.00"));
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, expectedAmount);
|
||||
|
||||
evaluateLoanSummaryAdjustments(getLoansLoanIdResponse, Double.valueOf("500.00"));
|
||||
loanTransactionHelper.evaluateLoanSummaryAdjustments(getLoansLoanIdResponse, expectedAmount);
|
||||
DelinquencyBucketsHelper.evaluateLoanCollectionData(getLoansLoanIdResponse, 0, expectedAmount);
|
||||
|
||||
// Third round, array size equal to 2
|
||||
reviewLoanTransactionRelations(loanId, transactionId, 2, Double.valueOf("0.00"));
|
||||
|
||||
applyChargebackTransaction(loanId, transactionId, "500.00", 0, responseSpec);
|
||||
loanTransactionHelper.applyChargebackTransaction(loanId, transactionId, "500.00", 0, responseSpec);
|
||||
|
||||
expectedAmount = Double.valueOf("1000.00");
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, Double.valueOf("1000.00"));
|
||||
loanTransactionHelper.validateLoanPrincipalOustandingBalance(getLoansLoanIdResponse, expectedAmount);
|
||||
|
||||
evaluateLoanSummaryAdjustments(getLoansLoanIdResponse, Double.valueOf("1000.00"));
|
||||
loanTransactionHelper.evaluateLoanSummaryAdjustments(getLoansLoanIdResponse, expectedAmount);
|
||||
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
|
||||
|
||||
DelinquencyBucketsHelper.evaluateLoanCollectionData(getLoansLoanIdResponse, 0, expectedAmount);
|
||||
}
|
||||
|
||||
private Integer createAccounts(final Integer daysToSubtract, final Integer numberOfRepayments) {
|
||||
// Delinquency Bucket
|
||||
final Integer delinquencyBucketId = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec, responseSpec);
|
||||
final GetDelinquencyBucketsResponse delinquencyBucket = DelinquencyBucketsHelper.getDelinquencyBucket(requestSpec, responseSpec,
|
||||
delinquencyBucketId);
|
||||
|
||||
// Client and Loan account creation
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
|
||||
final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper, null);
|
||||
final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper,
|
||||
delinquencyBucketId);
|
||||
assertNotNull(getLoanProductsProductResponse);
|
||||
log.info("Loan Product Bucket Name: {}", getLoanProductsProductResponse.getDelinquencyBucket().getName());
|
||||
assertEquals(getLoanProductsProductResponse.getDelinquencyBucket().getName(), delinquencyBucket.getName());
|
||||
|
||||
// Older date to have more than one overdue installment
|
||||
final LocalDate transactionDate = this.todaysDate.minusDays(daysToSubtract + (30 * (numberOfRepayments - 1)));
|
||||
@@ -424,16 +464,6 @@ public class LoanTransactionChargebackTest {
|
||||
operationDate, amountVal, numberOfRepayments.toString());
|
||||
}
|
||||
|
||||
private String createChargebackPayload(final String transactionAmount, final Integer paymentTypeId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("transactionAmount", transactionAmount);
|
||||
map.put("paymentTypeId", paymentTypeId);
|
||||
map.put("locale", CommonConstants.LOCALE);
|
||||
final String chargebackPayload = new Gson().toJson(map);
|
||||
log.info("{}", chargebackPayload);
|
||||
return chargebackPayload;
|
||||
}
|
||||
|
||||
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
|
||||
final Integer delinquencyBucketId) {
|
||||
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId);
|
||||
@@ -457,21 +487,6 @@ public class LoanTransactionChargebackTest {
|
||||
return loanId;
|
||||
}
|
||||
|
||||
private Integer applyChargebackTransaction(final Integer loanId, final Integer transactionId, final String amount,
|
||||
final Integer paymentTypeIdx, ResponseSpecification responseSpec) {
|
||||
List<GetPaymentTypesResponse> paymentTypeList = PaymentTypeHelper.getSystemPaymentType(this.requestSpec, this.responseSpec);
|
||||
assertTrue(!paymentTypeList.isEmpty());
|
||||
|
||||
final String payload = createChargebackPayload(amount, paymentTypeList.get(paymentTypeIdx).getId());
|
||||
log.info("Loan Chargeback: {}", payload);
|
||||
PostLoansLoanIdTransactionsTransactionIdResponse postLoansTransactionCommandResponse = loanTransactionHelper
|
||||
.applyLoanTransactionCommand(loanId, transactionId, "chargeback", payload, responseSpec);
|
||||
assertNotNull(postLoansTransactionCommandResponse);
|
||||
|
||||
log.info("Loan Chargeback Id: {}", postLoansTransactionCommandResponse.getResourceId());
|
||||
return postLoansTransactionCommandResponse.getResourceId();
|
||||
}
|
||||
|
||||
private void reviewLoanTransactionRelations(final Integer loanId, final Integer transactionId, final Integer expectedSize,
|
||||
final Double outstandingBalance) {
|
||||
log.info("Loan Transaction Id: {} {}", loanId, transactionId);
|
||||
@@ -487,13 +502,4 @@ public class LoanTransactionChargebackTest {
|
||||
assertEquals(outstandingBalance, getLoansTransactionResponse.getOutstandingLoanBalance());
|
||||
}
|
||||
|
||||
private void evaluateLoanSummaryAdjustments(GetLoansLoanIdResponse getLoansLoanIdResponse, Double amountExpected) {
|
||||
// Evaluate The Loan Summary Principal Adjustments
|
||||
GetLoansLoanIdSummary getLoansLoanIdSummary = getLoansLoanIdResponse.getSummary();
|
||||
if (getLoansLoanIdSummary != null) {
|
||||
log.info("Loan with Principal Adjustments {} expected {}", getLoansLoanIdSummary.getPrincipalAdjustments(), amountExpected);
|
||||
assertEquals(amountExpected, getLoansLoanIdSummary.getPrincipalAdjustments());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+55
-2
@@ -20,6 +20,7 @@ package org.apache.fineract.integrationtests.common.loans;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
@@ -43,11 +44,13 @@ import javax.ws.rs.core.MediaType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.GetDelinquencyTagHistoryResponse;
|
||||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdCollectionData;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentPeriod;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdRepaymentSchedule;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdSummary;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdTransactionsTransactionIdResponse;
|
||||
import org.apache.fineract.client.models.GetPaymentTypesResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
|
||||
@@ -55,6 +58,7 @@ import org.apache.fineract.client.models.PostLoansLoanIdTransactionsTransactionI
|
||||
import org.apache.fineract.client.models.PutLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.util.JSON;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
@@ -1155,12 +1159,19 @@ public class LoanTransactionHelper {
|
||||
if (getLoanRepaymentSchedule != null) {
|
||||
log.info("Loan with {} periods", getLoanRepaymentSchedule.getPeriods().size());
|
||||
for (GetLoansLoanIdRepaymentPeriod period : getLoanRepaymentSchedule.getPeriods()) {
|
||||
log.info("Period number {} for due date {} and outstanding {}", period.getPeriod(), period.getDueDate(),
|
||||
period.getTotalOutstandingForPeriod());
|
||||
log.info("Period number {} for due date {} and outstanding {} {}", period.getPeriod(), period.getDueDate(),
|
||||
period.getTotalOutstandingForPeriod(), period.getComplete());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void printDelinquencyData(GetLoansLoanIdResponse getLoansLoanIdResponse) {
|
||||
GetLoansLoanIdCollectionData getLoansLoanIdCollectionData = getLoansLoanIdResponse.getDelinquent();
|
||||
if (getLoansLoanIdCollectionData != null) {
|
||||
log.info("Loan Delinquency {}", getLoansLoanIdCollectionData.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void validateLoanStatus(GetLoansLoanIdResponse getLoansLoanIdResponse, final String statusCodeExpected) {
|
||||
final String statusCode = getLoansLoanIdResponse.getStatus().getCode();
|
||||
log.info("Loan with Id {} is with Status {}", getLoansLoanIdResponse.getId(), statusCode);
|
||||
@@ -1192,4 +1203,46 @@ public class LoanTransactionHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public Integer applyChargebackTransaction(final Integer loanId, final Integer transactionId, final String amount,
|
||||
final Integer paymentTypeIdx, ResponseSpecification responseSpec) {
|
||||
List<GetPaymentTypesResponse> paymentTypeList = PaymentTypeHelper.getSystemPaymentType(this.requestSpec, this.responseSpec);
|
||||
assertTrue(!paymentTypeList.isEmpty());
|
||||
|
||||
final String payload = createChargebackPayload(amount, paymentTypeList.get(paymentTypeIdx).getId());
|
||||
log.info("Loan Chargeback: {}", payload);
|
||||
PostLoansLoanIdTransactionsTransactionIdResponse postLoansTransactionCommandResponse = applyLoanTransactionCommand(loanId,
|
||||
transactionId, "chargeback", payload, responseSpec);
|
||||
assertNotNull(postLoansTransactionCommandResponse);
|
||||
|
||||
log.info("Loan Chargeback Id: {}", postLoansTransactionCommandResponse.getResourceId());
|
||||
return postLoansTransactionCommandResponse.getResourceId();
|
||||
}
|
||||
|
||||
public void reviewLoanTransactionRelations(final Integer loanId, final Integer transactionId, final Integer expectedSize) {
|
||||
GetLoansLoanIdTransactionsTransactionIdResponse getLoansTransactionResponse = getLoanTransaction(loanId, transactionId);
|
||||
assertNotNull(getLoansTransactionResponse);
|
||||
assertNotNull(getLoansTransactionResponse.getTransactionRelations());
|
||||
assertEquals(expectedSize, getLoansTransactionResponse.getTransactionRelations().size());
|
||||
log.info("Loan with {} Chargeback Transactions", getLoansTransactionResponse.getTransactionRelations().size());
|
||||
}
|
||||
|
||||
public void evaluateLoanSummaryAdjustments(GetLoansLoanIdResponse getLoansLoanIdResponse, Double amountExpected) {
|
||||
// Evaluate The Loan Summary Principal Adjustments
|
||||
GetLoansLoanIdSummary getLoansLoanIdSummary = getLoansLoanIdResponse.getSummary();
|
||||
if (getLoansLoanIdSummary != null) {
|
||||
log.info("Loan with Principal Adjustments {} expected {}", getLoansLoanIdSummary.getPrincipalAdjustments(), amountExpected);
|
||||
assertEquals(amountExpected, getLoansLoanIdSummary.getPrincipalAdjustments());
|
||||
}
|
||||
}
|
||||
|
||||
private String createChargebackPayload(final String transactionAmount, final Integer paymentTypeId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("transactionAmount", transactionAmount);
|
||||
map.put("paymentTypeId", paymentTypeId);
|
||||
map.put("locale", CommonConstants.LOCALE);
|
||||
final String chargebackPayload = new Gson().toJson(map);
|
||||
log.info("{}", chargebackPayload);
|
||||
return chargebackPayload;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+60
-6
@@ -18,6 +18,10 @@
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.products;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.linecorp.armeria.internal.shaded.guava.reflect.TypeToken;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
@@ -25,22 +29,24 @@ import io.restassured.specification.ResponseSpecification;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.DeleteDelinquencyBucketResponse;
|
||||
import org.apache.fineract.client.models.GetDelinquencyBucketsResponse;
|
||||
import org.apache.fineract.client.models.GetDelinquencyRangesResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdCollectionData;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.PostDelinquencyBucketResponse;
|
||||
import org.apache.fineract.client.models.PostDelinquencyRangeResponse;
|
||||
import org.apache.fineract.client.models.PutDelinquencyBucketResponse;
|
||||
import org.apache.fineract.client.util.JSON;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Slf4j
|
||||
public class DelinquencyBucketsHelper {
|
||||
|
||||
private static final String DELINQUENCY_BUCKETS_URL = "/fineract-provider/api/v1/delinquency/buckets";
|
||||
private static final Gson GSON = new JSON().getGson();
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DelinquencyBucketsHelper.class);
|
||||
|
||||
protected DelinquencyBucketsHelper() {}
|
||||
|
||||
public static ArrayList<GetDelinquencyBucketsResponse> getDelinquencyBuckets(final RequestSpecification requestSpec,
|
||||
@@ -60,7 +66,7 @@ public class DelinquencyBucketsHelper {
|
||||
|
||||
public static PostDelinquencyBucketResponse createDelinquencyBucket(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String json) {
|
||||
LOG.info("JSON: {}", json);
|
||||
log.info("JSON: {}", json);
|
||||
final String response = Utils.performServerPost(requestSpec, responseSpec, DELINQUENCY_BUCKETS_URL + "?" + Utils.TENANT_IDENTIFIER,
|
||||
json, null);
|
||||
return GSON.fromJson(response, PostDelinquencyBucketResponse.class);
|
||||
@@ -68,7 +74,7 @@ public class DelinquencyBucketsHelper {
|
||||
|
||||
public static PutDelinquencyBucketResponse updateDelinquencyBucket(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final Integer resourceId, final String json) {
|
||||
LOG.info("JSON: {}", json);
|
||||
log.info("JSON: {}", json);
|
||||
final String response = Utils.performServerPut(requestSpec, responseSpec,
|
||||
DELINQUENCY_BUCKETS_URL + "/" + resourceId + "?" + Utils.TENANT_IDENTIFIER, json, null);
|
||||
return GSON.fromJson(response, PutDelinquencyBucketResponse.class);
|
||||
@@ -88,4 +94,52 @@ public class DelinquencyBucketsHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static Integer createDelinquencyBucket(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
ArrayList<Integer> rangeIds = new ArrayList<>();
|
||||
|
||||
// First Range
|
||||
String jsonRange = DelinquencyRangesHelper.getAsJSON(1, 3);
|
||||
PostDelinquencyRangeResponse delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec,
|
||||
jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
jsonRange = DelinquencyRangesHelper.getAsJSON(4, 60);
|
||||
GetDelinquencyRangesResponse range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec,
|
||||
delinquencyRangeResponse.getResourceId());
|
||||
|
||||
// Second Range
|
||||
delinquencyRangeResponse = DelinquencyRangesHelper.createDelinquencyRange(requestSpec, responseSpec, jsonRange);
|
||||
rangeIds.add(delinquencyRangeResponse.getResourceId());
|
||||
range = DelinquencyRangesHelper.getDelinquencyRange(requestSpec, responseSpec, delinquencyRangeResponse.getResourceId());
|
||||
|
||||
String jsonBucket = DelinquencyBucketsHelper.getAsJSON(rangeIds);
|
||||
PostDelinquencyBucketResponse delinquencyBucketResponse = DelinquencyBucketsHelper.createDelinquencyBucket(requestSpec,
|
||||
responseSpec, jsonBucket);
|
||||
assertNotNull(delinquencyBucketResponse);
|
||||
|
||||
return delinquencyBucketResponse.getResourceId();
|
||||
}
|
||||
|
||||
public static void evaluateLoanCollectionData(GetLoansLoanIdResponse getLoansLoanIdResponse, Integer pastDueDays,
|
||||
Double amountExpected) {
|
||||
GetLoansLoanIdCollectionData getCollectionData = getLoansLoanIdResponse.getDelinquent();
|
||||
if (getCollectionData != null) {
|
||||
log.info("Loan Delinquency Data in Days {} and Amount {}", getCollectionData.getPastDueDays(),
|
||||
getCollectionData.getDelinquentAmount());
|
||||
assertEquals(pastDueDays, getCollectionData.getPastDueDays());
|
||||
assertEquals(amountExpected, getCollectionData.getDelinquentAmount());
|
||||
} else {
|
||||
log.info("Loan Delinquency Data is null");
|
||||
}
|
||||
|
||||
GetDelinquencyRangesResponse delinquencyRange = getLoansLoanIdResponse.getDelinquencyRange();
|
||||
if (delinquencyRange != null) {
|
||||
log.info("Loan Delinquency Classification is {} : ({} - {}) {}", delinquencyRange.getClassification(),
|
||||
delinquencyRange.getMinimumAgeDays(), delinquencyRange.getMaximumAgeDays(), pastDueDays);
|
||||
assertTrue(delinquencyRange.getMinimumAgeDays() <= pastDueDays);
|
||||
assertTrue(delinquencyRange.getMaximumAgeDays() >= pastDueDays);
|
||||
} else {
|
||||
log.info("Loan Delinquency Classification is null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ public class DelinquencyRangesHelper {
|
||||
|
||||
public static String getAsJSON(int minimumAgeDays, int maximumAgeDays) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("classification", Utils.randomNameGenerator("Delinquency_", 4));
|
||||
map.put("classification", Utils.randomNameGenerator("Delinquency__" + minimumAgeDays + "_" + maximumAgeDays + "__", 4));
|
||||
map.put("minimumAgeDays", minimumAgeDays);
|
||||
map.put("maximumAgeDays", maximumAgeDays);
|
||||
map.put("locale", "en");
|
||||
|
||||
Reference in New Issue
Block a user