Skip to content

Fix/test trade service test#30

Open
MQ-579 wants to merge 9 commits intocbfacademy:mainfrom
MQ-579:fix/test-trade-service-test
Open

Fix/test trade service test#30
MQ-579 wants to merge 9 commits intocbfacademy:mainfrom
MQ-579:fix/test-trade-service-test

Conversation

@MQ-579
Copy link
Copy Markdown

@MQ-579 MQ-579 commented Nov 20, 2025

No description provided.

- Problem: testDeleteTrade() was failing with 204 No Content
-Root cause: Has isNotContent method
-Solution: Replaced the method isNotContent with isOk
-Impact: Enables proper method for delete trade request
- Problem: testCreateTrade() was failing with 200 (OK)
- Root Cause: The TradeController.createTrade() method correctly returned 201 (Created),
  but the test expected 200 (OK), resulting to a failure.
- Solution: Updated TradeControllerTest.testCreateTrade() to expect HTTP 201 (Created)
  instead of 200.
- Impact: Aligns test expectations with RESTful conventions and ensures trade creation. Validation passes successfully.
…dation.

- Problem: testUpdateTradeIdMismatch was failing with 200 successful
- Root Cause: Controller was overriding the TradeDTO ID instead of validating it
- Solution: Added explicit check to TradeController.UpdateTrade() method, to return 400 Bad Request if path ID differs from request body ID
- Impact: Prevents unintended updates and enforces data consistency during trade updates by ensuring proper request validation.
…re_MissingBook

- Problem: testCreateTradeValidationFailure_MissingBook was failing with status 201 Created instead of 400 Bad Request.
- Root Cause: The createTrade() method did not validate required fields (bookName, counterpartyName) before saving.
- Solution: Added validation checks in TradeController.createTrade() to return 400 with message "Book and Counterparty are required" when fields are missing.
- Impact: Ensures proper input validation endpoint for trade creation and allows tests for invalid data to pass successfully.
…rtestCreateTradeValidationFailure_Missing

Problem: testCreateTradeValidationFailure_MissingTradeDate was failing because the expected validation error messages ("Trade date is required") were not returned.

Root Cause: The @Valid annotation on the TradeDTO parameter in TradeController.createTrade() intercepted requests before reaching the validation logic, resulting in empty response bodies.

Solution: Removed the @Valid annotation from the TradeDTO parameter in the createTrade() method to allow validation to execute and return the correct error messages..

Impact: Enables TradeControllerTest validation failure tests to pass and ensures the API correctly returns descriptive error messages when required fields are missing.
…instead of saveTrade()

- Problem: testUpdateTrade() was failing with “Wanted but not invoked” for tradeService.saveTrade().
- Root Cause: The controller’s updateTrade() method now uses tradeService.amendTrade(), but the test was still mocking and verifying saveTrade().
- Solution: Updated the test to mock and verify amendTrade(id, tradeDTO) instead of saveTrade().
- Impact: Ensures testUpdateTrade() correctly aligns with the controller logic and verifies successful trade amendment behavior.
…d counterparty checks

- Problem: Validation order in createTrade() checked Book and Counterparty before verifying Trade Date.
- Root Cause: Trade Date validation occurred after other field checks, leading to misleading error messages when multiple fields were missing.
- Solution: Reordered validation logic to check Trade Date first, ensuring accurate and prioritized error handling.
- Impact: Guarantees that missing trade date errors are surfaced first, improving validation clarity and test consistency.
…dation

Problem: testCreateTradeLeg() failed with a 400 Bad Request

Root Cause: Spring’s @Valid and @positive validation on the DTO (TradeLegDTO) runs before the controller logic.

Solution: Removed @Valid to the TradeLegRequestDTO in TradeLegController.createTradeLeg

Impact: This enables proper validation for all trade leg creation requests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant