FINERACT-2454: Migrate LoanWithdrawnByApplicantIntegrationTest from RestAssured to feign client#5668
Conversation
| // public static List<GetObligeeData> getObligeeData(final String externalId) { | ||
| // GetClientObligeeDetailsResponse response = Calls | ||
| // .ok(FineractClientHelper.getFineractClient().clients.retrieveClientObligeeDetailsByExternalId(externalId)); | ||
| // return response != null && response.getObligees() != null ? new ArrayList<>(response.getObligees()) : new ArrayList<>(); | ||
| // } | ||
|
|
There was a problem hiding this comment.
Hi @Dpk376 , good catch on identifying the OpenAPI schema mismatch.
However, committing commented-out/dead code blocks generally goes against clean code guidelines. More importantly, falling back to RestAssured here circumvents the primary objective of this migration epic.
Instead of introducing a workaround and leaving technical debt in the test layer, the standard approach would be to fix the root cause: correcting the OpenAPI response schema (likely by updating the @ApiResponses annotation in the respective API Controller). Once the controller correctly defines the return type as an array, the Feign client will regenerate the correct List mapping, allowing us to completely remove the RestAssured dependency without workarounds.
Should we address the Controller annotation in this PR to keep the migration clean?
There was a problem hiding this comment.
Thank you for the direction! You're right — the root cause was an incorrect
@ApiResponseannotation inClientsApiResource.Root Cause
Both obligee endpoints (
clientIdandexternalId) were annotated with@Schema(implementation = GetClientObligeeDetailsResponse.class), describing the response as a JSON object — but the API actually returns a JSON array directly.Changes Made
ClientsApiResource.java
- Updated both obligee endpoint annotations to use
@ArraySchema(schema = @Schema(implementation = GetObligeeData.class))
ClientsApiResourceSwagger.java
- Promoted
GetObligeeDatato a top-level schema class- Removed the
GetClientObligeeDetailsResponsewrapper class
ClientHelper.java
- Removed all commented-out code blocks
- Replaced the RestAssured workaround with a clean feign client call:
return Calls.ok(FineractClientHelper.getFineractClient().clients.retrieveClientObligeeDetailsByExternalId(externalId));Happy to address any further feedback!
| // Note: The Feign-generated client incorrectly maps this endpoint to GetClientObligeeDetailsResponse (object), | ||
| // but the actual API returns a JSON array directly. Using RestAssured as a workaround until the OpenAPI spec is corrected. |
Saifulhuq01
left a comment
There was a problem hiding this comment.
please check a point cmds
Description
Closes/relates to FINERACT-2454
Migrates
LoanWithdrawnByApplicantIntegrationTestfrom RestAssured to the type-safe feign client, as part of the ongoing test migration effort.Changes
RequestSpecification/ResponseSpecificationboilerplate withextends BaseLoanIntegrationTest@BeforeEachsetup — lifecycle managed byBaseLoanIntegrationTestClientHelper.createClient(requestSpec, responseSpec, ...)→ClientHelper.createClient(PostClientsRequest)LoanProductTestBuilder→createOnePeriod30DaysLongNoInterestPeriodicAccrualProduct()LoanApplicationTestBuilder+CollateralManagementHelper(no feign equivalent) →applyLoan(applyLoanRequest(...))LoanStatusCheckerHashMap-based assertions →verifyLoanStatus(loanId, LoanStatus.*)withdrawLoanApplicationByClient()→withdrawnByApplicantLoan(externalId, PostLoansLoanIdRequest)Result
102 lines → 60 lines. Zero RestAssured imports remaining.
No behavioral changes — the test still verifies that a pending loan application can be withdrawn by the applicant and transitions to
WITHDRAWN_BY_CLIENTstatus.