Class MockServerRestTemplateCustomizer
- java.lang.Object
- org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer
- All Implemented Interfaces:
org.springframework.boot.web.client.RestTemplateCustomizer
public class MockServerRestTemplateCustomizer extends Object implements org.springframework.boot.web.client.RestTemplateCustomizer
RestTemplateCustomizer
that can be applied to aRestTemplateBuilder
instances to addMockRestServiceServer
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 thegetServer(RestTemplate)
orgetServers()
method must be used to access the related server.- Since:
- 1.4.0
- See Also:
getServer()
,getServer(RestTemplate)
Constructor Summary
Constructors Constructor Description MockServerRestTemplateCustomizer()
MockServerRestTemplateCustomizer(Class<? extends org.springframework.test.web.client.RequestExpectationManager> expectationManager)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.springframework.test.web.client.RequestExpectationManager
createExpectationManager()
void
customize(org.springframework.web.client.RestTemplate restTemplate)
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 fromRootUriRequestExpectationManager
should be detected and applied to theMockRestServiceServer
.
Constructor Detail
MockServerRestTemplateCustomizer
public MockServerRestTemplateCustomizer()
MockServerRestTemplateCustomizer
public MockServerRestTemplateCustomizer(Class<? extends org.springframework.test.web.client.RequestExpectationManager> expectationManager)
Method Detail
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
customize
public void customize(org.springframework.web.client.RestTemplate restTemplate)
- Specified by:
customize
in interfaceorg.springframework.boot.web.client.RestTemplateCustomizer
createExpectationManager
protected org.springframework.test.web.client.RequestExpectationManager createExpectationManager()
getServer
public org.springframework.test.web.client.MockRestServiceServer getServer()
getExpectationManagers
public Map<org.springframework.web.client.RestTemplate,org.springframework.test.web.client.RequestExpectationManager> getExpectationManagers()
getServer
public org.springframework.test.web.client.MockRestServiceServer getServer(org.springframework.web.client.RestTemplate restTemplate)
getServers
public Map<org.springframework.web.client.RestTemplate,org.springframework.test.web.client.MockRestServiceServer> getServers()