public abstract class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>> extends Object
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.
| Modifier | Constructor and Description |
|---|---|
protected |
MockMvcWebConnectionBuilderSupport(MockMvc mockMvc)
Create a new instance using the supplied
MockMvc instance. |
protected |
MockMvcWebConnectionBuilderSupport(org.springframework.web.context.WebApplicationContext context)
Create a new instance using the supplied
WebApplicationContext. |
protected |
MockMvcWebConnectionBuilderSupport(org.springframework.web.context.WebApplicationContext context,
MockMvcConfigurer configurer)
Create a new instance using the supplied
WebApplicationContext
and MockMvcConfigurer. |
| Modifier and Type | Method and Description |
|---|---|
T |
alwaysUseMockMvc()
Specify that
MockMvc should always be used regardless of
what the request looks like. |
T |
contextPath(String contextPath)
Set the context path to use.
|
protected com.gargoylesoftware.htmlunit.WebConnection |
createConnection(com.gargoylesoftware.htmlunit.WebConnection defaultConnection)
Create a new
WebConnection that will use a MockMvc
instance if one of the specified WebRequestMatcher instances
matches. |
T |
useMockMvc(WebRequestMatcher... matchers)
Add additional
WebRequestMatcher instances that will ensure
that MockMvc is used to process the request, if such a matcher
matches against the web request. |
T |
useMockMvcForHosts(String... hosts)
Add additional
WebRequestMatcher instances that return true
if a supplied host matches — for example, "example.com" or
"example.com:8080". |
protected MockMvcWebConnectionBuilderSupport(MockMvc mockMvc)
MockMvc instance.mockMvc - the MockMvc instance to use; never nullprotected MockMvcWebConnectionBuilderSupport(org.springframework.web.context.WebApplicationContext context)
WebApplicationContext.context - the WebApplicationContext to create a MockMvc
instance from; never nullprotected MockMvcWebConnectionBuilderSupport(org.springframework.web.context.WebApplicationContext context,
MockMvcConfigurer configurer)
WebApplicationContext
and MockMvcConfigurer.context - the WebApplicationContext to create a MockMvc
instance from; never nullconfigurer - the MockMvcConfigurer to apply; never nullpublic T contextPath(String contextPath)
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 "".
contextPath - the context path to usepublic T alwaysUseMockMvc()
MockMvc should always be used regardless of
what the request looks like.public T useMockMvc(WebRequestMatcher... matchers)
WebRequestMatcher instances that will ensure
that MockMvc is used to process the request, if such a matcher
matches against the web request.matchers - additional WebRequestMatcher instancespublic T useMockMvcForHosts(String... hosts)
WebRequestMatcher instances that return true
if a supplied host matches — for example, "example.com" or
"example.com:8080".hosts - additional hosts that ensure MockMvc gets invokedprotected final com.gargoylesoftware.htmlunit.WebConnection createConnection(com.gargoylesoftware.htmlunit.WebConnection defaultConnection)
WebConnection that will use a MockMvc
instance if one of the specified WebRequestMatcher instances
matches.defaultConnection - the default WebConnection to use if none of
the specified WebRequestMatcher instances matches; never nullWebConnection that will use a MockMvc
instance if one of the specified WebRequestMatcher matchesalwaysUseMockMvc(),
useMockMvc(WebRequestMatcher...),
useMockMvcForHosts(String...)