类 RootUriRequestExpectationManager
java.lang.Object
cn.taketoday.framework.test.web.client.RootUriRequestExpectationManager
- 所有已实现的接口:
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);
- 从以下版本开始:
- 4.0
- 作者:
- Phillip Webb
- 另请参阅:
-
RootUriTemplateHandlerbindTo(RestTemplate)forRestTemplate(RestTemplate, RequestExpectationManager)
-
嵌套类概要
嵌套类修饰符和类型类说明private static classClientHttpRequestwrapper to replace the request URI. -
字段概要
字段 -
构造器概要
构造器构造器说明RootUriRequestExpectationManager(String rootUri, RequestExpectationManager expectationManager) -
方法概要
修饰符和类型方法说明static MockRestServiceServerbindTo(cn.taketoday.web.client.RestTemplate restTemplate) Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.static MockRestServiceServerbindTo(cn.taketoday.web.client.RestTemplate restTemplate, RequestExpectationManager expectationManager) Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.expectRequest(ExpectedCount count, RequestMatcher requestMatcher) Set up a new request expectation.static RequestExpectationManagerforRestTemplate(cn.taketoday.web.client.RestTemplate restTemplate, RequestExpectationManager expectationManager) ReturnRequestExpectationManagerto be used for binding with the specifiedRestTemplate.private cn.taketoday.http.client.ClientHttpRequestreplaceURI(cn.taketoday.http.client.ClientHttpRequest request, String replacementUri) voidreset()Reset the internal state removing all expectations and recorded requests.cn.taketoday.http.client.ClientHttpResponsevalidateRequest(cn.taketoday.http.client.ClientHttpRequest request) Validate the given actual request against the declared expectations.voidverify()Verify that all expectations have been met.voidVariant ofRequestExpectationManager.verify()that waits for up to the specified time for all expectations to be fulfilled.
-
字段详细资料
-
rootUri
-
expectationManager
-
-
构造器详细资料
-
RootUriRequestExpectationManager
public RootUriRequestExpectationManager(String rootUri, RequestExpectationManager expectationManager)
-
-
方法详细资料
-
expectRequest
从接口复制的说明:RequestExpectationManagerSet up a new request expectation. The returnedResponseActionsis used to add more expectations and define a response.This is a delegate for
MockRestServiceServer.expect(ExpectedCount, RequestMatcher).- 指定者:
expectRequest在接口中RequestExpectationManagerrequestMatcher- a request expectation- 返回:
- for setting up further expectations and define a response
- 另请参阅:
-
validateRequest
public cn.taketoday.http.client.ClientHttpResponse validateRequest(cn.taketoday.http.client.ClientHttpRequest request) throws IOException 从接口复制的说明:RequestExpectationManagerValidate the given actual request against the declared expectations. Is successful return the mock response to use or raise an error.This is used in
MockRestServiceServeragainst actual requests.- 指定者:
validateRequest在接口中RequestExpectationManager- 参数:
request- the request- 返回:
- the response to return if the request was validated.
- 抛出:
IOException- in case of any validation errors
-
replaceURI
private cn.taketoday.http.client.ClientHttpRequest replaceURI(cn.taketoday.http.client.ClientHttpRequest request, String replacementUri) -
verify
public void verify()从接口复制的说明:RequestExpectationManagerVerify that all expectations have been met.This is a delegate for
MockRestServiceServer.verify().- 指定者:
verify在接口中RequestExpectationManager- 另请参阅:
-
verify
从接口复制的说明:RequestExpectationManagerVariant ofRequestExpectationManager.verify()that waits for up to the specified time for all expectations to be fulfilled. This can be useful for tests that involve asynchronous requests.- 指定者:
verify在接口中RequestExpectationManager- 参数:
timeout- how long to wait for all expecations to be met
-
reset
public void reset()从接口复制的说明:RequestExpectationManagerReset the internal state removing all expectations and recorded requests.This is a delegate for
MockRestServiceServer.reset().- 指定者:
reset在接口中RequestExpectationManager- 另请参阅:
-
bindTo
Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.- 参数:
restTemplate- the source REST template- 返回:
- a configured
MockRestServiceServer
-
bindTo
public static MockRestServiceServer bindTo(cn.taketoday.web.client.RestTemplate restTemplate, RequestExpectationManager expectationManager) Return a boundMockRestServiceServerfor the givenRestTemplate, configured withRootUriRequestExpectationManagerwhen possible.- 参数:
restTemplate- the source REST templateexpectationManager- the sourceRequestExpectationManager- 返回:
- a configured
MockRestServiceServer
-
forRestTemplate
public static RequestExpectationManager forRestTemplate(cn.taketoday.web.client.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.- 参数:
restTemplate- the source REST templateexpectationManager- the sourceRequestExpectationManager- 返回:
- a
RequestExpectationManagerto be bound to the template
-