类 RootUriRequestExpectationManager
- java.lang.Object
- org.springframework.boot.test.web.client.RootUriRequestExpectationManager
- 所有已实现的接口:
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("http://example.com").build(); MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate); server.expect(requestTo("/hello")).andRespond(withSuccess()); restTemplate.getForEntity("/hello", String.class);
- 从以下版本开始:
- 1.4.0
- 另请参阅:
RootUriTemplateHandler
,bindTo(RestTemplate)
,forRestTemplate(RestTemplate, RequestExpectationManager)
构造器概要
构造器 构造器 说明 RootUriRequestExpectationManager(String rootUri, org.springframework.test.web.client.RequestExpectationManager expectationManager)
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static org.springframework.test.web.client.MockRestServiceServer
bindTo(org.springframework.web.client.RestTemplate restTemplate)
Return a boundMockRestServiceServer
for the givenRestTemplate
, configured withRootUriRequestExpectationManager
when possible.static org.springframework.test.web.client.MockRestServiceServer
bindTo(org.springframework.web.client.RestTemplate restTemplate, org.springframework.test.web.client.RequestExpectationManager expectationManager)
Return a boundMockRestServiceServer
for the givenRestTemplate
, configured withRootUriRequestExpectationManager
when possible.org.springframework.test.web.client.ResponseActions
expectRequest(org.springframework.test.web.client.ExpectedCount count, org.springframework.test.web.client.RequestMatcher requestMatcher)
static org.springframework.test.web.client.RequestExpectationManager
forRestTemplate(org.springframework.web.client.RestTemplate restTemplate, org.springframework.test.web.client.RequestExpectationManager expectationManager)
ReturnRequestExpectationManager
to be used for binding with the specifiedRestTemplate
.void
reset()
org.springframework.http.client.ClientHttpResponse
validateRequest(org.springframework.http.client.ClientHttpRequest request)
void
verify()
构造器详细资料
RootUriRequestExpectationManager
public RootUriRequestExpectationManager(String rootUri, org.springframework.test.web.client.RequestExpectationManager expectationManager)
方法详细资料
expectRequest
public org.springframework.test.web.client.ResponseActions expectRequest(org.springframework.test.web.client.ExpectedCount count, org.springframework.test.web.client.RequestMatcher requestMatcher)
- 指定者:
expectRequest
在接口中org.springframework.test.web.client.RequestExpectationManager
validateRequest
public org.springframework.http.client.ClientHttpResponse validateRequest(org.springframework.http.client.ClientHttpRequest request) throws IOException
- 指定者:
validateRequest
在接口中org.springframework.test.web.client.RequestExpectationManager
- 抛出:
IOException
verify
public void verify()
- 指定者:
verify
在接口中org.springframework.test.web.client.RequestExpectationManager
reset
public void reset()
- 指定者:
reset
在接口中org.springframework.test.web.client.RequestExpectationManager
bindTo
public static org.springframework.test.web.client.MockRestServiceServer bindTo(org.springframework.web.client.RestTemplate restTemplate)
Return a boundMockRestServiceServer
for the givenRestTemplate
, configured withRootUriRequestExpectationManager
when possible.- 参数:
restTemplate
- the source REST template- 返回:
- 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 boundMockRestServiceServer
for the givenRestTemplate
, configured withRootUriRequestExpectationManager
when possible.- 参数:
restTemplate
- the source REST templateexpectationManager
- the sourceRequestExpectationManager
- 返回:
- 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)
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.- 参数:
restTemplate
- the source REST templateexpectationManager
- the sourceRequestExpectationManager
- 返回:
- a
RequestExpectationManager
to be bound to the template