类 MockServerRestClientCustomizer
java.lang.Object
org.springframework.boot.test.web.client.MockServerRestClientCustomizer
- 所有已实现的接口:
RestClientCustomizer
RestClientCustomizer
that can be applied to RestClient.Builder
instances to add MockRestServiceServer
support.
Typically applied to an existing builder before it is used, for example:
MockServerRestClientCustomizer customizer = new MockServerRestClientCustomizer(); RestClient.Builder builder = RestClient.builder(); customizer.customize(builder); MyBean bean = new MyBean(client.build()); 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(RestClient.Builder)
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(restClientBuilder).reset()
.
- 从以下版本开始:
- 3.2.0
- 作者:
- Scott Frederick
- 另请参阅:
-
构造器概要
构造器构造器说明MockServerRestClientCustomizer
(Class<? extends RequestExpectationManager> expectationManager) Create a newMockServerRestClientCustomizer
instance.MockServerRestClientCustomizer
(Supplier<? extends RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestClientCustomizer
instance. -
方法概要
修饰符和类型方法说明protected RequestExpectationManager
void
customize
(RestClient.Builder restClientBuilder) Callback to customize aRestClient.Builder
instance.getServer
(RestClient.Builder restClientBuilder) void
setBufferContent
(boolean bufferContent) Set if theBufferingClientHttpRequestFactory
wrapper should be used to buffer the input and output streams, and for example, allow multiple reads of the response body.
-
构造器详细资料
-
MockServerRestClientCustomizer
public MockServerRestClientCustomizer() -
MockServerRestClientCustomizer
public MockServerRestClientCustomizer(Class<? extends RequestExpectationManager> expectationManager) Create a newMockServerRestClientCustomizer
instance.- 参数:
expectationManager
- the expectation manager class to use
-
MockServerRestClientCustomizer
public MockServerRestClientCustomizer(Supplier<? extends RequestExpectationManager> expectationManagerSupplier) Create a newMockServerRestClientCustomizer
instance.- 参数:
expectationManagerSupplier
- a supplier that provides theRequestExpectationManager
to use- 从以下版本开始:
- 3.0.0
-
-
方法详细资料
-
setBufferContent
public void setBufferContent(boolean bufferContent) Set if theBufferingClientHttpRequestFactory
wrapper 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
从接口复制的说明:RestClientCustomizer
Callback to customize aRestClient.Builder
instance.- 指定者:
customize
在接口中RestClientCustomizer
- 参数:
restClientBuilder
- the client builder to customize
-
createExpectationManager
-
getServer
-
getExpectationManagers
-
getServer
-
getServers
-