Skip to content

Commit

Permalink
FINERACT-1971: Enhance validation for installment level delinquency f…
Browse files Browse the repository at this point in the history
…or loan product
  • Loading branch information
ruchiD authored and adamsaghy committed May 14, 2024
1 parent bcf04b7 commit b108ca9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ public void validateForCreate(final JsonCommand command) {
// Validating whether the processor is existing
loanRepaymentScheduleTransactionProcessorFactory.determineProcessor(transactionProcessingStrategyCode);

Long delinquencyBucketId = null;
if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.DELINQUENCY_BUCKET_PARAM_NAME, element)) {
final Long delinquencyBucketId = this.fromApiJsonHelper.extractLongNamed(LoanProductConstants.DELINQUENCY_BUCKET_PARAM_NAME,
element);
delinquencyBucketId = this.fromApiJsonHelper.extractLongNamed(LoanProductConstants.DELINQUENCY_BUCKET_PARAM_NAME, element);
baseDataValidator.reset().parameter(LoanProductConstants.DELINQUENCY_BUCKET_PARAM_NAME).value(delinquencyBucketId)
.ignoreIfNull().integerGreaterThanZero();
}
Expand Down Expand Up @@ -785,6 +785,13 @@ public void validateForCreate(final JsonCommand command) {
.extractBooleanNamed(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY, element);
baseDataValidator.reset().parameter(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY)
.value(enableInstallmentLevelDelinquency).ignoreIfNull().validateForBooleanValue();
if (delinquencyBucketId == null) {
if (enableInstallmentLevelDelinquency) {
baseDataValidator.reset().parameter(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY).failWithCode(
"can.be.enabled.for.loan.product.having.valid.delinquency.bucket",
"Installment level delinquency cannot be enabled if Delinquency bucket is not configured for loan product");
}
}
}

String loanScheduleType = LoanScheduleType.CUMULATIVE.name();
Expand Down Expand Up @@ -1301,9 +1308,9 @@ public void validateForUpdate(final JsonCommand command, final LoanProduct loanP
.integerZeroOrGreater();
}

Long delinquencyBucketId = null;
if (this.fromApiJsonHelper.parameterExists(LoanProductConstants.DELINQUENCY_BUCKET_PARAM_NAME, element)) {
final Long delinquencyBucketId = this.fromApiJsonHelper.extractLongNamed(LoanProductConstants.DELINQUENCY_BUCKET_PARAM_NAME,
element);
delinquencyBucketId = this.fromApiJsonHelper.extractLongNamed(LoanProductConstants.DELINQUENCY_BUCKET_PARAM_NAME, element);
baseDataValidator.reset().parameter(LoanProductConstants.DELINQUENCY_BUCKET_PARAM_NAME).value(delinquencyBucketId)
.ignoreIfNull().integerGreaterThanZero();
}
Expand Down Expand Up @@ -1770,6 +1777,13 @@ public void validateForUpdate(final JsonCommand command, final LoanProduct loanP
.extractBooleanNamed(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY, element);
baseDataValidator.reset().parameter(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY)
.value(enableInstallmentLevelDelinquency).ignoreIfNull().validateForBooleanValue();
if (delinquencyBucketId == null) {
if (enableInstallmentLevelDelinquency) {
baseDataValidator.reset().parameter(LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY).failWithCode(
"can.be.enabled.for.loan.product.having.valid.delinquency.bucket",
"Installment level delinquency cannot be enabled if Delinquency bucket is not configured for loan product");
}
}
}

String loanScheduleType = loanProduct.getLoanProductRelatedDetail().getLoanScheduleType().name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void testSnapshotEventGenerationWhenLoanInstallmentIsNotPayed() {
// Create Loan Product
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);

// Apply and Approve Loan
Expand Down Expand Up @@ -112,7 +111,6 @@ public void testNoSnapshotEventGenerationWhenLoanInstallmentIsPayed() {
// Create Loan Product
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);

// Apply and Approve Loan
Expand Down Expand Up @@ -169,7 +167,6 @@ public void testNoSnapshotEventGenerationWhenWhenCustomSnapshotEventCOBTaskIsNot
// Create Loan Product
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);

// Apply and Approve Loan
Expand Down Expand Up @@ -215,7 +212,6 @@ public void testNoSnapshotEventGenerationWhenCOBDateIsNotMatchingWithInstallment
// Create Loan Product
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);

// Apply and Approve Loan
Expand Down Expand Up @@ -259,7 +255,6 @@ public void testNoSnapshotEventGenerationWhenCustomSnapshotEventIsDisabled() {
// Create Loan Product
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);

// Apply and Approve Loan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
import org.apache.fineract.client.models.PostLoanProductsRequest;
import org.apache.fineract.client.models.PostLoanProductsResponse;
import org.apache.fineract.client.models.PutLoanProductsProductIdRequest;
import org.apache.fineract.client.util.CallFailedRuntimeException;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
Expand Down Expand Up @@ -410,6 +411,55 @@ public void tesInstallmentLevelSettingForLoanWithLoanProductWithoutDelinquencyBu

}

@Test
public void tesInstallmentLevelSettingForLoanProductWithoutDelinquencyBucketValidation() {

runAt("31 May 2023", () -> {
// Create Client
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();

// Create Loan Product without delinquency bucket
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
// set installment level delinquency as true
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);

// Create loan product with installment level delinquency setting
CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class,
() -> loanProductHelper.createLoanProduct(loanProductsRequest));

Assertions.assertTrue(callFailedRuntimeException.getMessage()
.contains("Installment level delinquency cannot be enabled if Delinquency bucket is not configured for loan product"));

});

}

@Test
public void tesUpdateInstallmentLevelSettingForLoanProductWithoutDelinquencyBucketValidation() {

runAt("31 May 2023", () -> {
// Create Client
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();

// Create Loan Product without delinquency bucket
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);

PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);

// Update loan product with installment level delinquency setting
CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class,
() -> loanProductHelper.updateLoanProductById(loanProductResponse.getResourceId(),
new PutLoanProductsProductIdRequest().enableInstallmentLevelDelinquency(true).locale("en")));

Assertions.assertTrue(callFailedRuntimeException.getMessage()
.contains("Installment level delinquency cannot be enabled if Delinquency bucket is not configured for loan product"));

});

}

private void updateBusinessDateAndExecuteCOBJob(String date) {
businessDateHelper.updateBusinessDate(
new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en"));
Expand Down

0 comments on commit b108ca9

Please sign in to comment.