Skip to content

ENH-007 β€” Test Coverage for Error Scenarios 🟠 #64

Description

@hajk1

The test suite covers only the happy path. Manual API testing reveals unhandled edge cases: missing
entities return 500 instead of 404, business rule violations surface as unstructured errors, and
lazy associations accessed outside a transaction throw 500s. This issue adds negative-path coverage
and fixes the underlying service-layer issues that these tests expose.

Use FreightOrderControllerTest as the reference pattern for test setup.

404 β€” Entity not found (one test per controller):

  • VesselControllerTest β€” GET /vessels/9999 β†’ 404
  • VoyageControllerTest β€” GET /voyages/9999 β†’ 404
  • FreightOrderControllerTest β€” GET /freight-orders/9999 β†’ 404
  • PortControllerTest β€” GET /ports/9999 β†’ 404
  • CustomerControllerTest β€” GET /customers/9999 β†’ 404
  • AgentControllerTest β€” GET /agents/9999 β†’ 404
  • InvoiceControllerTest β€” invoice for non-existent order ID β†’ 404

400 β€” Validation failures:

  • VoyageControllerTest β€” create voyage with missing required fields β†’ 400
  • FreightOrderControllerTest β€” create order with missing voyageId, containerId, or
    customerId β†’ 400
  • FreightOrderControllerTest β€” discountPercent > 100 β†’ 400

Business rule violations:

  • FreightOrderControllerTest β€” book the same container on two active voyages β†’ 400
    (double-booking)
  • InvoiceControllerTest β€” generate invoice for an order not in DELIVERED status β†’ appropriate
    4xx (not 500)

Underlying fixes required by these tests:

  • Any service method that throws IllegalArgumentException for a not-found case must throw
    ResponseStatusException(NOT_FOUND) instead β€” the GlobalExceptionHandler then returns 404
  • Any service method that accesses a lazy association must be annotated @Transactional or
    @Transactional(readOnly = true) as appropriate

Acceptance criteria:

  • All 404 tests listed above implemented and passing
  • All 400 validation tests implemented and passing
  • Business rule violation tests implemented and passing
  • All services that return not-found throw ResponseStatusException(NOT_FOUND), not 500
  • All service methods accessing lazy associations are @Transactional
  • No existing test regresses
  • Code is formatted

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions