Class MockServerRestTemplateCustomizer

java.lang.Object
org.springframework.boot.restclient.test.MockServerRestTemplateCustomizer
All Implemented Interfaces:
RestTemplateCustomizer

@Deprecated(since="4.2.0", forRemoval=true) public class MockServerRestTemplateCustomizer extends Object implements RestTemplateCustomizer
Deprecated, for removal: This API element is subject to removal in a future version.
since 4.2.0 for removal in 4.4.0 in favor of MockServerRestClientCustomizer
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().

Since:
4.0.0
Author:
Phillip Webb, Moritz Halbritter, Chinmoy Chakraborty
See Also:
  • Constructor Details

    • MockServerRestTemplateCustomizer

      public MockServerRestTemplateCustomizer()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • MockServerRestTemplateCustomizer

      public MockServerRestTemplateCustomizer(Class<? extends RequestExpectationManager> expectationManager)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Create a new MockServerRestTemplateCustomizer instance.
      Parameters:
      expectationManager - the expectation manager class to use
    • MockServerRestTemplateCustomizer

      public MockServerRestTemplateCustomizer(Supplier<? extends RequestExpectationManager> expectationManagerSupplier)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Create a new MockServerRestTemplateCustomizer instance.
      Parameters:
      expectationManagerSupplier - a supplier that provides the RequestExpectationManager to use
  • Method Details

    • setDetectRootUri

      public void setDetectRootUri(boolean detectRootUri)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set if root URIs from RootUriRequestExpectationManager should be detected and applied to the MockRestServiceServer.
      Parameters:
      detectRootUri - if root URIs should be detected
    • setBufferContent

      public void setBufferContent(boolean bufferContent)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set if the BufferingClientHttpRequestFactory wrapper should be used to buffer the input and output streams, and for example, allow multiple reads of the response body.
      Parameters:
      bufferContent - if request and response content should be buffered
    • customize

      public void customize(RestTemplate restTemplate)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Description copied from interface: RestTemplateCustomizer
      Callback to customize a RestTemplate instance.
      Specified by:
      customize in interface RestTemplateCustomizer
      Parameters:
      restTemplate - the template to customize
    • createExpectationManager

      protected RequestExpectationManager createExpectationManager()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getServer

      public MockRestServiceServer getServer()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getExpectationManagers

      public Map<RestTemplate, RequestExpectationManager> getExpectationManagers()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getServer

      public @Nullable MockRestServiceServer getServer(RestTemplate restTemplate)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getServers

      public Map<RestTemplate, MockRestServiceServer> getServers()
      Deprecated, for removal: This API element is subject to removal in a future version.