Class MockServerRestTemplateCustomizer
java.lang.Object
org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer
- All Implemented Interfaces:
RestTemplateCustomizer
RestTemplateCustomizer
that can be applied to a RestTemplateBuilder
instances to add MockRestServiceServer
support.
Typically applied to an existing builder before it is used, for example:
MockServerRestTemplateCustomizer customizer = new MockServerRestTemplateCustomizer(); MyBean bean = new MyBean(new RestTemplateBuilder(customizer)); 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(RestTemplate)
or getServers()
method must be used to access
the related server.
- Since:
- 1.4.0
- Author:
- Phillip Webb, Moritz Halbritter, Chinmoy Chakraborty
- See Also:
-
Constructor Summary
ConstructorDescriptionMockServerRestTemplateCustomizer
(Class<? extends RequestExpectationManager> expectationManager) Create a newMockServerRestTemplateCustomizer
instance.MockServerRestTemplateCustomizer
(Supplier<? extends RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestTemplateCustomizer
instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected RequestExpectationManager
void
customize
(RestTemplate restTemplate) Callback to customize aRestTemplate
instance.getServer
(RestTemplate restTemplate) void
setBufferContent
(boolean bufferContent) Set if theBufferingClientHttpRequestFactory
wrapper should be used to buffer the input and output streams, and for example, allow multiple reads of the response body.void
setDetectRootUri
(boolean detectRootUri) Set if root URIs fromRootUriRequestExpectationManager
should be detected and applied to theMockRestServiceServer
.
-
Constructor Details
-
MockServerRestTemplateCustomizer
public MockServerRestTemplateCustomizer() -
MockServerRestTemplateCustomizer
public MockServerRestTemplateCustomizer(Class<? extends RequestExpectationManager> expectationManager) Create a newMockServerRestTemplateCustomizer
instance.- Parameters:
expectationManager
- the expectation manager class to use
-
MockServerRestTemplateCustomizer
public MockServerRestTemplateCustomizer(Supplier<? extends RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestTemplateCustomizer
instance.- Parameters:
expectationManagerSupplier
- a supplier that provides theRequestExpectationManager
to use- Since:
- 3.0.0
-
-
Method Details
-
setDetectRootUri
public void setDetectRootUri(boolean detectRootUri) Set if root URIs fromRootUriRequestExpectationManager
should be detected and applied to theMockRestServiceServer
.- Parameters:
detectRootUri
- if root URIs should be detected
-
setBufferContent
public void setBufferContent(boolean bufferContent) Set if theBufferingClientHttpRequestFactory
wrapper 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
Description copied from interface:RestTemplateCustomizer
Callback to customize aRestTemplate
instance.- Specified by:
customize
in interfaceRestTemplateCustomizer
- Parameters:
restTemplate
- the template to customize
-
createExpectationManager
-
getServer
-
getExpectationManagers
-
getServer
-
getServers
-