Using Spring Cloud Contract, how can I set up multiple Wiremock stubs for different hosts/ports?

1.4k views Asked by At

What is the best way to set up multiple Wiremock stubs using Spring Cloud Contract that have different hosts/ports and are both invoked in code exercised by a single @Test method? For example, I want to test ServiceA.doSomething(), and this method invokes ServiceB.doSomethingElse() and ConsulClient.getKVValue(). I have no problem creating one instance of WireMockRestServiceServer, but I haven't figured out how to create a second one to be used within the same test that points to a different base URL. The reason I'm trying to do this is because I need to stub out calls that we make to Consul, and I need these requests to always be sent to http://localhost:8500, whereby my other requests are sent through the load balanced RestTemplate. I hope I've explained my scenario clearly.

1

There are 1 answers

0
Marcin Grzejszczak On

In terms of Stub Runner you can have a HttpStub server per a dependency - you just provide a different port to the string based notation of your dependency. Example @AutoConfigureStubRunner(ids = {"com.example:beer-api-producer:+:stubs:8090", "a.b:artifact:0.0.1.RELEASE:prod-stubs:9999"}). You can stub out the load balanced stuff like we describe here - http://cloud.spring.io/spring-cloud-contract/1.0.x/spring-cloud-contract.html#_stub_runner_spring_cloud