Skip to content

FINERACT-2649: Migrate Tier 3 loan integration tests to Feign client#6084

Open
DeathGun44 wants to merge 13 commits into
apache:developfrom
DeathGun44:FINERACT-2649/batch-migrate-loan-tests-to-feign-s3
Open

FINERACT-2649: Migrate Tier 3 loan integration tests to Feign client#6084
DeathGun44 wants to merge 13 commits into
apache:developfrom
DeathGun44:FINERACT-2649/batch-migrate-loan-tests-to-feign-s3

Conversation

@DeathGun44

@DeathGun44 DeathGun44 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR transitions 56 test classes (encompassing approximately 277 test methods) to utilize the Feign client, entirely removing their dependency on REST-assured.

Note on Behavior: The core test behavior and assertions remain completely unchanged. This is strictly a refactor of the underlying HTTP client layer.

Targeted commits

I've split this work into 13 commits, grouped logically by test area (reschedule, chargebacks, APA, down-payments, etc.) to keep things manageable for review.

This will ensure that if CI fails or issues arise later, it is much easier to isolate and track down the specific batch that introduced the regression.

Scope

Included in this PR:

  • Comprehensive Loan Rescheduling and Re-aging tests (including Center/Group reschedules).
  • Chargeback integration scenarios (non-APA workflows, overpaid loans, payment type constraints).
  • Down-payment workflows (product configuration, transaction typing, undo disbursal, and repayment schedules).
  • Advanced Payment Allocation (APA) coverage for write-offs, transaction reprocessing, and external-id support.
  • Client loan lifecycle tests (credit balance refund, multiple disbursements, floating rates, and date validations).
  • Reverse-replay transaction relations and loan summary tests.
  • Standardization of BigDecimal precision assertions across migrated Feign tests.

Bug Fix: Incorrect journal entry assertions in UndoLoanDisbursalWithDownPaymentIntegrationTest

During the migration, the stricter Feign verifyJournalEntries() (which performs exact 1-to-1 matching with count validation) exposed a pre-existing bug on develop in two test methods:

  • testUndoDisbursalForLoanWithSingleDisbursalAutoDownPaymentEnabledAndHasManualTransactions
  • testUndoDisbursalForLoanWithMultiDisbursalAutoDownPaymentEnabledAndHasManualTransactions

Both tests make a manual repayment of 100.0 after disbursement, then undo the disbursal. The "repayment entries compensated" journal entry assertions incorrectly expected 250.0 (the down-payment amount) instead of 100.0 (the actual repayment amount). The old REST-assured based verifyJournalEntries() had more lenient matching semantics that masked this error. Fixed as part of the migration commit.

Infrastructure Enhancements

This PR builds upon the shared Feign test infrastructure from earlier batches, adding and extending several utilities to streamline testing:

  • InternalLoanReAgeApi: Supports specific internal API flows related to the re-aging of loans.
  • FeignGroupCenterHelper: Provides utilities for managing group and center associations during loan testing.
  • FeignRawHttpHelper: Safely handles edge cases that require raw HTTP requests to bypass strict Swagger model limitations (e.g., floating rate properties), utilizing fineract.it.url securely.
  • Business Date Context (runAt): Expanded the FeignLoanTestBase to cleanly execute nested operations under specific simulated business dates.
  • Event Verification: Integrated Awaitility-based assertions for robust verification of asynchronous business events.
  • Shared Builders & Validators: Expanded Feign loan helpers for external-ids, re-amortizations, write-offs, and credit allocations.

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Write the commit message as per our guidelines
  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
  • Create/update unit or integration tests for verifying the changes made.
  • Follow our coding conventions.
  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
  • This PR must not be a "code dump". Large changes can be made in a branch, with assistance. Ask for help on the developer mailing list.

Your assigned reviewer(s) will follow our guidelines for code reviews.

@DeathGun44

Copy link
Copy Markdown
Contributor Author

the test is failing and the issue is in develop itself, because a reversal of a 100.0 repayment should produce 100.0 journal entries, not 250.0. i am adding a fix for it in the pr and describing it in the description aswell

@DeathGun44 DeathGun44 force-pushed the FINERACT-2649/batch-migrate-loan-tests-to-feign-s3 branch from 9276e89 to 1d32a0e Compare July 3, 2026 15:11

@Aman-Mittal Aman-Mittal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still reviewing this one.....

@Aman-Mittal Aman-Mittal requested a review from budaidev July 3, 2026 15:56
@Aman-Mittal Aman-Mittal added the java Pull requests that update Java code label Jul 3, 2026
@DeathGun44 DeathGun44 force-pushed the FINERACT-2649/batch-migrate-loan-tests-to-feign-s3 branch from 1d32a0e to ba3e948 Compare July 5, 2026 19:29
@DeathGun44 DeathGun44 force-pushed the FINERACT-2649/batch-migrate-loan-tests-to-feign-s3 branch from ba3e948 to 07c5b62 Compare July 5, 2026 22:17
@adamsaghy

