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

MockMvcWebConnectionBuilderSupport

abstract class MockMvcWebConnectionBuilderSupport<T : MockMvcWebConnectionBuilderSupport<T>>

Support class that simplifies the creation of a WebConnection that uses MockMvc and optionally delegates to a real WebConnection for specific requests.

The default is to use MockMvc for requests to localhost and otherwise use a real WebConnection.

Author
Rob Winch

Author
Sam Brannen

Since
4.2

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".

Inheritors

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).

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.