public class RootUriRequestExpectationManager extends Object implements org.springframework.test.web.client.RequestExpectationManager
RequestExpectationManager
that strips the specified root URI from the request
before verification. Can be used to simply test declarations when all REST calls start
the same way. For example: RestTemplate restTemplate = new RestTemplateBuilder().rootUri("https://example.com").build(); MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate); server.expect(requestTo("/hello")).andRespond(withSuccess()); restTemplate.getForEntity("/hello", String.class);
RootUriTemplateHandler
,
bindTo(RestTemplate)
,
forRestTemplate(RestTemplate, RequestExpectationManager)
Constructor and Description |
---|
RootUriRequestExpectationManager(String rootUri,
org.springframework.test.web.client.RequestExpectationManager expectationManager) |
Modifier and Type | Method and Description |
---|---|
static org.springframework.test.web.client.MockRestServiceServer |
bindTo(org.springframework.web.client.RestTemplate restTemplate)
Return a bound
MockRestServiceServer for the given RestTemplate ,
configured with RootUriRequestExpectationManager when possible. |
static org.springframework.test.web.client.MockRestServiceServer |
bindTo(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.test.web.client.RequestExpectationManager expectationManager)
Return a bound
MockRestServiceServer for the given RestTemplate ,
configured with RootUriRequestExpectationManager when possible. |
org.springframework.test.web.client.ResponseActions |
expectRequest(org.springframework.test.web.client.ExpectedCount count,
org.springframework.test.web.client.RequestMatcher requestMatcher) |
static org.springframework.test.web.client.RequestExpectationManager |
forRestTemplate(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.test.web.client.RequestExpectationManager expectationManager)
Return
RequestExpectationManager to be used for binding with the specified
RestTemplate . |
void |
reset() |
org.springframework.http.client.ClientHttpResponse |
validateRequest(org.springframework.http.client.ClientHttpRequest request) |
void |
verify() |
public RootUriRequestExpectationManager(String rootUri, org.springframework.test.web.client.RequestExpectationManager expectationManager)
public org.springframework.test.web.client.ResponseActions expectRequest(org.springframework.test.web.client.ExpectedCount count, org.springframework.test.web.client.RequestMatcher requestMatcher)
expectRequest
in interface org.springframework.test.web.client.RequestExpectationManager
public org.springframework.http.client.ClientHttpResponse validateRequest(org.springframework.http.client.ClientHttpRequest request) throws IOException
validateRequest
in interface org.springframework.test.web.client.RequestExpectationManager
IOException
public void verify()
verify
in interface org.springframework.test.web.client.RequestExpectationManager
public void reset()
reset
in interface org.springframework.test.web.client.RequestExpectationManager
public static org.springframework.test.web.client.MockRestServiceServer bindTo(org.springframework.web.client.RestTemplate restTemplate)
MockRestServiceServer
for the given RestTemplate
,
configured with RootUriRequestExpectationManager
when possible.restTemplate
- the source REST templateMockRestServiceServer
public static org.springframework.test.web.client.MockRestServiceServer bindTo(org.springframework.web.client.RestTemplate restTemplate, org.springframework.test.web.client.RequestExpectationManager expectationManager)
MockRestServiceServer
for the given RestTemplate
,
configured with RootUriRequestExpectationManager
when possible.restTemplate
- the source REST templateexpectationManager
- the source RequestExpectationManager
MockRestServiceServer
public static org.springframework.test.web.client.RequestExpectationManager forRestTemplate(org.springframework.web.client.RestTemplate restTemplate, org.springframework.test.web.client.RequestExpectationManager expectationManager)
RequestExpectationManager
to be used for binding with the specified
RestTemplate
. If the RestTemplate
is using a
RootUriTemplateHandler
then a RootUriRequestExpectationManager
is
returned, otherwise the source manager is returned unchanged.restTemplate
- the source REST templateexpectationManager
- the source RequestExpectationManager
RequestExpectationManager
to be bound to the templateCopyright © 2019 Pivotal Software, Inc.. All rights reserved.