Class MockServerRestClientCustomizer
java.lang.Object
org.springframework.boot.test.web.client.MockServerRestClientCustomizer
- All Implemented Interfaces:
- 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.
 
 If a mock server is used in more than one test case in a test class, it might be
 necessary to reset the expectations on the server between tests using
 getServer().reset() or getServer(restClientBuilder).reset().
- Since:
- 3.2.0
- Author:
- Scott Frederick
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionMockServerRestClientCustomizer(Class<? extends RequestExpectationManager> expectationManager) Create a newMockServerRestClientCustomizerinstance.MockServerRestClientCustomizer(Supplier<? extends RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestClientCustomizerinstance.
- 
Method SummaryModifier and TypeMethodDescriptionprotected RequestExpectationManagervoidcustomize(RestClient.Builder restClientBuilder) Callback to customize aRestClient.Builderinstance.getServer(RestClient.Builder restClientBuilder) 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- 
MockServerRestClientCustomizerpublic MockServerRestClientCustomizer()
- 
MockServerRestClientCustomizerpublic MockServerRestClientCustomizer(Class<? extends RequestExpectationManager> expectationManager) Create a newMockServerRestClientCustomizerinstance.- Parameters:
- expectationManager- the expectation manager class to use
 
- 
MockServerRestClientCustomizerpublic MockServerRestClientCustomizer(Supplier<? extends RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestClientCustomizerinstance.- Parameters:
- expectationManagerSupplier- a supplier that provides the- RequestExpectationManagerto use
- Since:
- 3.0.0
 
 
- 
- 
Method Details- 
setBufferContentpublic 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
 
- 
customizeDescription copied from interface:RestClientCustomizerCallback to customize aRestClient.Builderinstance.- Specified by:
- customizein interface- RestClientCustomizer
- Parameters:
- restClientBuilder- the client builder to customize
 
- 
createExpectationManager
- 
getServer
- 
getExpectationManagers
- 
getServer
- 
getServers
 
-