spring-framework / org.springframework.test.web.servlet.htmlunit / MockMvcWebClientBuilder

MockMvcWebClientBuilder

open class MockMvcWebClientBuilder : 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.

Author
Rob Winch

Author
Sam Brannen

Since
4.2

See Also
#mockMvcSetup(MockMvc)#webAppContextSetup(WebApplicationContext)#webAppContextSetup(WebApplicationContext, MockMvcConfigurer)#withDelegate(WebClient)#build()

Functions

build

open fun build(): WebClient

Build the WebClient configured via this builder.

The returned client will use the configured MockMvc instance for processing any WebRequestMatcher 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.

mockMvcSetup

open static fun mockMvcSetup(mockMvc: MockMvc): MockMvcWebClientBuilder

Create a new MockMvcWebClientBuilder based on the supplied MockMvc instance.

webAppContextSetup

open static fun webAppContextSetup(context: WebApplicationContext): MockMvcWebClientBuilder

Create a new MockMvcWebClientBuilder based on the supplied WebApplicationContext.

open static fun webAppContextSetup(context: WebApplicationContext, configurer: MockMvcConfigurer): MockMvcWebClientBuilder

Create a new MockMvcWebClientBuilder based on the supplied WebApplicationContext and MockMvcConfigurer.

withDelegate

open fun withDelegate(webClient: WebClient): MockMvcWebClientBuilder

Supply the WebClient that the client built by this builder should delegate to when processing non-WebRequestMatcher requests.

Inherited Functions

alwaysUseMockMvc

open fun alwaysUseMockMvc(): T

Specify that MockMvc should always be used regardless of what the request looks like.

contextPath

open fun contextPath(contextPath: String): T

Set the context path to use.

If the supplied value is null or empty, the first path segment of the request URL is assumed to be the context path.

Default is "".

useMockMvc

open fun useMockMvc(vararg matchers: WebRequestMatcher): T

Add additional WebRequestMatcher instances that will ensure that MockMvc is used to process the request, if such a matcher matches against the web request.

useMockMvcForHosts

open fun useMockMvcForHosts(vararg hosts: String): T

Add additional WebRequestMatcher instances that return true if a supplied host matches — for example, "example.com" or "example.com:8080".