Copy link
Copy Markdown
Contributor

@DeathGun44 Please rebase.

DeathGun44 added 13 commits July 6, 2026 15:14
…elpers

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
… Feign

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
…sts to Feign

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
…to Feign

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
… dates

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
… Feign

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
… and down-payment schedule tests to Feign

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
…ests to Feign

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
…d Feign tests

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
@DeathGun44 DeathGun44 force-pushed the FINERACT-2649/batch-migrate-loan-tests-to-feign-s3 branch from 07c5b62 to 94261bf Compare July 6, 2026 09:45
@DeathGun44

Copy link
Copy Markdown
Contributor Author

@adamsaghy Done!

@adamsaghy adamsaghy requested a review from budaidev July 6, 2026 13:43

@budaidev budaidev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR has a massive scope and a lot of changes, so the lot of comments doesn't mean it's bad, but I would advise to fix those to keep the refactor clean. The direction is really good.

Also please avoid any behavior changes in the test, by modifying or removing assertations, because it could lead silent errors.

*/
public Long createLoanProductFromJson(String loanProductJson) {
try {
String sanitizedJson = loanProductJson.replaceAll("(?<=\\d),(?=\\d{3})", "");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, any numeric array/sequence where a value with ≥3 digits follows a comma gets silently merged. For example: {"loanIds":[5,1000]} → {"loanIds":[51000]}. I don't think this is the indended behaviour here.


public <T> T getLoanProductError(String loanProductJson, String jsonAttributeToGetBack) {
try {
String sanitizedJson = loanProductJson.replaceAll("(?<=\\d),(?=\\d{3})", "");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, any numeric array/sequence where a value with ≥3 digits follows a comma gets silently merged. For example: {"loanIds":[5,1000]} → {"loanIds":[51000]}. I don't think this is the indended behaviour here.

@@ -114,12 +155,11 @@ public static void setupHelpers() {
codeHelper = new FeignCodeHelper(client);
globalConfigurationHelper = new FeignGlobalConfigurationHelper(client);
schedulerHelper = new FeignSchedulerHelper(client);
externalEventHelper = new FeignExternalEventHelper(client);
accounts = new LoanTestAccounts(accountHelper);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accounts = new LoanTestAccounts(accountHelper) is now eager in @BeforeAll (was lazy in getAccounts()). That's ~21 create-GL-account calls and 21 junk accounts per test class — for all 56 classes this PR moves onto the base, including ones that never touch accounting. Please restore lazy initialization.

this.overpaymentAccount = getAccounts().getOverpaymentAccount();
}

private ClientHelper clientHelper;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused here, no init no usage

this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
this.assetAccount = this.accountHelper.createAssetAccount();
this.incomeAccount = this.accountHelper.createIncomeAccount();
this.expenseAccount = this.accountHelper.createExpenseAccount();
this.overpaymentAccount = this.accountHelper.createLiabilityAccount();
}

private ClientHelper clientHelper;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused here, it shadows the parent classes field

public void testCenterReschedulingMultiTrancheLoansWithInterestRecalculationEnabled() {

Integer officeId = new OfficeHelper().createOffice(LocalDate.of(2007, 7, 1)).getResourceId().intValue();
Long officeId = new FeignOfficeHelper(fineractClient()).createOffice(LocalDate.of(2007, Month.JULY, 1)).getResourceId();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct new FeignOfficeHelper(fineractClient()) in the test (helpers belong in the base per the test-infra conventions)

Long loanProductId = createLoanProduct(product);
GetLoanProductsProductIdResponse retrievedProduct = retrieveLoanProduct(loanProductId);
assertNotNull(retrievedProduct);
return loanProductId;
}

private Long addChargeWithCurrency(Long loanId, boolean isPenalty, double amount, String dueDate, String currencyCode) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignores isPenalty and always creates a fee. Branch to the penalty builder or drop the parameter

Integer penalty = ChargesHelper.createCharges(requestSpec, responseSpec,
ChargesHelper.getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "10", true));

Long penalty = createLoanSpecifiedDueDateCharge(10.0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code

Assertions.assertNotNull(deletedFinancialActivityAccountId);
Assertions.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId);
@AfterEach
public void tearDownFinancialActivityAccounts() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AfterEach now deletes all financial-activity mappings after every test (original: one mapping once in AfterAll) and mapLiabilityTransferFinancialActivity(Long) ignores its parameter; new FinancialActivityAccountHelper(null) is fragile. Also the savings product lost withMinimumOpenningBalance("10000.0").

return ok(() -> fineractClient.rescheduleLoans().createLoanRescheduleRequest(request));
}

public CallFailedRuntimeException createRescheduleRequestExpectingError(PostCreateRescheduleLoansRequest request) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createRescheduleRequestExpectingError is dead code with a latent bug: the recalc path throws AssertionError (RestAssured expectStatusCode(200)), which FeignCalls.fail() doesn't catch — it can never return the expected exception. Remove or implement via Feign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants