Class ExecutingResponseCreator

java.lang.Object
org.springframework.test.web.client.response.ExecutingResponseCreator
All Implemented Interfaces:
ResponseCreator

public class ExecutingResponseCreator extends Object implements ResponseCreator
ResponseCreator that obtains the response by executing the request through a ClientHttpRequestFactory. This is useful in scenarios with multiple remote services where some need to be called rather than mocked.

The ClientHttpRequestFactory is typically used for building the RestClient and is passed to MockRestServiceServer, in effect using the original factory rather than the test factory:

RestClient.Builder restClientBuilder = RestClient.builder().requestFactory(requestFactory);
ResponseCreator withActualResponse = new ExecutingResponseCreator(requestFactory);
MockRestServiceServer server = MockRestServiceServer.bindTo(restClientBuilder).build();
//...
server.expect(requestTo("/foo")).andRespond(withSuccess());
server.expect(requestTo("/bar")).andRespond(withActualResponse);
Since:
6.0.4
Author:
Simon Baslé