peter-kovacs-dpc commented on code in PR #5584:
URL: https://github.com/apache/fineract/pull/5584#discussion_r2918913297


##########
fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/WorkingCapitalProductLoanAccountStepDef.java:
##########
@@ -0,0 +1,618 @@
+/**
+ * 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.test.stepdef.loan;
+
+import static org.apache.fineract.client.feign.util.FeignCalls.fail;
+import static org.apache.fineract.client.feign.util.FeignCalls.ok;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.cucumber.datatable.DataTable;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
+import java.math.BigDecimal;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Map;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.client.feign.FineractFeignClient;
+import org.apache.fineract.client.feign.util.CallFailedRuntimeException;
+import 
org.apache.fineract.client.models.DeleteWorkingCapitalLoansLoanIdResponse;
+import org.apache.fineract.client.models.GetWorkingCapitalLoansLoanIdResponse;
+import org.apache.fineract.client.models.PostClientsResponse;
+import org.apache.fineract.client.models.PostWorkingCapitalLoansRequest;
+import org.apache.fineract.client.models.PostWorkingCapitalLoansResponse;
+import org.apache.fineract.client.models.PutWorkingCapitalLoansLoanIdRequest;
+import org.apache.fineract.client.models.PutWorkingCapitalLoansLoanIdResponse;
+import 
org.apache.fineract.test.data.workingcapitalproduct.DefaultWorkingCapitalLoanProduct;
+import 
org.apache.fineract.test.data.workingcapitalproduct.WorkingCapitalLoanProductResolver;
+import org.apache.fineract.test.factory.WorkingCapitalLoanRequestFactory;
+import org.apache.fineract.test.messaging.event.EventCheckHelper;
+import org.apache.fineract.test.stepdef.AbstractStepDef;
+import org.apache.fineract.test.support.TestContextKey;
+
+@Slf4j
+@RequiredArgsConstructor
+public class WorkingCapitalProductLoanAccountStepDef extends AbstractStepDef {
+
+    private static final String DATE_FORMAT = "dd MMMM yyyy";
+    private static final DateTimeFormatter FORMATTER = 
DateTimeFormatter.ofPattern(DATE_FORMAT);
+    private static final Long NON_EXISTENT_LOAN_ID = 999_999_999L;
+
+    private final FineractFeignClient fineractClient;
+    private final WorkingCapitalLoanProductResolver 
workingCapitalLoanProductResolver;
+    private final WorkingCapitalLoanRequestFactory 
workingCapitalLoanRequestFactory;
+    private final EventCheckHelper eventCheckHelper;
+
+    @When("Admin creates a working capital loan with the following data:")
+    public void createWorkingCapitalLoan(final DataTable table) {
+        final List<List<String>> data = table.asLists();
+        createWorkingCapitalLoanAccount(data.get(1));
+    }
+
+    private void createWorkingCapitalLoanAccount(final List<String> loanData) {
+        final String loanProduct = loanData.get(0);
+        final String submittedOnDate = loanData.get(1);
+        final String expectedDisbursementDate = loanData.get(2);
+        final String principal = loanData.get(3);
+        final String totalPayment = loanData.get(4);
+        final String periodPaymentRate = loanData.get(5);
+        final String discount = loanData.get(6);
+
+        final PostClientsResponse clientResponse = 
testContext().get(TestContextKey.CLIENT_CREATE_RESPONSE);
+        final Long clientId = clientResponse.getClientId();
+
+        final DefaultWorkingCapitalLoanProduct product = 
DefaultWorkingCapitalLoanProduct.valueOf(loanProduct);
+        final Long loanProductId = 
workingCapitalLoanProductResolver.resolve(product);
+
+        final PostWorkingCapitalLoansRequest loansRequest = 
workingCapitalLoanRequestFactory.defaultWorkingCapitalLoansRequest(clientId)
+                
.productId(loanProductId).submittedOnDate(submittedOnDate).expectedDisbursementDate(expectedDisbursementDate)
+                .principalAmount(new BigDecimal(principal)).totalPayment(new 
BigDecimal(totalPayment))
+                .periodPaymentRate(new BigDecimal(periodPaymentRate))
+                .discount(discount != null && !discount.isEmpty() ? new 
BigDecimal(discount) : null);
+
+        final PostWorkingCapitalLoansResponse response = ok(
+                () -> 
fineractClient.workingCapitalLoans().submitWorkingCapitalLoanApplication(loansRequest));
+        testContext().set(TestContextKey.LOAN_CREATE_RESPONSE, response);
+        log.info("Working Capital Loan created with ID: {}", 
response.getLoanId());
+    }
+
+    @Then("Working capital loan creation was successful")
+    public void verifyWorkingCapitalLoanCreationSuccess() {
+        final PostWorkingCapitalLoansResponse loanResponse = 
testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
+
+        assertNotNull(loanResponse, "Loan creation response should not be 
null");
+        assertNotNull(loanResponse.getLoanId(), "Loan ID should not be null");
+        assertNotNull(loanResponse.getResourceId(), "Resource ID should not be 
null");
+        assertTrue(loanResponse.getLoanId() > 0, "Loan ID should be greater 
than 0");
+
+        log.info("Verified working capital loan creation was successful. Loan 
ID: {}", loanResponse.getLoanId());
+    }
+
+    @Then("Working capital loan account has the correct data:")
+    public void verifyWorkingCapitalLoanAccountData(final DataTable table) {
+        final PostWorkingCapitalLoansResponse loanResponse = 
testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
+        final Long loanId = loanResponse.getLoanId();
+
+        final GetWorkingCapitalLoansLoanIdResponse response = ok(
+                () -> 
fineractClient.workingCapitalLoans().retrieveWorkingCapitalLoanById(loanId));
+
+        final List<List<String>> data = table.asLists();
+        final List<String> expectedData = data.get(1);
+
+        final String expectedProductName = expectedData.get(0);
+        final String expectedSubmittedOnDate = expectedData.get(1);
+        final String expectedDisbursementDate = expectedData.get(2);
+        final String expectedStatus = expectedData.get(3);
+        final String expectedPrincipal = expectedData.get(4);
+        final String expectedTotalPayment = expectedData.get(5);
+        final String expectedPeriodPaymentRate = expectedData.get(6);
+        final String expectedDiscount = expectedData.get(7);
+
+        assertNotNull(response, "Loan response should not be null");
+        assertNotNull(response.getProduct(), "Product should not be null");
+        assertThat(response.getProduct().getName()).as("Product name should 
match").isEqualTo(expectedProductName);
+        assertThat(response.getSubmittedOnDate().toString()).as("Submitted on 
date should match").isEqualTo(expectedSubmittedOnDate);
+        
assertThat(response.getExpectedDisbursementDate().toString()).as("Expected 
disbursement date should match")
+                .isEqualTo(expectedDisbursementDate);
+        assertThat(response.getStatus().getValue()).as("Status should 
match").isEqualTo(expectedStatus);
+        assertThat(response.getPrincipal()).as("Principal should 
match").isEqualByComparingTo(new BigDecimal(expectedPrincipal));
+        assertThat(response.getTotalPayment()).as("Total payment should 
match").isEqualByComparingTo(new BigDecimal(expectedTotalPayment));
+        assertThat(response.getPeriodPaymentRate()).as("Period payment rate 
should match")
+                .isEqualByComparingTo(new 
BigDecimal(expectedPeriodPaymentRate));
+
+        if ("null".equals(expectedDiscount)) {
+            assertThat(response.getDiscount()).as("Discount should be 
null").isNull();
+        } else {
+            assertThat(response.getDiscount()).as("Discount should 
match").isEqualByComparingTo(new BigDecimal(expectedDiscount));
+        }
+
+        log.info("Verified working capital loan account data for loan ID: {}", 
loanId);
+    }
+
+    @Then("Creating a working capital loan with LP overridables disabled and 
with the following data will result an error:")
+    public void 
creatingWorkingCapitalLoanWithLpOverridablesDisabledWillResultAnError(final 
DataTable table) {
+        final List<List<String>> data = table.asLists();
+        final List<String> loanData = data.get(1);
+
+        final String loanProduct = loanData.get(0);
+        final String submittedOnDate = loanData.get(1);
+        final String expectedDisbursementDate = loanData.get(2);
+        final String principal = loanData.get(3);
+        final String totalPayment = loanData.get(4);
+        final String periodPaymentRate = loanData.get(5);
+        final String discount = loanData.get(6);
+        final String flatPercentageAmount = loanData.get(7);
+        final String delinquencyBucketId = loanData.get(8);
+        final String repaymentEvery = loanData.get(9);
+        final String repaymentFrequencyType = loanData.get(10);
+
+        final PostClientsResponse clientResponse = 
testContext().get(TestContextKey.CLIENT_CREATE_RESPONSE);
+        final Long clientId = clientResponse.getClientId();
+
+        final DefaultWorkingCapitalLoanProduct product = 
DefaultWorkingCapitalLoanProduct.valueOf(loanProduct);
+        final Long loanProductId = 
workingCapitalLoanProductResolver.resolve(product);
+
+        final PostWorkingCapitalLoansRequest loansRequest = 
workingCapitalLoanRequestFactory.defaultWorkingCapitalLoansRequest(clientId)
+                
.productId(loanProductId).submittedOnDate(submittedOnDate).expectedDisbursementDate(expectedDisbursementDate)
+                .principalAmount(new BigDecimal(principal)).totalPayment(new 
BigDecimal(totalPayment))
+                .periodPaymentRate(new BigDecimal(periodPaymentRate))
+                .discount(discount != null && !discount.isEmpty() ? new 
BigDecimal(discount) : null)
+                .flatPercentageAmount(
+                        flatPercentageAmount != null && 
!flatPercentageAmount.isEmpty() ? new BigDecimal(flatPercentageAmount) : null)
+                .delinquencyBucketId(
+                        delinquencyBucketId != null && 
!delinquencyBucketId.isEmpty() ? Long.valueOf(delinquencyBucketId) : null)
+                .repaymentEvery(repaymentEvery != null && 
!repaymentEvery.isEmpty() ? Integer.valueOf(repaymentEvery) : null)
+                .repaymentFrequencyType(repaymentFrequencyType != null && 
!repaymentFrequencyType.isEmpty()
+                        ? 
PostWorkingCapitalLoansRequest.RepaymentFrequencyTypeEnum.valueOf(repaymentFrequencyType)
+                        : null);
+
+        final CallFailedRuntimeException exception = fail(
+                () -> 
fineractClient.workingCapitalLoans().submitWorkingCapitalLoanApplication(loansRequest));
+        testContext().set(TestContextKey.LOAN_CREATE_RESPONSE, exception);
+
+        log.info("HTTP status code: {}", exception.getStatus());
+
+        assertThat(exception.getStatus()).as("HTTP status code should be 
400").isEqualTo(400);
+
+        log.info("Validation error 1: 
validation.msg.WORKINGCAPITALLOAN.flatPercentageAmount.override.not.allowed.by.product");
+        assertThat(exception.getMessage()).as("Should contain 
flatPercentageAmount override error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.flatPercentageAmount.override.not.allowed.by.product");
+
+        log.info("Validation error 2: 
validation.msg.WORKINGCAPITALLOAN.delinquencyBucketId.override.not.allowed.by.product");
+        assertThat(exception.getMessage()).as("Should contain 
delinquencyBucketId override error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.delinquencyBucketId.override.not.allowed.by.product");
+
+        log.info("Validation error 3: 
validation.msg.WORKINGCAPITALLOAN.repaymentEvery.override.not.allowed.by.product");
+        assertThat(exception.getMessage()).as("Should contain repaymentEvery 
override error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.repaymentEvery.override.not.allowed.by.product");
+
+        log.info("Validation error 4: 
validation.msg.WORKINGCAPITALLOAN.repaymentFrequencyType.override.not.allowed.by.product");
+        assertThat(exception.getMessage()).as("Should contain 
repaymentFrequencyType override error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.repaymentFrequencyType.override.not.allowed.by.product");
+
+        log.info("Verified working capital loan creation failed with expected 
validation errors for LP overridables disabled");
+    }
+
+    @Then("Creating a working capital loan with principal amount greater than 
Working Capital Loan Product max will result an error:")
+    public void 
creatingAWorkingCapitalLoanWithPrincipalAmountGreaterThanWorkingCapitalLoanProductMaxWillResultAnError(
+            final DataTable table) {
+        final List<List<String>> data = table.asLists();

Review Comment:
   Fixed



##########
fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/WorkingCapitalProductLoanAccountStepDef.java:
##########
@@ -0,0 +1,618 @@
+/**
+ * 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.test.stepdef.loan;
+
+import static org.apache.fineract.client.feign.util.FeignCalls.fail;
+import static org.apache.fineract.client.feign.util.FeignCalls.ok;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import io.cucumber.datatable.DataTable;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
+import java.math.BigDecimal;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Map;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.client.feign.FineractFeignClient;
+import org.apache.fineract.client.feign.util.CallFailedRuntimeException;
+import 
org.apache.fineract.client.models.DeleteWorkingCapitalLoansLoanIdResponse;
+import org.apache.fineract.client.models.GetWorkingCapitalLoansLoanIdResponse;
+import org.apache.fineract.client.models.PostClientsResponse;
+import org.apache.fineract.client.models.PostWorkingCapitalLoansRequest;
+import org.apache.fineract.client.models.PostWorkingCapitalLoansResponse;
+import org.apache.fineract.client.models.PutWorkingCapitalLoansLoanIdRequest;
+import org.apache.fineract.client.models.PutWorkingCapitalLoansLoanIdResponse;
+import 
org.apache.fineract.test.data.workingcapitalproduct.DefaultWorkingCapitalLoanProduct;
+import 
org.apache.fineract.test.data.workingcapitalproduct.WorkingCapitalLoanProductResolver;
+import org.apache.fineract.test.factory.WorkingCapitalLoanRequestFactory;
+import org.apache.fineract.test.messaging.event.EventCheckHelper;
+import org.apache.fineract.test.stepdef.AbstractStepDef;
+import org.apache.fineract.test.support.TestContextKey;
+
+@Slf4j
+@RequiredArgsConstructor
+public class WorkingCapitalProductLoanAccountStepDef extends AbstractStepDef {
+
+    private static final String DATE_FORMAT = "dd MMMM yyyy";
+    private static final DateTimeFormatter FORMATTER = 
DateTimeFormatter.ofPattern(DATE_FORMAT);
+    private static final Long NON_EXISTENT_LOAN_ID = 999_999_999L;
+
+    private final FineractFeignClient fineractClient;
+    private final WorkingCapitalLoanProductResolver 
workingCapitalLoanProductResolver;
+    private final WorkingCapitalLoanRequestFactory 
workingCapitalLoanRequestFactory;
+    private final EventCheckHelper eventCheckHelper;
+
+    @When("Admin creates a working capital loan with the following data:")
+    public void createWorkingCapitalLoan(final DataTable table) {
+        final List<List<String>> data = table.asLists();
+        createWorkingCapitalLoanAccount(data.get(1));
+    }
+
+    private void createWorkingCapitalLoanAccount(final List<String> loanData) {
+        final String loanProduct = loanData.get(0);
+        final String submittedOnDate = loanData.get(1);
+        final String expectedDisbursementDate = loanData.get(2);
+        final String principal = loanData.get(3);
+        final String totalPayment = loanData.get(4);
+        final String periodPaymentRate = loanData.get(5);
+        final String discount = loanData.get(6);
+
+        final PostClientsResponse clientResponse = 
testContext().get(TestContextKey.CLIENT_CREATE_RESPONSE);
+        final Long clientId = clientResponse.getClientId();
+
+        final DefaultWorkingCapitalLoanProduct product = 
DefaultWorkingCapitalLoanProduct.valueOf(loanProduct);
+        final Long loanProductId = 
workingCapitalLoanProductResolver.resolve(product);
+
+        final PostWorkingCapitalLoansRequest loansRequest = 
workingCapitalLoanRequestFactory.defaultWorkingCapitalLoansRequest(clientId)
+                
.productId(loanProductId).submittedOnDate(submittedOnDate).expectedDisbursementDate(expectedDisbursementDate)
+                .principalAmount(new BigDecimal(principal)).totalPayment(new 
BigDecimal(totalPayment))
+                .periodPaymentRate(new BigDecimal(periodPaymentRate))
+                .discount(discount != null && !discount.isEmpty() ? new 
BigDecimal(discount) : null);
+
+        final PostWorkingCapitalLoansResponse response = ok(
+                () -> 
fineractClient.workingCapitalLoans().submitWorkingCapitalLoanApplication(loansRequest));
+        testContext().set(TestContextKey.LOAN_CREATE_RESPONSE, response);
+        log.info("Working Capital Loan created with ID: {}", 
response.getLoanId());
+    }
+
+    @Then("Working capital loan creation was successful")
+    public void verifyWorkingCapitalLoanCreationSuccess() {
+        final PostWorkingCapitalLoansResponse loanResponse = 
testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
+
+        assertNotNull(loanResponse, "Loan creation response should not be 
null");
+        assertNotNull(loanResponse.getLoanId(), "Loan ID should not be null");
+        assertNotNull(loanResponse.getResourceId(), "Resource ID should not be 
null");
+        assertTrue(loanResponse.getLoanId() > 0, "Loan ID should be greater 
than 0");
+
+        log.info("Verified working capital loan creation was successful. Loan 
ID: {}", loanResponse.getLoanId());
+    }
+
+    @Then("Working capital loan account has the correct data:")
+    public void verifyWorkingCapitalLoanAccountData(final DataTable table) {
+        final PostWorkingCapitalLoansResponse loanResponse = 
testContext().get(TestContextKey.LOAN_CREATE_RESPONSE);
+        final Long loanId = loanResponse.getLoanId();
+
+        final GetWorkingCapitalLoansLoanIdResponse response = ok(
+                () -> 
fineractClient.workingCapitalLoans().retrieveWorkingCapitalLoanById(loanId));
+
+        final List<List<String>> data = table.asLists();
+        final List<String> expectedData = data.get(1);
+
+        final String expectedProductName = expectedData.get(0);
+        final String expectedSubmittedOnDate = expectedData.get(1);
+        final String expectedDisbursementDate = expectedData.get(2);
+        final String expectedStatus = expectedData.get(3);
+        final String expectedPrincipal = expectedData.get(4);
+        final String expectedTotalPayment = expectedData.get(5);
+        final String expectedPeriodPaymentRate = expectedData.get(6);
+        final String expectedDiscount = expectedData.get(7);
+
+        assertNotNull(response, "Loan response should not be null");
+        assertNotNull(response.getProduct(), "Product should not be null");
+        assertThat(response.getProduct().getName()).as("Product name should 
match").isEqualTo(expectedProductName);
+        assertThat(response.getSubmittedOnDate().toString()).as("Submitted on 
date should match").isEqualTo(expectedSubmittedOnDate);
+        
assertThat(response.getExpectedDisbursementDate().toString()).as("Expected 
disbursement date should match")
+                .isEqualTo(expectedDisbursementDate);
+        assertThat(response.getStatus().getValue()).as("Status should 
match").isEqualTo(expectedStatus);
+        assertThat(response.getPrincipal()).as("Principal should 
match").isEqualByComparingTo(new BigDecimal(expectedPrincipal));
+        assertThat(response.getTotalPayment()).as("Total payment should 
match").isEqualByComparingTo(new BigDecimal(expectedTotalPayment));
+        assertThat(response.getPeriodPaymentRate()).as("Period payment rate 
should match")
+                .isEqualByComparingTo(new 
BigDecimal(expectedPeriodPaymentRate));
+
+        if ("null".equals(expectedDiscount)) {
+            assertThat(response.getDiscount()).as("Discount should be 
null").isNull();
+        } else {
+            assertThat(response.getDiscount()).as("Discount should 
match").isEqualByComparingTo(new BigDecimal(expectedDiscount));
+        }
+
+        log.info("Verified working capital loan account data for loan ID: {}", 
loanId);
+    }
+
+    @Then("Creating a working capital loan with LP overridables disabled and 
with the following data will result an error:")
+    public void 
creatingWorkingCapitalLoanWithLpOverridablesDisabledWillResultAnError(final 
DataTable table) {
+        final List<List<String>> data = table.asLists();
+        final List<String> loanData = data.get(1);
+
+        final String loanProduct = loanData.get(0);
+        final String submittedOnDate = loanData.get(1);
+        final String expectedDisbursementDate = loanData.get(2);
+        final String principal = loanData.get(3);
+        final String totalPayment = loanData.get(4);
+        final String periodPaymentRate = loanData.get(5);
+        final String discount = loanData.get(6);
+        final String flatPercentageAmount = loanData.get(7);
+        final String delinquencyBucketId = loanData.get(8);
+        final String repaymentEvery = loanData.get(9);
+        final String repaymentFrequencyType = loanData.get(10);
+
+        final PostClientsResponse clientResponse = 
testContext().get(TestContextKey.CLIENT_CREATE_RESPONSE);
+        final Long clientId = clientResponse.getClientId();
+
+        final DefaultWorkingCapitalLoanProduct product = 
DefaultWorkingCapitalLoanProduct.valueOf(loanProduct);
+        final Long loanProductId = 
workingCapitalLoanProductResolver.resolve(product);
+
+        final PostWorkingCapitalLoansRequest loansRequest = 
workingCapitalLoanRequestFactory.defaultWorkingCapitalLoansRequest(clientId)
+                
.productId(loanProductId).submittedOnDate(submittedOnDate).expectedDisbursementDate(expectedDisbursementDate)
+                .principalAmount(new BigDecimal(principal)).totalPayment(new 
BigDecimal(totalPayment))
+                .periodPaymentRate(new BigDecimal(periodPaymentRate))
+                .discount(discount != null && !discount.isEmpty() ? new 
BigDecimal(discount) : null)
+                .flatPercentageAmount(
+                        flatPercentageAmount != null && 
!flatPercentageAmount.isEmpty() ? new BigDecimal(flatPercentageAmount) : null)
+                .delinquencyBucketId(
+                        delinquencyBucketId != null && 
!delinquencyBucketId.isEmpty() ? Long.valueOf(delinquencyBucketId) : null)
+                .repaymentEvery(repaymentEvery != null && 
!repaymentEvery.isEmpty() ? Integer.valueOf(repaymentEvery) : null)
+                .repaymentFrequencyType(repaymentFrequencyType != null && 
!repaymentFrequencyType.isEmpty()
+                        ? 
PostWorkingCapitalLoansRequest.RepaymentFrequencyTypeEnum.valueOf(repaymentFrequencyType)
+                        : null);
+
+        final CallFailedRuntimeException exception = fail(
+                () -> 
fineractClient.workingCapitalLoans().submitWorkingCapitalLoanApplication(loansRequest));
+        testContext().set(TestContextKey.LOAN_CREATE_RESPONSE, exception);
+
+        log.info("HTTP status code: {}", exception.getStatus());
+
+        assertThat(exception.getStatus()).as("HTTP status code should be 
400").isEqualTo(400);
+
+        log.info("Validation error 1: 
validation.msg.WORKINGCAPITALLOAN.flatPercentageAmount.override.not.allowed.by.product");
+        assertThat(exception.getMessage()).as("Should contain 
flatPercentageAmount override error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.flatPercentageAmount.override.not.allowed.by.product");
+
+        log.info("Validation error 2: 
validation.msg.WORKINGCAPITALLOAN.delinquencyBucketId.override.not.allowed.by.product");
+        assertThat(exception.getMessage()).as("Should contain 
delinquencyBucketId override error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.delinquencyBucketId.override.not.allowed.by.product");
+
+        log.info("Validation error 3: 
validation.msg.WORKINGCAPITALLOAN.repaymentEvery.override.not.allowed.by.product");
+        assertThat(exception.getMessage()).as("Should contain repaymentEvery 
override error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.repaymentEvery.override.not.allowed.by.product");
+
+        log.info("Validation error 4: 
validation.msg.WORKINGCAPITALLOAN.repaymentFrequencyType.override.not.allowed.by.product");
+        assertThat(exception.getMessage()).as("Should contain 
repaymentFrequencyType override error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.repaymentFrequencyType.override.not.allowed.by.product");
+
+        log.info("Verified working capital loan creation failed with expected 
validation errors for LP overridables disabled");
+    }
+
+    @Then("Creating a working capital loan with principal amount greater than 
Working Capital Loan Product max will result an error:")
+    public void 
creatingAWorkingCapitalLoanWithPrincipalAmountGreaterThanWorkingCapitalLoanProductMaxWillResultAnError(
+            final DataTable table) {
+        final List<List<String>> data = table.asLists();
+        final List<String> loanData = data.get(1);
+
+        final String loanProduct = loanData.get(0);
+        final String submittedOnDate = loanData.get(1);
+        final String expectedDisbursementDate = loanData.get(2);
+        final String principal = loanData.get(3);
+        final String totalPayment = loanData.get(4);
+        final String periodPaymentRate = loanData.get(5);
+        final String discount = loanData.get(6);
+
+        final PostClientsResponse clientResponse = 
testContext().get(TestContextKey.CLIENT_CREATE_RESPONSE);
+        final Long clientId = clientResponse.getClientId();
+
+        final DefaultWorkingCapitalLoanProduct product = 
DefaultWorkingCapitalLoanProduct.valueOf(loanProduct);
+        final Long loanProductId = 
workingCapitalLoanProductResolver.resolve(product);
+
+        final PostWorkingCapitalLoansRequest loansRequest = 
workingCapitalLoanRequestFactory.defaultWorkingCapitalLoansRequest(clientId)
+                
.productId(loanProductId).submittedOnDate(submittedOnDate).expectedDisbursementDate(expectedDisbursementDate)
+                .principalAmount(new BigDecimal(principal)).totalPayment(new 
BigDecimal(totalPayment))
+                .periodPaymentRate(new BigDecimal(periodPaymentRate))
+                .discount(discount != null && !discount.isEmpty() ? new 
BigDecimal(discount) : null);
+
+        final CallFailedRuntimeException exception = fail(
+                () -> 
fineractClient.workingCapitalLoans().submitWorkingCapitalLoanApplication(loansRequest));
+        testContext().set(TestContextKey.LOAN_CREATE_RESPONSE, exception);
+
+        log.info("HTTP status code: {}", exception.getStatus());
+
+        assertThat(exception.getStatus()).as("HTTP status code should be 
400").isEqualTo(400);
+
+        log.info("Validation error: 
validation.msg.WORKINGCAPITALLOAN.principalAmount.must.be.less.than.or.equal.to.max");
+        assertThat(exception.getMessage()).as("Should contain principalAmount 
max validation error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.principalAmount.must.be.less.than.or.equal.to.max");
+
+        log.info("Verified working capital loan creation failed with principal 
amount exceeding max");
+    }
+
+    @Then("Creating a working capital loan with principal amount smaller than 
Working Capital Loan Product min will result an error:")
+    public void 
creatingAWorkingCapitalLoanWithPrincipalAmountSmallerThanWorkingCapitalLoanProductMinWillResultAnError(
+            final DataTable table) {
+        final List<List<String>> data = table.asLists();
+        final List<String> loanData = data.get(1);
+
+        final String loanProduct = loanData.get(0);
+        final String submittedOnDate = loanData.get(1);
+        final String expectedDisbursementDate = loanData.get(2);
+        final String principal = loanData.get(3);
+        final String totalPayment = loanData.get(4);
+        final String periodPaymentRate = loanData.get(5);
+        final String discount = loanData.get(6);
+
+        final PostClientsResponse clientResponse = 
testContext().get(TestContextKey.CLIENT_CREATE_RESPONSE);
+        final Long clientId = clientResponse.getClientId();
+
+        final DefaultWorkingCapitalLoanProduct product = 
DefaultWorkingCapitalLoanProduct.valueOf(loanProduct);
+        final Long loanProductId = 
workingCapitalLoanProductResolver.resolve(product);
+
+        final PostWorkingCapitalLoansRequest loansRequest = 
workingCapitalLoanRequestFactory.defaultWorkingCapitalLoansRequest(clientId)
+                
.productId(loanProductId).submittedOnDate(submittedOnDate).expectedDisbursementDate(expectedDisbursementDate)
+                .principalAmount(new BigDecimal(principal)).totalPayment(new 
BigDecimal(totalPayment))
+                .periodPaymentRate(new BigDecimal(periodPaymentRate))
+                .discount(discount != null && !discount.isEmpty() ? new 
BigDecimal(discount) : null);
+
+        final CallFailedRuntimeException exception = fail(
+                () -> 
fineractClient.workingCapitalLoans().submitWorkingCapitalLoanApplication(loansRequest));
+        testContext().set(TestContextKey.LOAN_CREATE_RESPONSE, exception);
+
+        log.info("HTTP status code: {}", exception.getStatus());
+
+        assertThat(exception.getStatus()).as("HTTP status code should be 
400").isEqualTo(400);
+
+        log.info("Validation error: 
validation.msg.WORKINGCAPITALLOAN.principalAmount.must.be.greater.than.or.equal.to.min");
+        assertThat(exception.getMessage()).as("Should contain principalAmount 
min validation error")
+                
.contains("validation.msg.WORKINGCAPITALLOAN.principalAmount.must.be.greater.than.or.equal.to.min");
+
+        log.info("Verified working capital loan creation failed with principal 
amount below min");
+    }
+
+    @Then("Creating a working capital loan with missing mandatory fields will 
result an error:")
+    public void 
creatingAWorkingCapitalLoanWithMissingMandatoryFieldsWillResultAnError(final 
DataTable table) {
+        final List<List<String>> data = table.asLists();
+        final List<String> loanData = data.get(1);
+
+        final String loanProduct = loanData.get(0);
+        final String submittedOnDate = loanData.get(1);
+        final String expectedDisbursementDate = loanData.get(2);
+        final String principal = loanData.get(3);
+        final String totalPayment = loanData.get(4);
+        final String periodPaymentRate = loanData.get(5);
+        final String discount = loanData.get(6);
+
+        final PostClientsResponse clientResponse = 
testContext().get(TestContextKey.CLIENT_CREATE_RESPONSE);
+        final Long clientId = clientResponse.getClientId();
+
+        final DefaultWorkingCapitalLoanProduct product = 
DefaultWorkingCapitalLoanProduct.valueOf(loanProduct);
+        final Long loanProductId = 
workingCapitalLoanProductResolver.resolve(product);
+
+        final PostWorkingCapitalLoansRequest loansRequest = 
workingCapitalLoanRequestFactory.defaultWorkingCapitalLoansRequest(clientId)
+                .productId(loanProductId).submittedOnDate(submittedOnDate != 
null && !submittedOnDate.isEmpty() ? submittedOnDate : null)
+                .expectedDisbursementDate(
+                        expectedDisbursementDate != null && 
!expectedDisbursementDate.isEmpty() ? expectedDisbursementDate : null)
+                .principalAmount(principal != null && !principal.isEmpty() ? 
new BigDecimal(principal) : null)
+                .totalPayment(totalPayment != null && !totalPayment.isEmpty() 
? new BigDecimal(totalPayment) : null)
+                .periodPaymentRate(periodPaymentRate != null && 
!periodPaymentRate.isEmpty() ? new BigDecimal(periodPaymentRate) : null)
+                .discount(discount != null && !discount.isEmpty() ? new 
BigDecimal(discount) : null);
+
+        final CallFailedRuntimeException exception = fail(
+                () -> 
fineractClient.workingCapitalLoans().submitWorkingCapitalLoanApplication(loansRequest));
+        testContext().set(TestContextKey.LOAN_CREATE_RESPONSE, exception);
+
+        log.info("HTTP status code: {}", exception.getStatus());
+
+        assertThat(exception.getStatus()).as("HTTP status code should be 
400").isEqualTo(400);
+
+        // Check for missing mandatory field errors
+        if (principal == null || principal.isEmpty()) {
+            log.info("Checking for principalAmount error: The parameter 
`principalAmount` is mandatory.");
+            assertThat(exception.getMessage()).as("Should contain 
principalAmount mandatory error")
+                    .contains("The parameter `principalAmount` is mandatory.");
+        }
+
+        if (totalPayment == null || totalPayment.isEmpty()) {
+            log.info("Checking for totalPayment error: The parameter 
`totalPayment` is mandatory.");
+            assertThat(exception.getMessage()).as("Should contain totalPayment 
mandatory error")
+                    .contains("The parameter `totalPayment` is mandatory.");
+        }
+
+        if (periodPaymentRate == null || periodPaymentRate.isEmpty()) {
+            log.info("Checking for periodPaymentRate error: The parameter 
`periodPaymentRate` is mandatory.");
+            assertThat(exception.getMessage()).as("Should contain 
periodPaymentRate mandatory error")
+                    .contains("The parameter `periodPaymentRate` is 
mandatory.");
+        }
+
+        if (expectedDisbursementDate == null || 
expectedDisbursementDate.isEmpty()) {
+            log.info("Checking for expectedDisbursementDate error: The 
parameter `expectedDisbursementDate` is mandatory.");
+            assertThat(exception.getMessage()).as("Should contain 
expectedDisbursementDate mandatory error")
+                    .contains("The parameter `expectedDisbursementDate` is 
mandatory.");
+        }
+
+        log.info("Verified working capital loan creation failed with missing 
mandatory fields");
+    }
+
+    @When("Admin modifies the working capital loan with the following data:")
+    public void modifyWorkingCapitalLoan(final DataTable table) {
+        final List<List<String>> data = table.asLists();
+        modifyWorkingCapitalLoanAccount(data.get(1));
+    }
+
+    private void modifyWorkingCapitalLoanAccount(final List<String> loanData) {
+        final String submittedOnDate = loanData.get(0);

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to