fineract icon indicating copy to clipboard operation
fineract copied to clipboard

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

Open DeathGun44 opened this issue 4 months ago • 8 comments

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 14 commits, grouped logically by test area (reschedule, chargebacks, APA, down-payments, etc.) plus a dedicated review-feedback refinement commit 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.

Review Feedback & OpenAPI Refinements

Based on maintainer review feedback, this PR also includes cleanups to improve codebase hygiene and client generation:

  • OpenAPI Schema Fix (retrieveTransactionTemplate): Corrected @ApiResponse on retrieveTransactionTemplate to declare LoanTransactionData.class instead of GetLoansLoanIdTransactionsTemplateResponse.class. This aligns the OpenAPI definition with actual wire runtime behavior and enables standard generated Feign clients to deserialize transaction templates without custom workarounds.
  • Strongly Typed Response Models: Replaced untyped HashMap<String, Object> test builder responses with strongly-typed generated models (PostLoansResponse, PostLoansLoanIdResponse).
  • Simplified Business Date Context: Streamlined FeignBusinessDateHelper.runAt(...) by removing unnecessary nested ThreadLocal depth tracking.
  • Date Readability: Standardized LocalDate.of(...) calls to use concise numeric month parameters.

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:

  • 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): Cleanly executes operations under simulated business dates with guaranteed cleanup.
  • 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 avatar Jul 03 '26 12:07 DeathGun44

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 avatar Jul 03 '26 15:07 DeathGun44

@DeathGun44 Please rebase.

adamsaghy avatar Jul 06 '26 09:07 adamsaghy

@adamsaghy Done!

DeathGun44 avatar Jul 06 '26 09:07 DeathGun44

@budaidev Thank you for the thorough review! I enjoy all these reviews as they help me learn a lot. I know there is a lot of code to go through. I will keep trying my best to make it as clean as possible and easier to review, and I'll make sure the quality of the code doesn't deteriorate with these bulk prs. Thanks again, everyone, for keeping up!

DeathGun44 avatar Jul 07 '26 11:07 DeathGun44

please rebase and handle the conflicts

budaidev avatar Jul 07 '26 13:07 budaidev

@adamsaghy @budaidev Done!

DeathGun44 avatar Jul 07 '26 18:07 DeathGun44

Regarding the OpenAPI backward-compatibility check failure: this is expected due to updating the @ApiResponse schema on retrieveTransactionTemplate from GetLoansLoanIdTransactionsTemplateResponse to LoanTransactionData.

Inspecting LoanTransactionsApiResource.java shows the endpoint uses DefaultToApiJsonSerializer and has always returned LoanTransactionData on the wire at runtime. The previous OpenAPI annotation was incorrect. This change aligns the Swagger spec with actual runtime behavior, so there is no real-world breaking change for API consumers.

DeathGun44 avatar Jul 08 '26 13:07 DeathGun44

the other test failure is just flaky ,should pass on rerun. I have also updated the pr description with regard to the current state

DeathGun44 avatar Jul 08 '26 13:07 DeathGun44

@adamsaghy please take a look when you have a moment!

DeathGun44 avatar Jul 10 '26 12:07 DeathGun44

I am postponing to merge this till release of 1.15.0 is not finished

adamsaghy avatar Jul 10 '26 13:07 adamsaghy