Search code examples
testingapache-kafkajunitquarkuswiremock

On a integration test with jUnit/Quarkus how to check a request body of an outgoing http request?


I need to check on one outgoing HTTP call from my service to a known endpoint during an integration test.

I'm using Quarkus, jUnit, Test Containers, and WireMock

My feature runs as follows:

  1. The app receive a request.
  2. It processes and transforms the data it receives
    1. Saves the transformer data on the database
  3. It forward the transformed request to an external endpoint (this endpoint changes based on the request)
    1. Sends a message on kafka, to later execute other processes.
  4. Answer with a 200 [empty body] to the caller

On my integration test I need to validate that on step 3, the process is executing the request with the expected transformations and the right outbound payload on the body.

Some solutions I though for it:

  1. On step 2.1 check if the transformed data is saved as expected on the database.
    1. This works, but it don't validate that the request was sent, and that it was sent to the correct endpoint.
  2. On step 3.1 validate if the message was right on Kafka.
    1. This has the same problem as before

I need a way to intercept the outbound request, and check if it is being sent to the right place and with the right data.

On the answer given on this post (on the second bullet point) they describe the exact way I would want to implement this, but until now, I could not find a feasible way to do it.


Solution

  • If you have setup your stubs with Wiremock, then you can use Wiremock.verify.

    See also https://wiremock.org/docs/verifying/