Class RootUriRequestExpectationManager
java.lang.Object
org.springframework.boot.test.web.client.RootUriRequestExpectationManager
- All Implemented Interfaces:
org.springframework.test.web.client.RequestExpectationManager
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);
- Since:
- 1.4.0
- See Also:
-
RootUriTemplateHandlerbindTo(RestTemplate)forRestTemplate(RestTemplate, RequestExpectationManager)
-
Constructor Summary
ConstructorsConstructorDescriptionRootUriRequestExpectationManager(String rootUri, org.springframework.test.web.client.RequestExpectationManager expectationManager) -
Method Summary
Modifier and TypeMethodDescriptionstatic org.springframework.test.web.client.MockRestServiceServerbindTo(org.springframework.web.client.RestTemplate restTemplate) Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.static org.springframework.test.web.client.MockRestServiceServerbindTo(org.springframework.web.client.RestTemplate restTemplate, org.springframework.test.web.client.RequestExpectationManager expectationManager) Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.org.springframework.test.web.client.ResponseActionsexpectRequest(org.springframework.test.web.client.ExpectedCount count, org.springframework.test.web.client.RequestMatcher requestMatcher) static org.springframework.test.web.client.RequestExpectationManagerforRestTemplate(org.springframework.web.client.RestTemplate restTemplate, org.springframework.test.web.client.RequestExpectationManager expectationManager) ReturnRequestExpectationManagerto be used for binding with the specifiedRestTemplate.voidreset()org.springframework.http.client.ClientHttpResponsevalidateRequest(org.springframework.http.client.ClientHttpRequest request) voidverify()void
-
Constructor Details
-
RootUriRequestExpectationManager
public RootUriRequestExpectationManager(String rootUri, org.springframework.test.web.client.RequestExpectationManager expectationManager)
-
-
Method Details
-
expectRequest
public org.springframework.test.web.client.ResponseActions expectRequest(org.springframework.test.web.client.ExpectedCount count, org.springframework.test.web.client.RequestMatcher requestMatcher) - Specified by:
expectRequestin interfaceorg.springframework.test.web.client.RequestExpectationManager
-
validateRequest
public org.springframework.http.client.ClientHttpResponse validateRequest(org.springframework.http.client.ClientHttpRequest request) throws IOException - Specified by:
validateRequestin interfaceorg.springframework.test.web.client.RequestExpectationManager- Throws:
IOException
-
verify
public void verify()- Specified by:
verifyin interfaceorg.springframework.test.web.client.RequestExpectationManager
-
verify
- Specified by:
verifyin interfaceorg.springframework.test.web.client.RequestExpectationManager
-
reset
public void reset()- Specified by:
resetin interfaceorg.springframework.test.web.client.RequestExpectationManager
-
bindTo
public static org.springframework.test.web.client.MockRestServiceServer bindTo(org.springframework.web.client.RestTemplate restTemplate) Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.- Parameters:
restTemplate- the source REST template- Returns:
- a configured
MockRestServiceServer
-
bindTo
public static org.springframework.test.web.client.MockRestServiceServer bindTo(org.springframework.web.client.RestTemplate restTemplate, org.springframework.test.web.client.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 org.springframework.test.web.client.RequestExpectationManager forRestTemplate(org.springframework.web.client.RestTemplate restTemplate, org.springframework.test.web.client.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
-