mardi 10 juillet 2018

Java functional tests with a transparent proxy

I have an app that consumes a remote API by posting a request. I want to implement a functional test that allows me to detect when the API changes.

For example, I have some request x. The API normally expects requests that look like x, but the interface was recently changed. Now, requests that look like x are rejected (and a 400 Bad Request response is given). I want a functional test to be able to detect if such a change occurs downstream and causes the test to fail.

The objective of this test is to verify that the downstream API is still fulfilling its contract with my app.

I wanted to do this with some sort of transparent proxy which all requests and responses go to and fro the requester and the API and perform the test assertions there.

  +------------------+
  v                  |
+-----+  request   +-------+             +----------------+
| App | ---------> | Proxy | ----------> | Downstream API |
+-----+            +-------+             +----------------+
                     ^       response      |
                     +---------------------+

I have not found any library for this particular use case. The closest I have found is mockserver which supports intercepting the request, then passing it down to the (real) API, but not for responses.

Mocking the API (with mockserver or wiremock) is not an option because the test failure depends on the real API changing its interface. It's also a functional test, so everything should remain real.

Aucun commentaire:

Enregistrer un commentaire