T
- a self reference to the builder typepublic 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(WebApplicationContext context)
Create a new instance using the supplied
WebApplicationContext . |
protected |
MockMvcWebConnectionBuilderSupport(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.WebClient webClient)
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 null
protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context)
WebApplicationContext
.context
- the WebApplicationContext
to create a MockMvc
instance from; never null
protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context, MockMvcConfigurer configurer)
WebApplicationContext
and MockMvcConfigurer
.context
- the WebApplicationContext
to create a MockMvc
instance from; never null
configurer
- the MockMvcConfigurer to apply; never null
public 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.WebClient webClient)
WebConnection
that will use a MockMvc
instance if one of the specified WebRequestMatcher
instances
matches.webClient
- the WebClient to use if none of the specified
WebRequestMatcher
instances matches (never null
)WebConnection
that will use a MockMvc
instance if one of the specified WebRequestMatcher
matchesalwaysUseMockMvc()
,
useMockMvc(WebRequestMatcher...)
,
useMockMvcForHosts(String...)