Class MockMvcWebClientBuilder


public class MockMvcWebClientBuilder extends MockMvcWebConnectionBuilderSupport<MockMvcWebClientBuilder>
MockMvcWebClientBuilder simplifies the creation of an HtmlUnit WebClient that delegates to a MockMvc instance.

The MockMvc instance used by the builder may be supplied directly or created transparently from a WebApplicationContext.

Since:
4.2
Author:
Rob Winch, Sam Brannen
See Also:
  • Constructor Details

  • Method Details

    • mockMvcSetup

      public static MockMvcWebClientBuilder mockMvcSetup(MockMvc mockMvc)
      Create a new MockMvcWebClientBuilder based on the supplied MockMvc instance.
      Parameters:
      mockMvc - the MockMvc instance to use; never null
      Returns:
      the MockMvcWebClientBuilder to customize
    • webAppContextSetup

      public static MockMvcWebClientBuilder webAppContextSetup(WebApplicationContext context)
      Create a new MockMvcWebClientBuilder based on the supplied WebApplicationContext.
      Parameters:
      context - the WebApplicationContext to create a MockMvc instance from; never null
      Returns:
      the MockMvcWebClientBuilder to customize
    • webAppContextSetup

      public static MockMvcWebClientBuilder webAppContextSetup(WebApplicationContext context, MockMvcConfigurer configurer)
      Create a new MockMvcWebClientBuilder based on the supplied WebApplicationContext and MockMvcConfigurer.
      Parameters:
      context - the WebApplicationContext to create a MockMvc instance from; never null
      configurer - the MockMvcConfigurer to apply; never null
      Returns:
      the MockMvcWebClientBuilder to customize
    • withDelegate

      public MockMvcWebClientBuilder withDelegate(com.gargoylesoftware.htmlunit.WebClient webClient)
      Supply the WebClient that the client built by this builder should delegate to when processing non-matching requests.
      Parameters:
      webClient - the WebClient to delegate to for requests that do not match; never null
      Returns:
      this builder for further customization
      See Also:
    • build

      public com.gargoylesoftware.htmlunit.WebClient build()
      Build the WebClient configured via this builder.

      The returned client will use the configured MockMvc instance for processing any matching requests and a delegate WebClient for all other requests.

      If a delegate has been explicitly configured, it will be used; otherwise, a default WebClient will be configured as the delegate.

      Returns:
      the WebClient to use
      See Also: