Class MockMvcWebClientBuilder
- java.lang.Object
- org.springframework.test.web.servlet.htmlunit.MockMvcWebConnectionBuilderSupport<MockMvcWebClientBuilder>
- org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder
public class MockMvcWebClientBuilder extends MockMvcWebConnectionBuilderSupport<MockMvcWebClientBuilder>
MockMvcWebClientBuilder
simplifies the creation of an HtmlUnitWebClient
that delegates to aMockMvc
instance.The
MockMvc
instance used by the builder may be supplied directly or created transparently from aWebApplicationContext
.- Since:
- 4.2
- Author:
- Rob Winch, Sam Brannen
- See Also:
mockMvcSetup(MockMvc)
,webAppContextSetup(WebApplicationContext)
,webAppContextSetup(WebApplicationContext, MockMvcConfigurer)
,withDelegate(WebClient)
,build()
Constructor Summary
Constructors Modifier Constructor Description protected
MockMvcWebClientBuilder(MockMvc mockMvc)
protected
MockMvcWebClientBuilder(WebApplicationContext context)
protected
MockMvcWebClientBuilder(WebApplicationContext context, MockMvcConfigurer configurer)
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.gargoylesoftware.htmlunit.WebClient
build()
Build theWebClient
configured via this builder.static MockMvcWebClientBuilder
mockMvcSetup(MockMvc mockMvc)
Create a newMockMvcWebClientBuilder
based on the suppliedMockMvc
instance.static MockMvcWebClientBuilder
webAppContextSetup(WebApplicationContext context)
Create a newMockMvcWebClientBuilder
based on the suppliedWebApplicationContext
.static MockMvcWebClientBuilder
webAppContextSetup(WebApplicationContext context, MockMvcConfigurer configurer)
Create a newMockMvcWebClientBuilder
based on the suppliedWebApplicationContext
andMockMvcConfigurer
.MockMvcWebClientBuilder
withDelegate(com.gargoylesoftware.htmlunit.WebClient webClient)
Methods inherited from class org.springframework.test.web.servlet.htmlunit.MockMvcWebConnectionBuilderSupport
alwaysUseMockMvc, contextPath, createConnection, useMockMvc, useMockMvcForHosts
Constructor Detail
MockMvcWebClientBuilder
protected MockMvcWebClientBuilder(MockMvc mockMvc)
MockMvcWebClientBuilder
protected MockMvcWebClientBuilder(WebApplicationContext context)
MockMvcWebClientBuilder
protected MockMvcWebClientBuilder(WebApplicationContext context, MockMvcConfigurer configurer)
Method Detail
mockMvcSetup
public static MockMvcWebClientBuilder mockMvcSetup(MockMvc mockMvc)
Create a newMockMvcWebClientBuilder
based on the suppliedMockMvc
instance.- Parameters:
mockMvc
- theMockMvc
instance to use; nevernull
- Returns:
- the MockMvcWebClientBuilder to customize
webAppContextSetup
public static MockMvcWebClientBuilder webAppContextSetup(WebApplicationContext context)
Create a newMockMvcWebClientBuilder
based on the suppliedWebApplicationContext
.- Parameters:
context
- theWebApplicationContext
to create aMockMvc
instance from; nevernull
- Returns:
- the MockMvcWebClientBuilder to customize
webAppContextSetup
public static MockMvcWebClientBuilder webAppContextSetup(WebApplicationContext context, MockMvcConfigurer configurer)
Create a newMockMvcWebClientBuilder
based on the suppliedWebApplicationContext
andMockMvcConfigurer
.- Parameters:
context
- theWebApplicationContext
to create aMockMvc
instance from; nevernull
configurer
- theMockMvcConfigurer
to apply; nevernull
- Returns:
- the MockMvcWebClientBuilder to customize
withDelegate
public MockMvcWebClientBuilder withDelegate(com.gargoylesoftware.htmlunit.WebClient webClient)
Supply theWebClient
that the client built by this builder should delegate to when processing non-matching requests.- Parameters:
webClient
- theWebClient
to delegate to for requests that do not match; nevernull
- Returns:
- this builder for further customization
- See Also:
build()
build
public com.gargoylesoftware.htmlunit.WebClient build()
Build theWebClient
configured via this builder.The returned client will use the configured
MockMvc
instance for processing any matching requests and a delegateWebClient
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:
withDelegate(WebClient)