类 MockServerRestTemplateCustomizer
java.lang.Object
org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer
- 所有已实现的接口:
RestTemplateCustomizer
RestTemplateCustomizer that can be applied to a RestTemplateBuilder
instances to add MockRestServiceServer support.
Typically applied to an existing builder before it is used, for example:
MockServerRestTemplateCustomizer customizer = new MockServerRestTemplateCustomizer();
MyBean bean = new MyBean(new RestTemplateBuilder(customizer));
customizer.getServer().expect(requestTo("/hello")).andRespond(withSuccess());
bean.makeRestCall();
If the customizer is only used once, the getServer() method can be used to
obtain the mock server. If the customizer has been used more than once the
getServer(RestTemplate) or getServers() method must be used to access
the related server.
If a mock server is used in more than one test case in a test class, it might be
necessary to reset the expectations on the server between tests using
getServer().reset() or getServer(restTemplate).reset().
- 从以下版本开始:
- 1.4.0
- 作者:
- Phillip Webb, Moritz Halbritter, Chinmoy Chakraborty
- 另请参阅:
-
构造器概要
构造器构造器说明MockServerRestTemplateCustomizer(Class<? extends RequestExpectationManager> expectationManager) Create a newMockServerRestTemplateCustomizerinstance.MockServerRestTemplateCustomizer(Supplier<? extends RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestTemplateCustomizerinstance. -
方法概要
修饰符和类型方法说明protected RequestExpectationManagervoidcustomize(RestTemplate restTemplate) Callback to customize aRestTemplateinstance.getServer(RestTemplate restTemplate) voidsetBufferContent(boolean bufferContent) Set if theBufferingClientHttpRequestFactorywrapper should be used to buffer the input and output streams, and for example, allow multiple reads of the response body.voidsetDetectRootUri(boolean detectRootUri) Set if root URIs fromRootUriRequestExpectationManagershould be detected and applied to theMockRestServiceServer.
-
构造器详细资料
-
MockServerRestTemplateCustomizer
public MockServerRestTemplateCustomizer() -
MockServerRestTemplateCustomizer
public MockServerRestTemplateCustomizer(Class<? extends RequestExpectationManager> expectationManager) Create a newMockServerRestTemplateCustomizerinstance.- 参数:
expectationManager- the expectation manager class to use
-
MockServerRestTemplateCustomizer
public MockServerRestTemplateCustomizer(Supplier<? extends RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestTemplateCustomizerinstance.- 参数:
expectationManagerSupplier- a supplier that provides theRequestExpectationManagerto use- 从以下版本开始:
- 3.0.0
-
-
方法详细资料
-
setDetectRootUri
public void setDetectRootUri(boolean detectRootUri) Set if root URIs fromRootUriRequestExpectationManagershould be detected and applied to theMockRestServiceServer.- 参数:
detectRootUri- if root URIs should be detected
-
setBufferContent
public void setBufferContent(boolean bufferContent) Set if theBufferingClientHttpRequestFactorywrapper should be used to buffer the input and output streams, and for example, allow multiple reads of the response body.- 参数:
bufferContent- if request and response content should be buffered- 从以下版本开始:
- 3.1.0
-
customize
从接口复制的说明:RestTemplateCustomizerCallback to customize aRestTemplateinstance.- 指定者:
customize在接口中RestTemplateCustomizer- 参数:
restTemplate- the template to customize
-
createExpectationManager
-
getServer
-
getExpectationManagers
-
getServer
-
getServers
-