FINERACT-1724: Delinquency classification tests were failing

This commit is contained in:
Jose Alberto Hernandez
2023-03-08 15:43:18 +01:00
committed by Adam Saghy
parent 367550007c
commit 18811e57b3
3 changed files with 49 additions and 26 deletions
@@ -34,6 +34,7 @@ import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.models.BusinessDateResponse;
import org.apache.fineract.client.models.DeleteDelinquencyBucketResponse;
import org.apache.fineract.client.models.DeleteDelinquencyRangeResponse;
import org.apache.fineract.client.models.GetDelinquencyBucketsResponse;
@@ -64,7 +65,6 @@ import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.apache.fineract.integrationtests.common.products.DelinquencyBucketsHelper;
import org.apache.fineract.integrationtests.common.products.DelinquencyRangesHelper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@Slf4j
@@ -72,6 +72,7 @@ public class DelinquencyBucketsIntegrationTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
private BusinessDateHelper businessDateHelper;
private static final String principalAmount = "10000";
@BeforeEach
@@ -81,6 +82,7 @@ public class DelinquencyBucketsIntegrationTest {
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.businessDateHelper = new BusinessDateHelper();
}
@Test
@@ -236,10 +238,16 @@ public class DelinquencyBucketsIntegrationTest {
}
@Test
@Disabled("It was failing at the beginning of some moths")
public void testLoanClassificationRealtime() {
// Given
final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
final LocalDate bussinesLocalDate = Utils.getDateAsLocalDate("01 March 2012");
log.info("Current date {}", bussinesLocalDate);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, bussinesLocalDate);
final BusinessDateResponse businessDateResponse = this.businessDateHelper.getBusinessDateByType(requestSpec, responseSpec,
BusinessDateType.BUSINESS_DATE);
ArrayList<Integer> rangeIds = new ArrayList<>();
// First Range
@@ -275,9 +283,8 @@ public class DelinquencyBucketsIntegrationTest {
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);
final LocalDate transactionDate = bussinesLocalDate.minusDays(50);
String operationDate = Utils.dateFormatter.format(transactionDate);
// Create Loan Account
@@ -285,15 +292,16 @@ public class DelinquencyBucketsIntegrationTest {
getLoanProductsProductResponse.getId().toString(), operationDate);
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange().getClassification());
assertNotNull(getLoansLoanIdResponse);
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
log.info("Loan Delinquency Range after Disbursement {}", getLoansLoanIdResponse.getDelinquencyRange().getClassification());
// First Loan Delinquency Classification after Disbursement command
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
// Apply a partial repayment
operationDate = Utils.dateFormatter.format(todaysDate);
operationDate = Utils.dateFormatter.format(bussinesLocalDate);
loanTransactionHelper.makeLoanRepayment(operationDate, 100.0f, loanId);
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
@@ -316,16 +324,20 @@ public class DelinquencyBucketsIntegrationTest {
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).getAddedOnDate(), businessDateResponse.getDate());
assertEquals(getDelinquencyTagsHistory.get(0).getLiftedOnDate(), businessDateResponse.getDate());
assertEquals(getDelinquencyTagsHistory.get(0).getDelinquencyRange().getClassification(), classificationExpected);
log.info("Delinquency Tag Item with Lifted On {}", getDelinquencyTagsHistory.get(0).getLiftedOnDate());
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
}
@Test
@Disabled("It was failing at the beginning of some moths")
public void testLoanClassificationRealtimeWithCharges() {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
final LocalDate bussinesLocalDate = Utils.getDateAsLocalDate("01 April 2012");
log.info("Current date {}", bussinesLocalDate);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, bussinesLocalDate);
// Given
final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
@@ -364,9 +376,8 @@ public class DelinquencyBucketsIntegrationTest {
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);
LocalDate transactionDate = bussinesLocalDate.minusMonths(2).minusDays(5);
String operationDate = Utils.dateFormatter.format(transactionDate);
// Create Loan Account
@@ -381,7 +392,7 @@ public class DelinquencyBucketsIntegrationTest {
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
// Apply a repayment to get a full paid installment
operationDate = Utils.dateFormatter.format(todaysDate);
operationDate = Utils.dateFormatter.format(bussinesLocalDate);
loanTransactionHelper.makeLoanRepayment(operationDate, 2049.99f, loanId);
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
@@ -391,7 +402,7 @@ public class DelinquencyBucketsIntegrationTest {
assertNull(getLoansLoanIdResponse.getDelinquencyRange());
loanTransactionHelper.printRepaymentSchedule(getLoansLoanIdResponse);
transactionDate = todaysDate.minusDays(18);
transactionDate = bussinesLocalDate.minusDays(18);
operationDate = Utils.dateFormatter.format(transactionDate);
// Create and apply Charge for Specific Due Date
@@ -409,6 +420,7 @@ public class DelinquencyBucketsIntegrationTest {
assertNotNull(getLoansLoanIdResponse.getDelinquencyRange());
// Evaluate a Delinquency Tag set after add charge to the Loan
assertEquals(getLoansLoanIdResponse.getDelinquencyRange().getClassification(), classificationExpected);
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
}
@Test
@@ -706,15 +718,13 @@ public class DelinquencyBucketsIntegrationTest {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.FALSE);
}
@Disabled("Failing test.Need rework")
@Test
public void testLoanClassificationStepAsPartOfCOB() {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, Boolean.TRUE);
LocalDate businessDate = Utils.getLocalDateOfTenant();
businessDate = businessDate.minusDays(4);
log.info("Current date {}", businessDate);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, businessDate);
LocalDate bussinesLocalDate = Utils.getDateAsLocalDate("01 April 2012");
log.info("Current date {}", bussinesLocalDate);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, bussinesLocalDate);
// Given
final LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
@@ -748,9 +758,8 @@ public class DelinquencyBucketsIntegrationTest {
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(33);
final LocalDate transactionDate = bussinesLocalDate.minusDays(31);
String operationDate = Utils.dateFormatter.format(transactionDate);
// Create Loan Account
@@ -784,11 +793,11 @@ public class DelinquencyBucketsIntegrationTest {
}
// Move the Business date to get older the loan and to have an overdue loan
LocalDate lastLoanCOBBusinessDate = businessDate;
businessDate = businessDate.plusDays(3);
schedulerJobHelper.fastForwardTime(lastLoanCOBBusinessDate, businessDate, jobName, responseSpec);
log.info("Current date {}", businessDate);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, businessDate);
LocalDate lastLoanCOBBusinessDate = bussinesLocalDate;
bussinesLocalDate = bussinesLocalDate.plusDays(3);
schedulerJobHelper.fastForwardTime(lastLoanCOBBusinessDate, bussinesLocalDate, jobName, responseSpec);
log.info("Current date {}", bussinesLocalDate);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, bussinesLocalDate);
// Run Second time the Job
schedulerJobHelper.executeAndAwaitJob(jobName);
@@ -27,12 +27,15 @@ import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.models.BusinessDateRequest;
import org.apache.fineract.client.models.BusinessDateResponse;
import org.apache.fineract.client.util.JSON;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.integrationtests.client.IntegrationTest;
@Slf4j
public final class BusinessDateHelper extends IntegrationTest {
private static final Gson GSON = new JSON().getGson();
public BusinessDateHelper() {}
public static HashMap updateBusinessDate(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
@@ -49,6 +52,14 @@ public final class BusinessDateHelper extends IntegrationTest {
return ok(fineract().businessDateManagement.updateBusinessDate(request));
}
public BusinessDateResponse getBusinessDateByType(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final BusinessDateType type) {
final String BUSINESS_DATE_API = "/fineract-provider/api/v1/businessdate/" + type.name() + "?" + Utils.TENANT_IDENTIFIER;
final String response = Utils.performServerGet(requestSpec, responseSpec, BUSINESS_DATE_API);
log.info("{}", response);
return GSON.fromJson(response, BusinessDateResponse.class);
}
public BusinessDateResponse getBusinessDate(final String type) {
return ok(fineract().businessDateManagement.getBusinessDate(type));
}
@@ -461,4 +461,7 @@ public final class Utils {
return new Gson().toJson(map);
}
public static LocalDate getDateAsLocalDate(String dateAsString) {
return LocalDate.parse(dateAsString, dateFormatter);
}
}