Class RootUriRequestExpectationManager
java.lang.Object
org.springframework.boot.test.web.client.RootUriRequestExpectationManager
- All Implemented Interfaces:
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);
- Since:
- 1.4.0
- Author:
- Phillip Webb
- See Also:
-
Constructor Summary
ConstructorDescriptionRootUriRequestExpectationManager
(String rootUri, RequestExpectationManager expectationManager) -
Method Summary
Modifier and TypeMethodDescriptionstatic MockRestServiceServer
bindTo
(RestTemplate restTemplate) Return a boundMockRestServiceServer
for the givenRestTemplate
, configured withRootUriRequestExpectationManager
when possible.static MockRestServiceServer
bindTo
(RestTemplate restTemplate, RequestExpectationManager expectationManager) Return a boundMockRestServiceServer
for the givenRestTemplate
, configured withRootUriRequestExpectationManager
when possible.expectRequest
(ExpectedCount count, RequestMatcher requestMatcher) static RequestExpectationManager
forRestTemplate
(RestTemplate restTemplate, RequestExpectationManager expectationManager) ReturnRequestExpectationManager
to be used for binding with the specifiedRestTemplate
.void
reset()
validateRequest
(ClientHttpRequest request) void
verify()
void
-
Constructor Details
-
RootUriRequestExpectationManager
public RootUriRequestExpectationManager(String rootUri, RequestExpectationManager expectationManager)
-
-
Method Details
-
expectRequest
- Specified by:
expectRequest
in interfaceRequestExpectationManager
-
validateRequest
- Specified by:
validateRequest
in interfaceRequestExpectationManager
- Throws:
IOException
-
verify
public void verify()- Specified by:
verify
in interfaceRequestExpectationManager
-
verify
- Specified by:
verify
in interfaceRequestExpectationManager
-
reset
public void reset()- Specified by:
reset
in interfaceRequestExpectationManager
-
bindTo
Return a boundMockRestServiceServer
for the givenRestTemplate
, configured withRootUriRequestExpectationManager
when possible.- Parameters:
restTemplate
- the source REST template- Returns:
- a configured
MockRestServiceServer
-
bindTo
public static MockRestServiceServer bindTo(RestTemplate restTemplate, RequestExpectationManager expectationManager) Return a boundMockRestServiceServer
for the givenRestTemplate
, configured withRootUriRequestExpectationManager
when possible.- Parameters:
restTemplate
- the source REST templateexpectationManager
- the sourceRequestExpectationManager
- Returns:
- a configured
MockRestServiceServer
-
forRestTemplate
public static RequestExpectationManager forRestTemplate(RestTemplate restTemplate, RequestExpectationManager expectationManager) ReturnRequestExpectationManager
to be used for binding with the specifiedRestTemplate
. If theRestTemplate
is using aRootUriTemplateHandler
then aRootUriRequestExpectationManager
is returned, otherwise the source manager is returned unchanged.- Parameters:
restTemplate
- the source REST templateexpectationManager
- the sourceRequestExpectationManager
- Returns:
- a
RequestExpectationManager
to be bound to the template
-