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 org.springframework.test.web.client.RequestExpectationManager> expectationManager) |
Modifier and Type | Method and Description |
---|---|
protected org.springframework.test.web.client.RequestExpectationManager |
createExpectationManager() |
void |
customize(org.springframework.web.client.RestTemplate restTemplate)
Callback to customize a
RestTemplate instance. |
Map<org.springframework.web.client.RestTemplate,org.springframework.test.web.client.RequestExpectationManager> |
getExpectationManagers() |
org.springframework.test.web.client.MockRestServiceServer |
getServer() |
org.springframework.test.web.client.MockRestServiceServer |
getServer(org.springframework.web.client.RestTemplate restTemplate) |
Map<org.springframework.web.client.RestTemplate,org.springframework.test.web.client.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 org.springframework.test.web.client.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(org.springframework.web.client.RestTemplate restTemplate)
RestTemplateCustomizer
RestTemplate
instance.customize
in interface RestTemplateCustomizer
restTemplate
- the template to customizeprotected org.springframework.test.web.client.RequestExpectationManager createExpectationManager()
public org.springframework.test.web.client.MockRestServiceServer getServer()
public Map<org.springframework.web.client.RestTemplate,org.springframework.test.web.client.RequestExpectationManager> getExpectationManagers()
public org.springframework.test.web.client.MockRestServiceServer getServer(org.springframework.web.client.RestTemplate restTemplate)
public Map<org.springframework.web.client.RestTemplate,org.springframework.test.web.client.MockRestServiceServer> getServers()
Copyright © 2019 Pivotal Software, Inc.. All rights reserved.