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
ConstructorsConstructorDescriptionRootUriRequestExpectationManager(String rootUri, RequestExpectationManager expectationManager) -
Method Summary
Modifier and TypeMethodDescriptionstatic MockRestServiceServerbindTo(RestTemplate restTemplate) Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.static MockRestServiceServerbindTo(RestTemplate restTemplate, RequestExpectationManager expectationManager) Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.expectRequest(ExpectedCount count, RequestMatcher requestMatcher) static RequestExpectationManagerforRestTemplate(RestTemplate restTemplate, RequestExpectationManager expectationManager) ReturnRequestExpectationManagerto be used for binding with the specifiedRestTemplate.voidreset()validateRequest(ClientHttpRequest request) voidverify()void
-
Constructor Details
-
RootUriRequestExpectationManager
public RootUriRequestExpectationManager(String rootUri, RequestExpectationManager expectationManager)
-
-
Method Details
-
expectRequest
- Specified by:
expectRequestin interfaceRequestExpectationManager
-
validateRequest
- Specified by:
validateRequestin interfaceRequestExpectationManager- Throws:
IOException
-
verify
public void verify()- Specified by:
verifyin interfaceRequestExpectationManager
-
verify
- Specified by:
verifyin interfaceRequestExpectationManager
-
reset
public void reset()- Specified by:
resetin interfaceRequestExpectationManager
-
bindTo
Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.- Parameters:
restTemplate- the source REST template- Returns:
- a configured
MockRestServiceServer
-
bindTo
public static MockRestServiceServer bindTo(RestTemplate restTemplate, RequestExpectationManager expectationManager) Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.- Parameters:
restTemplate- the source REST templateexpectationManager- the sourceRequestExpectationManager- Returns:
- a configured
MockRestServiceServer
-
forRestTemplate
public static RequestExpectationManager forRestTemplate(RestTemplate restTemplate, RequestExpectationManager expectationManager) ReturnRequestExpectationManagerto be used for binding with the specifiedRestTemplate. If theRestTemplateis using aRootUriTemplateHandlerthen aRootUriRequestExpectationManageris returned, otherwise the source manager is returned unchanged.- Parameters:
restTemplate- the source REST templateexpectationManager- the sourceRequestExpectationManager- Returns:
- a
RequestExpectationManagerto be bound to the template
-