类 MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>>
- java.lang.Object
- org.springframework.test.web.servlet.htmlunit.MockMvcWebConnectionBuilderSupport<T>
public abstract class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>> extends Object
Support class that simplifies the creation of aWebConnection
that usesMockMvc
and optionally delegates to a realWebConnection
for specific requests.The default is to use
MockMvc
for requests tolocalhost
and otherwise use a realWebConnection
.- 从以下版本开始:
- 4.2
- 作者:
- Rob Winch, Sam Brannen
构造器概要
构造器 限定符 构造器 说明 protected
MockMvcWebConnectionBuilderSupport(MockMvc mockMvc)
Create a new instance using the suppliedMockMvc
instance.protected
MockMvcWebConnectionBuilderSupport(WebApplicationContext context)
Create a new instance using the suppliedWebApplicationContext
.protected
MockMvcWebConnectionBuilderSupport(WebApplicationContext context, MockMvcConfigurer configurer)
Create a new instance using the suppliedWebApplicationContext
andMockMvcConfigurer
.
方法概要
所有方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 T
alwaysUseMockMvc()
Specify thatMockMvc
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 newWebConnection
that will use aMockMvc
instance if one of the specifiedWebRequestMatcher
instances matches.protected com.gargoylesoftware.htmlunit.WebConnection
createConnection(com.gargoylesoftware.htmlunit.WebConnection defaultConnection)
已过时。UsecreateConnection(WebClient)
insteadT
useMockMvc(WebRequestMatcher... matchers)
Add additionalWebRequestMatcher
instances that will ensure thatMockMvc
is used to process the request, if such a matcher matches against the web request.T
useMockMvcForHosts(String... hosts)
Add additionalWebRequestMatcher
instances that returntrue
if a supplied host matches — for example,"example.com"
or"example.com:8080"
.
构造器详细资料
MockMvcWebConnectionBuilderSupport
protected MockMvcWebConnectionBuilderSupport(MockMvc mockMvc)
Create a new instance using the suppliedMockMvc
instance.- 参数:
mockMvc
- theMockMvc
instance to use; nevernull
MockMvcWebConnectionBuilderSupport
protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context)
Create a new instance using the suppliedWebApplicationContext
.- 参数:
context
- theWebApplicationContext
to create aMockMvc
instance from; nevernull
MockMvcWebConnectionBuilderSupport
protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context, MockMvcConfigurer configurer)
Create a new instance using the suppliedWebApplicationContext
andMockMvcConfigurer
.- 参数:
context
- theWebApplicationContext
to create aMockMvc
instance from; nevernull
configurer
- the MockMvcConfigurer to apply; nevernull
方法详细资料
contextPath
public T contextPath(String contextPath)
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
""
.- 参数:
contextPath
- the context path to use- 返回:
- this builder for further customization
alwaysUseMockMvc
public T alwaysUseMockMvc()
Specify thatMockMvc
should always be used regardless of what the request looks like.- 返回:
- this builder for further customization
useMockMvc
public T useMockMvc(WebRequestMatcher... matchers)
Add additionalWebRequestMatcher
instances that will ensure thatMockMvc
is used to process the request, if such a matcher matches against the web request.- 参数:
matchers
- additionalWebRequestMatcher
instances- 返回:
- this builder for further customization
useMockMvcForHosts
public T useMockMvcForHosts(String... hosts)
Add additionalWebRequestMatcher
instances that returntrue
if a supplied host matches — for example,"example.com"
or"example.com:8080"
.- 参数:
hosts
- additional hosts that ensureMockMvc
gets invoked- 返回:
- this builder for further customization
createConnection
@Deprecated protected final com.gargoylesoftware.htmlunit.WebConnection createConnection(com.gargoylesoftware.htmlunit.WebConnection defaultConnection)
已过时。UsecreateConnection(WebClient)
insteadCreate a newWebConnection
that will use aMockMvc
instance if one of the specifiedWebRequestMatcher
instances matches.- 参数:
defaultConnection
- the default WebConnection to use if none of the specifiedWebRequestMatcher
instances matches; nevernull
- 返回:
- a new
WebConnection
that will use aMockMvc
instance if one of the specifiedWebRequestMatcher
matches - 另请参阅:
alwaysUseMockMvc()
,useMockMvc(WebRequestMatcher...)
,useMockMvcForHosts(String...)
createConnection
protected final com.gargoylesoftware.htmlunit.WebConnection createConnection(com.gargoylesoftware.htmlunit.WebClient webClient)
Create a newWebConnection
that will use aMockMvc
instance if one of the specifiedWebRequestMatcher
instances matches.- 参数:
webClient
- the WebClient to use if none of the specifiedWebRequestMatcher
instances matches (nevernull
)- 返回:
- a new
WebConnection
that will use aMockMvc
instance if one of the specifiedWebRequestMatcher
matches - 从以下版本开始:
- 4.3
- 另请参阅:
alwaysUseMockMvc()
,useMockMvc(WebRequestMatcher...)
,useMockMvcForHosts(String...)