As far as I can tell, the standard Wiremock approach is to define stubs and verify the stub invocations separately, which entails duplicating the defined behavior of the endpoint, via something like
rule.stubFor(get(url).withHeader("Content-Type", equalTo("application/json")).willReturn(aResponse().withStatus(200)));
// later
rule.verify(getRequestedFor(url).withHeader("Content-Type", equalTo("application/json")));
, which both duplicates the definition of the endpoint I expect to be invoked and requires that I know when I expect the stub to have been invoked (I don't, in this case). What I want is essentially a callback that says a given stub has been invoked, which implicitly verifies that it was matched (so it doesn't have to be verify()'d). AFAICT the only out-of-the-box callback that WireMock provides is a webhook with withPostServeAction()
, which is not what I want here. I've found (after some frustration) that I can register a ResponseDefinitionTransformer
that can execute the callback in the process of applying a transform to the response, but that seems like a pretty clunky way to achieve what I would have thought would be a common goal. Am I missing the intended way to get Wiremock to do what I want?