public abstract class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>>
extends java.lang.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 and Type | Field and Description |
---|---|
private boolean |
alwaysUseMockMvc |
private java.lang.String |
contextPath |
private MockMvc |
mockMvc |
private java.util.List<WebRequestMatcher> |
requestMatchers |
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(java.lang.String contextPath)
Set the context path to use.
|
protected WebConnection |
createConnection(WebClient webClient)
Create a new
WebConnection that will use a MockMvc
instance if one of the specified WebRequestMatcher instances
matches. |
private WebConnection |
createConnection(WebClient webClient,
WebConnection defaultConnection) |
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(java.lang.String... hosts)
Add additional
WebRequestMatcher instances that return true
if a supplied host matches — for example, "example.com" or
"example.com:8080" . |
private final MockMvc mockMvc
private final java.util.List<WebRequestMatcher> requestMatchers
private java.lang.String contextPath
private boolean alwaysUseMockMvc
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(java.lang.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(java.lang.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 WebConnection createConnection(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...)
private WebConnection createConnection(WebClient webClient, WebConnection defaultConnection)