FINERACT-1971: Loan transaction processing strategy validation fix

This commit is contained in:
taskain7
2023-12-15 14:02:50 +01:00
committed by Adam Saghy
parent b9314d0b1e
commit f981ffe519
2 changed files with 53 additions and 12 deletions
@@ -396,6 +396,14 @@ public final class LoanApplicationCommandFromApiJsonHelper {
.extractStringNamed(LoanApiConstants.transactionProcessingStrategyCodeParameterName, element); .extractStringNamed(LoanApiConstants.transactionProcessingStrategyCodeParameterName, element);
baseDataValidator.reset().parameter(LoanApiConstants.transactionProcessingStrategyCodeParameterName) baseDataValidator.reset().parameter(LoanApiConstants.transactionProcessingStrategyCodeParameterName)
.value(transactionProcessingStrategy).notNull(); .value(transactionProcessingStrategy).notNull();
if (!AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY
.equals(loanProduct.getTransactionProcessingStrategyCode())
&& AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY.equals(transactionProcessingStrategy)) {
baseDataValidator.reset().parameter(LoanApiConstants.transactionProcessingStrategyCodeParameterName).failWithCode(
"strategy.cannot.be.advanced.payment.allocation.if.not.configured",
"Loan transaction processing strategy cannot be Advanced Payment Allocation Strategy if it's not configured on loan product");
}
// Validating whether the processor is existing // Validating whether the processor is existing
loanRepaymentScheduleTransactionProcessorFactory.determineProcessor(transactionProcessingStrategy); loanRepaymentScheduleTransactionProcessorFactory.determineProcessor(transactionProcessingStrategy);
@@ -670,6 +678,14 @@ public final class LoanApplicationCommandFromApiJsonHelper {
loanRepaymentScheduleTransactionProcessorFactory.determineProcessor(transactionProcessingStrategy); loanRepaymentScheduleTransactionProcessorFactory.determineProcessor(transactionProcessingStrategy);
} }
if (!AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY
.equals(loanProduct.getTransactionProcessingStrategyCode())
&& AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY.equals(transactionProcessingStrategy)) {
baseDataValidator.reset().parameter(LoanApiConstants.transactionProcessingStrategyCodeParameterName).failWithCode(
"strategy.cannot.be.advanced.payment.allocation.if.not.configured",
"Loan transaction processing strategy cannot be Advanced Payment Allocation Strategy if it's not configured on loan product");
}
BigDecimal principal = null; BigDecimal principal = null;
if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.principalParameterName, element)) { if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.principalParameterName, element)) {
atLeastOneParameterPassedForUpdate = true; atLeastOneParameterPassedForUpdate = true;
@@ -29,6 +29,7 @@ import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CollateralManagementHelper; import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
import org.apache.fineract.integrationtests.common.CommonConstants; import org.apache.fineract.integrationtests.common.CommonConstants;
@@ -38,18 +39,18 @@ import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker; import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension; import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.apache.fineract.portfolio.loanaccount.domain.transactionprocessor.impl.AdvancedPaymentScheduleTransactionProcessor;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@ExtendWith(LoanTestLifecycleExtension.class) @ExtendWith(LoanTestLifecycleExtension.class)
@Slf4j
public class LoanApplicationApprovalTest { public class LoanApplicationApprovalTest {
private static final Logger LOG = LoggerFactory.getLogger(LoanApplicationApprovalTest.class); private static final String DATETIME_PATTERN = "dd MMMM yyyy";
private ResponseSpecification responseSpec; private ResponseSpecification responseSpec;
private ResponseSpecification responseSpecForStatusCode403; private ResponseSpecification responseSpecForStatusCode403;
private ResponseSpecification responseSpecForStatusCode400; private ResponseSpecification responseSpecForStatusCode400;
@@ -136,16 +137,41 @@ public class LoanApplicationApprovalTest {
createTranches.add(createTrancheDetail("23 March 2014", "4000")); createTranches.add(createTrancheDetail("23 March 2014", "4000"));
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014"); final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
LOG.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientID); log.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientID);
final Integer loanProductID = this.loanTransactionHelper final Integer loanProductID = this.loanTransactionHelper
.getLoanProductId(new LoanProductTestBuilder().withInterestTypeAsDecliningBalance().withTranches(true) .getLoanProductId(new LoanProductTestBuilder().withInterestTypeAsDecliningBalance().withTranches(true)
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null)); .withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null));
LOG.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}", log.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}",
loanProductID); loanProductID);
this.trancheLoansApprovedAmountLesserThanProposedAmount(clientID, loanProductID, createTranches); this.trancheLoansApprovedAmountLesserThanProposedAmount(clientID, loanProductID, createTranches);
this.trancheLoansApprovalValidation(clientID, loanProductID, createTranches); this.trancheLoansApprovalValidation(clientID, loanProductID, createTranches);
}
@Test
public void loanApplicationShouldFailIfTransactionProcessingStrategyIsAdvancedPaymentAllocationButItIsNotConfiguredOnProduct() {
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
log.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientId);
final Integer loanProductId = this.loanTransactionHelper
.getLoanProductId(new LoanProductTestBuilder().withInterestTypeAsDecliningBalance().withTranches(true)
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null));
log.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}",
loanProductId);
loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode400);
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal("1000").withLoanTermFrequency("1")
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("1").withRepaymentEveryAfter("1")
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("0").withInterestTypeAsFlatBalance()
.withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
.withExpectedDisbursementDate("01 March 2022").withSubmittedOnDate("01 March 2022").withLoanType("individual")
.withRepaymentStrategy(AdvancedPaymentScheduleTransactionProcessor.ADVANCED_PAYMENT_ALLOCATION_STRATEGY)
.build(clientId.toString(), loanProductId.toString(), null);
List<HashMap> error = (List<HashMap>) loanTransactionHelper.createLoanAccount(loanApplicationJSON, CommonConstants.RESPONSE_ERROR);
assertEquals(
"validation.msg.loan.transactionProcessingStrategyCode.strategy.cannot.be.advanced.payment.allocation.if.not.configured",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} }
@@ -160,17 +186,17 @@ public class LoanApplicationApprovalTest {
approveTranches.add(createTrancheDetail("23 March 2014", "1000")); approveTranches.add(createTrancheDetail("23 March 2014", "1000"));
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches); final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
LOG.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID); log.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------"); log.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount, loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
loanID, approveTranches); loanID, approveTranches);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap); LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
LOG.info("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------"); log.info("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------");
} }
@@ -205,12 +231,12 @@ public class LoanApplicationApprovalTest {
approveTranche4.add(createTrancheDetail("24 March 2014", "100")); approveTranche4.add(createTrancheDetail("24 March 2014", "100"));
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches); final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
LOG.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID); log.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
HashMap<String, Object> loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); HashMap<String, Object> loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------"); log.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode400); this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode400);
/* Tranches with same expected disbursement date */ /* Tranches with same expected disbursement date */
@@ -278,7 +304,7 @@ public class LoanApplicationApprovalTest {
public Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal, public Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal,
List<HashMap> tranches) { List<HashMap> tranches) {
LOG.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); log.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
List<HashMap> collaterals = new ArrayList<>(); List<HashMap> collaterals = new ArrayList<>();
final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec); final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
Assertions.assertNotNull(collateralId); Assertions.assertNotNull(collateralId);
@@ -304,5 +330,4 @@ public class LoanApplicationApprovalTest {
return this.loanTransactionHelper.getLoanId(loanApplicationJSON); return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
} }
} }