public class RootUriRequestExpectationManager extends Object implements 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,
RequestExpectationManager expectationManager) |
Modifier and Type | Method and Description |
---|---|
static MockRestServiceServer |
bindTo(RestTemplate restTemplate)
Return a bound
MockRestServiceServer for the given RestTemplate ,
configured with RootUriRequestExpectationManager when possible. |
static MockRestServiceServer |
bindTo(RestTemplate restTemplate,
RequestExpectationManager expectationManager)
Return a bound
MockRestServiceServer for the given RestTemplate ,
configured with RootUriRequestExpectationManager when possible. |
ResponseActions |
expectRequest(ExpectedCount count,
RequestMatcher requestMatcher) |
static RequestExpectationManager |
forRestTemplate(RestTemplate restTemplate,
RequestExpectationManager expectationManager)
Return
RequestExpectationManager to be used for binding with the specified
RestTemplate . |
void |
reset() |
ClientHttpResponse |
validateRequest(ClientHttpRequest request) |
void |
verify() |
public RootUriRequestExpectationManager(String rootUri, RequestExpectationManager expectationManager)
public ResponseActions expectRequest(ExpectedCount count, RequestMatcher requestMatcher)
expectRequest
in interface RequestExpectationManager
public ClientHttpResponse validateRequest(ClientHttpRequest request) throws IOException
validateRequest
in interface RequestExpectationManager
IOException
public void verify()
verify
in interface RequestExpectationManager
public void reset()
reset
in interface RequestExpectationManager
public static MockRestServiceServer bindTo(RestTemplate restTemplate)
MockRestServiceServer
for the given RestTemplate
,
configured with RootUriRequestExpectationManager
when possible.restTemplate
- the source REST templateMockRestServiceServer
public static MockRestServiceServer bindTo(RestTemplate restTemplate, RequestExpectationManager expectationManager)
MockRestServiceServer
for the given RestTemplate
,
configured with RootUriRequestExpectationManager
when possible.restTemplate
- the source REST templateexpectationManager
- the source RequestExpectationManager
MockRestServiceServer
public static RequestExpectationManager forRestTemplate(RestTemplate restTemplate, 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 template