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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With