Class MockServerRestClientCustomizer
java.lang.Object
org.springframework.boot.test.web.client.MockServerRestClientCustomizer
- All Implemented Interfaces:
org.springframework.boot.web.client.RestClientCustomizer
public class MockServerRestClientCustomizer
extends Object
implements org.springframework.boot.web.client.RestClientCustomizer
RestClientCustomizer that can be applied to RestClient.Builder
instances to add MockRestServiceServer support.
Typically applied to an existing builder before it is used, for example:
MockServerRestClientCustomizer customizer = new MockServerRestClientCustomizer();
RestClient.Builder builder = RestClient.builder();
customizer.customize(builder);
MyBean bean = new MyBean(client.build());
customizer.getServer().expect(requestTo("/hello")).andRespond(withSuccess());
bean.makeRestCall();
If the customizer is only used once, the getServer() method can be used to
obtain the mock server. If the customizer has been used more than once the
getServer(RestClient.Builder) or getServers() method must be used to
access the related server.
- Since:
- 3.2.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMockServerRestClientCustomizer(Class<? extends org.springframework.test.web.client.RequestExpectationManager> expectationManager) Create a newMockServerRestClientCustomizerinstance.MockServerRestClientCustomizer(Supplier<? extends org.springframework.test.web.client.RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestClientCustomizerinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.test.web.client.RequestExpectationManagervoidcustomize(org.springframework.web.client.RestClient.Builder restClientBuilder) Map<org.springframework.web.client.RestClient.Builder,org.springframework.test.web.client.RequestExpectationManager> org.springframework.test.web.client.MockRestServiceServerorg.springframework.test.web.client.MockRestServiceServergetServer(org.springframework.web.client.RestClient.Builder restClientBuilder) Map<org.springframework.web.client.RestClient.Builder,org.springframework.test.web.client.MockRestServiceServer> voidsetBufferContent(boolean bufferContent) Set if theBufferingClientHttpRequestFactorywrapper should be used to buffer the input and output streams, and for example, allow multiple reads of the response body.
-
Constructor Details
-
MockServerRestClientCustomizer
public MockServerRestClientCustomizer() -
MockServerRestClientCustomizer
public MockServerRestClientCustomizer(Class<? extends org.springframework.test.web.client.RequestExpectationManager> expectationManager) Create a newMockServerRestClientCustomizerinstance.- Parameters:
expectationManager- the expectation manager class to use
-
MockServerRestClientCustomizer
public MockServerRestClientCustomizer(Supplier<? extends org.springframework.test.web.client.RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestClientCustomizerinstance.- Parameters:
expectationManagerSupplier- a supplier that provides theRequestExpectationManagerto use- Since:
- 3.0.0
-
-
Method Details
-
setBufferContent
public void setBufferContent(boolean bufferContent) Set if theBufferingClientHttpRequestFactorywrapper should be used to buffer the input and output streams, and for example, allow multiple reads of the response body.- Parameters:
bufferContent- if request and response content should be buffered- Since:
- 3.1.0
-
customize
public void customize(org.springframework.web.client.RestClient.Builder restClientBuilder) - Specified by:
customizein interfaceorg.springframework.boot.web.client.RestClientCustomizer
-
createExpectationManager
protected org.springframework.test.web.client.RequestExpectationManager createExpectationManager() -
getServer
public org.springframework.test.web.client.MockRestServiceServer getServer() -
getExpectationManagers
public Map<org.springframework.web.client.RestClient.Builder,org.springframework.test.web.client.RequestExpectationManager> getExpectationManagers() -
getServer
public org.springframework.test.web.client.MockRestServiceServer getServer(org.springframework.web.client.RestClient.Builder restClientBuilder) -
getServers
public Map<org.springframework.web.client.RestClient.Builder,org.springframework.test.web.client.MockRestServiceServer> getServers()
-