Skip to content

Commit 78e3b12

Browse files
authored
Merge pull request #5717
FINERACT-2455: data validator fix
2 parents b688899 + 3fb0fbb commit 78e3b12

6 files changed

Lines changed: 74 additions & 13 deletions

File tree

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/data/workingcapitalproduct/DefaultWorkingCapitalLoanProduct.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
public enum DefaultWorkingCapitalLoanProduct implements WorkingCapitalLoanProduct {
2222

2323
WCLP, //
24-
WCLP_DISALLOW_ATTRIBUTES_OVERRIDE, //
2524
WCLP_DISCOUNT, //
25+
WCLP_DISALLOW_ATTRIBUTES_OVERRIDE, //
2626
WCLP_DISCOUNT_DISALLOW_ATTRIBUTES_OVERRIDE, //
2727
WCLP_FOR_UPDATE; //
2828

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/WorkingCapitalLoanAccountStepDef.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public void creatingWorkingCapitalLoanWithLpOverridablesDisabledWillResultAnErro
154154
assertValidationError(exception, "validation.msg.WORKINGCAPITALLOAN.delinquencyBucketId.override.not.allowed.by.product");
155155
assertValidationError(exception, "validation.msg.WORKINGCAPITALLOAN.repaymentEvery.override.not.allowed.by.product");
156156
assertValidationError(exception, "validation.msg.WORKINGCAPITALLOAN.repaymentFrequencyType.override.not.allowed.by.product");
157+
assertValidationError(exception, "validation.msg.WORKINGCAPITALLOAN.discount.override.not.allowed.by.product");
157158

158159
log.info("Verified working capital loan creation failed with expected validation errors for LP overridables disabled");
159160
}

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/support/TestContextKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ public abstract class TestContextKey {
322322
public static final String OFFICE_CREATE_RESPONSE = "officeCreateResponse";
323323
public static final String DEFAULT_LOAN_PRODUCT_CREATE_RESPONSE_LP2_DOWNPAYMENT_ADVANCED_PAYMENT_ALLOCATION_PROGRESSIVE_LOAN_SCHEDULE_VERTICAL_INTEREST_RECALC = "loanProductCreateResponseLP2DownPaymentAdvancedPaymentAllocationProgressiveLoanScheduleVerticalInterestRecalc";
324324
public static final String DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_RESPONSE_WCLP = "workingCapitalLoanProductCreateResponseWCLP";
325-
public static final String DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_RESPONSE_WCLP_DISALLOW_OVERRIDES = "workingCapitalLoanProductCreateResponseWCLPDisallowOverrides";
326325
public static final String DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_RESPONSE_WCLP_DISCOUNT = "workingCapitalLoanProductCreateResponseWCLPDiscount";
326+
public static final String DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_RESPONSE_WCLP_DISALLOW_OVERRIDES = "workingCapitalLoanProductCreateResponseWCLPDisallowOverrides";
327327
public static final String DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_RESPONSE_WCLP_DISCOUNT_DISALLOW_OVERRIDES = "workingCapitalLoanProductCreateResponseWCLPDiscountDisallowOverrides";
328328
public static final String WC_LOAN_IDS = "wcLoanIds";
329329
public static final String DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_REQUEST_FOR_UPDATE_WCLP = "workingCapitalLoanProductCreateRequestForUpdateWCLP";

fineract-e2e-tests-runner/src/test/java/org/apache/fineract/test/initializer/global/WorkingCapitalInitializerStep.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,6 @@ public void initialize() throws Exception {
5454
final PostWorkingCapitalLoanProductsResponse responseDefaultWCPL = createWorkingCapitalLoanProductIdempotent(defaultWCPLRequest);
5555
TestContext.INSTANCE.set(TestContextKey.DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_RESPONSE_WCLP, responseDefaultWCPL);
5656

57-
final String workingCapitalProductDisallowOverridesDefaultName = DefaultWorkingCapitalLoanProduct.WCLP_DISALLOW_ATTRIBUTES_OVERRIDE
58-
.getName();
59-
final PostWorkingCapitalLoanProductsRequest defaultWCPLDisallowOverridesRequest = workingCapitalRequestFactory
60-
.defaultWorkingCapitalLoanProductRequest() //
61-
.name(workingCapitalProductDisallowOverridesDefaultName); //
62-
final PostWorkingCapitalLoanProductsResponse responseDefaultWCPLDisallowOverrides = createWorkingCapitalLoanProductIdempotent(
63-
defaultWCPLDisallowOverridesRequest);
64-
TestContext.INSTANCE.set(TestContextKey.DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_RESPONSE_WCLP_DISALLOW_OVERRIDES,
65-
responseDefaultWCPLDisallowOverrides);
66-
6757
final String workingCapitalProductDiscountDefaultName = DefaultWorkingCapitalLoanProduct.WCLP_DISCOUNT.getName();
6858
final PostWorkingCapitalLoanProductsRequest defaultWCPLPDiscountRequest = workingCapitalRequestFactory
6959
.defaultWorkingCapitalLoanProductAllowAttributesOverrideRequest() //
@@ -74,6 +64,16 @@ public void initialize() throws Exception {
7464
TestContext.INSTANCE.set(TestContextKey.DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_RESPONSE_WCLP_DISCOUNT,
7565
responseDefaultWCPLDiscount);
7666

67+
final String workingCapitalProductDisallowOverridesDefaultName = DefaultWorkingCapitalLoanProduct.WCLP_DISALLOW_ATTRIBUTES_OVERRIDE
68+
.getName();
69+
final PostWorkingCapitalLoanProductsRequest defaultWCPLDisallowOverridesRequest = workingCapitalRequestFactory
70+
.defaultWorkingCapitalLoanProductRequest() //
71+
.name(workingCapitalProductDisallowOverridesDefaultName); //
72+
final PostWorkingCapitalLoanProductsResponse responseDefaultWCPLDisallowOverrides = createWorkingCapitalLoanProductIdempotent(
73+
defaultWCPLDisallowOverridesRequest);
74+
TestContext.INSTANCE.set(TestContextKey.DEFAULT_WORKING_CAPITAL_LOAN_PRODUCT_CREATE_RESPONSE_WCLP_DISALLOW_OVERRIDES,
75+
responseDefaultWCPLDisallowOverrides);
76+
7777
final String workingCapitalProductDiscountDisallowOverridesDefaultName = DefaultWorkingCapitalLoanProduct.WCLP_DISCOUNT_DISALLOW_ATTRIBUTES_OVERRIDE
7878
.getName();
7979
PostAllowAttributeOverrides allowAttributeOverridesDisabled = new PostAllowAttributeOverrides()

fineract-e2e-tests-runner/src/test/resources/features/WorkingCapitalProductLoanAccount.feature

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,37 @@ Feature: WorkingCapitalLoanAccount
3838
| WCLP | 2026-01-01 | 2026-01-01 | Submitted and pending approval | 500.0 | 0.0 | 1000.0 | 2.0 | 5.0 |
3939

4040
@TestRailId:C70253
41-
Scenario: Create Working Capital Loan account - UC4: With LP overridables disabled, loan creation will result an error when trying override values (Negative)
41+
Scenario: Create Working Capital Loan account - UC4: With LP overridables disabled/disallowed, loan creation will result an error when trying override values (Negative)
4242
When Admin sets the business date to "01 January 2026"
4343
And Admin creates a client with random data
4444
Then Creating a working capital loan with LP overridables disabled and with the following data will result an error:
4545
| LoanProduct | submittedOnDate | expectedDisbursementDate | principalAmount | totalPayment | periodPaymentRate | discount | delinquencyBucketId | repaymentEvery | repaymentFrequencyType |
4646
| WCLP_DISALLOW_ATTRIBUTES_OVERRIDE | 01 January 2026 | 01 January 2026 | 100.0 | 100.0 | 1.0 | 0.0 | 1 | 30 | DAYS |
4747

48+
@TestRailId:C74453
49+
Scenario: Create Working Capital Loan account - UC4.1: With LP overridables enabled/allowed, loan creation will override discount value
50+
When Admin sets the business date to "01 January 2026"
51+
And Admin creates a client with random data
52+
And Admin creates a working capital loan with the following data:
53+
| LoanProduct | submittedOnDate | expectedDisbursementDate | principalAmount | totalPayment | periodPaymentRate | discount | delinquencyBucketId | repaymentEvery | repaymentFrequencyType |
54+
| WCLP_DISCOUNT | 01 January 2026 | 01 January 2026 | 100.0 | 100.0 | 2.0 | 60.0 | 1 | 1 | MONTHS |
55+
Then Working capital loan creation was successful
56+
And Working capital loan account has the correct data:
57+
| product.name | submittedOnDate | expectedDisbursementDate | status | principal | approvedPrincipal | totalPayment | periodPaymentRate | discount |
58+
| WCLP_DISCOUNT | 2026-01-01 | 2026-01-01 | Submitted and pending approval | 100.0 | 0.0 | 100.0 | 2.0 | 60.0 |
59+
60+
@TestRailId:C74479
61+
Scenario: Create Working Capital Loan account - UC4.2: With LP overridables disabled/disallowed, loan created with discount amount from loan product level
62+
When Admin sets the business date to "01 January 2026"
63+
And Admin creates a client with random data
64+
And Admin creates a working capital loan with the following data:
65+
| LoanProduct | submittedOnDate | expectedDisbursementDate | principalAmount | totalPayment | periodPaymentRate | discount | delinquencyBucketId | repaymentEvery | repaymentFrequencyType |
66+
| WCLP_DISCOUNT_DISALLOW_ATTRIBUTES_OVERRIDE | 01 January 2026 | 01 January 2026 | 100.0 | 100.0 | 1.0 | | 1 | 30 | DAYS |
67+
Then Working capital loan creation was successful
68+
And Working capital loan account has the correct data:
69+
| product.name | submittedOnDate | expectedDisbursementDate | status | principal | approvedPrincipal | totalPayment | periodPaymentRate | discount |
70+
| WCLP_DISCOUNT_DISALLOW_ATTRIBUTES_OVERRIDE | 2026-01-01 | 2026-01-01 | Submitted and pending approval | 100.0 | 0.0 | 100.0 | 1.0 | 50.0 |
71+
4872
@TestRailId:C70254
4973
Scenario: Create Working Capital Loan account - UC5: Create with principal amount greater than WCLP max (Negative)
5074
When Admin sets the business date to "01 January 2026"

integration-tests/src/test/java/org/apache/fineract/integrationtests/WorkingCapitalLoanApplicationValidationTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,32 @@ public void testSubmitWithOverrideNotAllowedByProduct() {
450450
productHelper.deleteWorkingCapitalLoanProductById(productId);
451451
}
452452

453+
/**
454+
* Product created without allowAttributeOverrides (all default to false). Discount override should be rejected.
455+
*/
456+
@Test
457+
public void testSubmitWithDiscountOverrideWhenProductHasNoOverridesConfigured() {
458+
final Long productId = createProductWithoutOverrides();
459+
final Long clientId = createClient();
460+
final String json = new WorkingCapitalLoanApplicationTestBuilder() //
461+
.withClientId(clientId) //
462+
.withProductId(productId) //
463+
.withPrincipal(BigDecimal.valueOf(5000)) //
464+
.withPeriodPaymentRate(BigDecimal.ONE) //
465+
.withTotalPayment(BigDecimal.valueOf(5500)) //
466+
.withDiscount(BigDecimal.ONE) //
467+
.buildSubmitJson();
468+
469+
final CallFailedRuntimeException ex = applicationHelper.runSubmitExpectingFailure(json);
470+
assertEquals(400, ex.getStatus());
471+
assertNotNull(ex.getDeveloperMessage());
472+
assertTrue(ex.getDeveloperMessage().contains("override.not.allowed.by.product"),
473+
"Expected override.not.allowed.by.product in: " + ex.getDeveloperMessage());
474+
assertTrue(ex.getDeveloperMessage().contains("discount"), "Expected discount in: " + ex.getDeveloperMessage());
475+
476+
productHelper.deleteWorkingCapitalLoanProductById(productId);
477+
}
478+
453479
@Test
454480
public void testSubmitWithOverrideNotAllowedByProductForBreach() {
455481
final Long productId = createProduct();
@@ -1068,6 +1094,16 @@ private Long createProductWithBreachOverride() {
10681094
.getResourceId();
10691095
}
10701096

1097+
private Long createProductWithoutOverrides() {
1098+
final String uniqueName = "WCL Product " + UUID.randomUUID().toString().substring(0, 8);
1099+
final String uniqueShortName = UUID.randomUUID().toString().replace("-", "").substring(0, 4);
1100+
return productHelper.createWorkingCapitalLoanProduct(new WorkingCapitalLoanProductTestBuilder() //
1101+
.withName(uniqueName) //
1102+
.withShortName(uniqueShortName) //
1103+
.build()) //
1104+
.getResourceId();
1105+
}
1106+
10711107
private Long createClient() {
10721108
return ClientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
10731109
}

0 commit comments

Comments
 (0)