spring-framework / org.springframework.test.web.servlet.htmlunit.webdriver / MockMvcHtmlUnitDriverBuilder

MockMvcHtmlUnitDriverBuilder

open class MockMvcHtmlUnitDriverBuilder : MockMvcWebConnectionBuilderSupport<MockMvcHtmlUnitDriverBuilder>

MockMvcHtmlUnitDriverBuilder simplifies the building of an HtmlUnitDriver that delegates to MockMvc and optionally delegates to an actual connection for specific requests.

By default, the driver will delegate to MockMvc to handle requests to localhost and to a WebClient to handle any other URL (i.e. to perform an actual HTTP request).

Author
Rob Winch

Author
Sam Brannen

Since
4.2

See Also
#mockMvcSetup(MockMvc)#webAppContextSetup(WebApplicationContext)#webAppContextSetup(WebApplicationContext, MockMvcConfigurer)#javascriptEnabled(boolean)#withDelegate(WebConnectionHtmlUnitDriver)#build()

Functions

build

open fun build(): HtmlUnitDriver

Build the HtmlUnitDriver configured via this builder.

The returned driver will use the configured MockMvc instance for processing any WebRequestMatcher requests and a delegate HtmlUnitDriver for all other requests.

If a delegate has been explicitly configured, it will be used; otherwise, a default WebConnectionHtmlUnitDriver with the BrowserVersion set to CHROME will be configured as the delegate.

javascriptEnabled

open fun javascriptEnabled(javascriptEnabled: Boolean): MockMvcHtmlUnitDriverBuilder

Specify whether JavaScript should be enabled.

Default is true.

mockMvcSetup

open static fun mockMvcSetup(mockMvc: MockMvc): MockMvcHtmlUnitDriverBuilder

Create a new MockMvcHtmlUnitDriverBuilder based on the supplied MockMvc instance.

webAppContextSetup

open static fun webAppContextSetup(context: WebApplicationContext): MockMvcHtmlUnitDriverBuilder

Create a new MockMvcHtmlUnitDriverBuilder based on the supplied WebApplicationContext.

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

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

withDelegate

open fun withDelegate(driver: WebConnectionHtmlUnitDriver): MockMvcHtmlUnitDriverBuilder

Supply the WebConnectionHtmlUnitDriver that the driver 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".