FINERACT-2649: Migrate Tier 3 loan integration tests to Feign client#6084
FINERACT-2649: Migrate Tier 3 loan integration tests to Feign client#6084DeathGun44 wants to merge 14 commits into
Conversation
|
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 |
9276e89 to
1d32a0e
Compare
Aman-Mittal
left a comment
There was a problem hiding this comment.
I am still reviewing this one.....
1d32a0e to
ba3e948
Compare
ba3e948 to
07c5b62
Compare
|
@DeathGun44 Please rebase. |
07c5b62 to
94261bf
Compare
|
@adamsaghy Done! |
budaidev
left a comment
There was a problem hiding this comment.
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.
6f8e2c3 to
e9acca1
Compare
|
@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! |
budaidev
left a comment
There was a problem hiding this comment.
looks good, great progress
|
please rebase and handle the conflicts |
…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>
e9acca1 to
13dc9db
Compare
|
@adamsaghy @budaidev Done! |
| public void testTransactionComparator() { | ||
| final Loan loan = new Loan(); | ||
| LocalDate today = LocalDate.of(2023, 10, 12); | ||
| LocalDate today = LocalDate.of(2023, Month.OCTOBER, 12); |
There was a problem hiding this comment.
this does not really help readability...
There was a problem hiding this comment.
Fair point! reverted all Month.ENUM back to integer months across the entire PR.
| loanCharge.setChargeTime(ChargeTimeType.TRANCHE_DISBURSEMENT.getValue()); | ||
| loanCharge.setChargeCalculation(ChargeCalculationType.FLAT.getValue()); | ||
| loanCharge.setDueDate(LocalDate.of(2022, 6, 27)); | ||
| loanCharge.setDueDate(LocalDate.of(2022, Month.JUNE, 27)); |
There was a problem hiding this comment.
this does not really help readability...
| @@ -61,12 +62,19 @@ public void runAt(String date, Runnable action) { | |||
| } | |||
|
|
|||
| public void runAt(String date, String dateFormat, Runnable action) { | |||
| boolean outerScope = RUN_AT_NESTING_DEPTH.get() == 0; | |||
There was a problem hiding this comment.
What is this for? We should not have nested business date changes...
There was a problem hiding this comment.
Agreed and removed the ThreadLocal nesting depth tracking entirely. No test actually nests runAt calls, so the complexity was unjustified.
|
|
||
| /** | ||
| * Feign interface for the reAge transaction template endpoint. The OpenAPI-generated client deserializes this response | ||
| * as {@code GetLoansLoanIdTransactionsTemplateResponse}, but the server returns {@link LoanTransactionData}. |
There was a problem hiding this comment.
The swagger definition should be fixed then instead please
There was a problem hiding this comment.
Fixed the @apiresponse on retrieveTransactionTemplate to use LoanTransactionData instead of GetLoansLoanIdTransactionsTemplateResponse. Deleted the InternalLoanReAgeApi workaround and switched to the standard generated client.
| protected HashMap<String, Object> getLoanIdFromApplication(String loanApplicationJson) { | ||
| Long loanId = applyForLoanFromJson(loanApplicationJson); | ||
| HashMap<String, Object> result = new HashMap<>(); | ||
| result.put("resourceId", loanId.intValue()); | ||
| result.put("resourceExternalId", getLoanDetails(loanId).getExternalId()); | ||
| return result; | ||
| } | ||
|
|
||
| protected HashMap<String, Object> disburseLoanAsMap(String date, Integer loanId, String transactionAmount, String externalId) { | ||
| PostLoansLoanIdResponse response = loanHelper.disburseLoanWithExternalId(date, loanId.longValue(), transactionAmount, externalId); | ||
| HashMap<String, Object> result = new HashMap<>(); | ||
| result.put("subResourceExternalId", response.getSubResourceExternalId()); | ||
| return result; | ||
| } | ||
|
|
||
| protected HashMap<String, Object> disburseLoanAsMap(String date, Integer loanId, String transactionAmount) { | ||
| PostLoansLoanIdResponse response = loanHelper.disburseLoan(date, loanId.longValue(), transactionAmount); | ||
| HashMap<String, Object> result = new HashMap<>(); | ||
| result.put("subResourceExternalId", response.getSubResourceExternalId()); | ||
| return result; | ||
| } | ||
|
|
||
| protected HashMap<String, Object> disburseLoan(String date, Integer loanId, String transactionAmount, String externalId) { | ||
| return disburseLoanAsMap(date, loanId, transactionAmount, externalId); | ||
| } | ||
|
|
||
| protected HashMap<String, Object> disburseLoan(String date, Integer loanId, String transactionAmount) { | ||
| return disburseLoanAsMap(date, loanId, transactionAmount); | ||
| } |
There was a problem hiding this comment.
Build and returning hashmap seems incorrect. why dont we use directly the response object?
There was a problem hiding this comment.
Replaced all HashMap<String, Object> returns with PostLoansResponse / PostLoansLoanIdResponse. Removed disburseLoanAsMap entirely.
| @@ -275,7 +270,7 @@ public void test_LoanReAgeTransaction_Works() { | |||
| installment(316.67, 0, 0, 0, 316.67, false, "13 May 2023"), // | |||
| installment(316.66, 0, 0, 0, 316.66, false, "12 June 2023") // | |||
| ); | |||
| checkMaturityDates(loanId, LocalDate.of(2023, 6, 12), LocalDate.of(2023, 6, 12)); | |||
| checkMaturityDates(loanId, LocalDate.of(2023, Month.JUNE, 12), LocalDate.of(2023, Month.JUNE, 12)); | |||
There was a problem hiding this comment.
It does not help the readability...
There was a problem hiding this comment.
Please review my concerns about:
- readability issues: Using Month.JUNE, etc looks weird... what was the problem with "6"?
- Creating HashMap objects from the response object: use the response object, dont map into HashMap...
- Minimalize the code logic which build manually HashMap / Json object and use that as request (i am not saying it cannot be used, but we should ensure, we are doing only when there are no other possibilities).
- Nested
runAt: We should not have nested runAt. Is there a particular reason to allow it?
…s, simplify runAt
95843e5 to
593eded
Compare
|
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. |
|
the other test failure is just flaky ,should pass on rerun. |
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:
BigDecimalprecision 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:
retrieveTransactionTemplate): Corrected@ApiResponseonretrieveTransactionTemplateto declareLoanTransactionData.classinstead ofGetLoansLoanIdTransactionsTemplateResponse.class. This aligns the OpenAPI definition with actual wire runtime behavior and enables standard generated Feign clients to deserialize transaction templates without custom workarounds.HashMap<String, Object>test builder responses with strongly-typed generated models (PostLoansResponse,PostLoansLoanIdResponse).FeignBusinessDateHelper.runAt(...)by removing unnecessary nestedThreadLocaldepth tracking.LocalDate.of(...)calls to use concise numeric month parameters.Bug Fix: Incorrect journal entry assertions in
UndoLoanDisbursalWithDownPaymentIntegrationTestDuring the migration, the stricter Feign
verifyJournalEntries()(which performs exact 1-to-1 matching with count validation) exposed a pre-existing bug ondevelopin two test methods:testUndoDisbursalForLoanWithSingleDisbursalAutoDownPaymentEnabledAndHasManualTransactionstestUndoDisbursalForLoanWithMultiDisbursalAutoDownPaymentEnabledAndHasManualTransactionsBoth 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), utilizingfineract.it.urlsecurely.runAt): Cleanly executes operations under simulated business dates with guaranteed cleanup.Awaitility-based assertions for robust verification of asynchronous business events.Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
Your assigned reviewer(s) will follow our guidelines for code reviews.