MockServerRestTemplateCustomizer
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();
Content copied to clipboard
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 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(restTemplate).reset()
.
Author
Phillip Webb
Moritz Halbritter
Chinmoy Chakraborty
Since
1.4.0
See also
Constructors
Link copied to clipboard
constructor()
Create a new MockServerRestTemplateCustomizer instance.
Create a new MockServerRestTemplateCustomizer instance.
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Set if the BufferingClientHttpRequestFactory wrapper should be used to buffer the input and output streams, and for example, allow multiple reads of the response body.
Link copied to clipboard
Set if root URIs from RootUriRequestExpectationManager should be detected and applied to the MockRestServiceServer.