Reputation: 665
I have been using wiremock for integration testing and I have custom request matcher created and used for authorization stubs.
Is there any way I can use this matcher in spring cloud contract contract definitions?
To be specific - I want to create stub for specific user and the only way I can get user is by decoding authorization token. If decoded token matches a user - I want to match request and use provided stub.
Upvotes: 0
Views: 817
Reputation: 11149
Currently, we don't support easy way of applying custom matchers out of the box. What you would have to do is to implement the org.springframework.cloud.contract.verifier.converter.StubGenerator
(for example by extending the org.springframework.cloud.contract.verifier.wiremock.DslToWireMockClientConverter
to properly convert the Groovy DSL contract to a WireMock StubMapping that would contain the JSON representation of the converter (like presented here http://wiremock.org/docs/extending-wiremock/). You would have to register that implementation in META-INF/spring.factories
(e.g. org.springframework.cloud.contract.verifier.converter.StubGenerator=\
a.b.c.YourStubGenerator
) . I think that could work.
To sum it up. What essentially would happen is that you would take the map of Contract to String stub mapping, iterate over those entries, convert the string back to WireMock StubMapping, add the required custom matcher and return back the response. You'd have to register your implementation in spring.factories
and put it on the classpath of the plugin - that way it will be picked when the stubs are generated.
Upvotes: 1