public class MockServerRestTemplateCustomizer extends Object implements 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.
getServer()
,
getServer(RestTemplate)
Constructor and Description |
---|
MockServerRestTemplateCustomizer() |
MockServerRestTemplateCustomizer(Class<? extends RequestExpectationManager> expectationManager) |
Modifier and Type | Method and Description |
---|---|
protected RequestExpectationManager |
createExpectationManager() |
void |
customize(RestTemplate restTemplate)
Callback to customize a
RestTemplate instance. |
Map<RestTemplate,RequestExpectationManager> |
getExpectationManagers() |
MockRestServiceServer |
getServer() |
MockRestServiceServer |
getServer(RestTemplate restTemplate) |
Map<RestTemplate,MockRestServiceServer> |
getServers() |
void |
setDetectRootUri(boolean detectRootUri)
Set if root URIs from
RootUriRequestExpectationManager should be detected
and applied to the MockRestServiceServer . |
public MockServerRestTemplateCustomizer()
public MockServerRestTemplateCustomizer(Class<? extends RequestExpectationManager> expectationManager)
public void setDetectRootUri(boolean detectRootUri)
RootUriRequestExpectationManager
should be detected
and applied to the MockRestServiceServer
.detectRootUri
- if root URIs should be detectedpublic void customize(RestTemplate restTemplate)
RestTemplateCustomizer
RestTemplate
instance.customize
in interface RestTemplateCustomizer
restTemplate
- the template to customizeprotected RequestExpectationManager createExpectationManager()
public MockRestServiceServer getServer()
public Map<RestTemplate,RequestExpectationManager> getExpectationManagers()
public MockRestServiceServer getServer(RestTemplate restTemplate)
public Map<RestTemplate,MockRestServiceServer> getServers()
Copyright © 2016 Pivotal Software, Inc.. All rights reserved.