类 AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- java.lang.Object
- org.springframework.test.web.servlet.MockMvcBuilderSupport
- org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder<B>
- 类型参数:
B- a self reference to the builder type
- 所有已实现的接口:
MockMvcBuilder,ConfigurableMockMvcBuilder<B>
public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>> extends MockMvcBuilderSupport implements ConfigurableMockMvcBuilder<B>
Abstract implementation ofMockMvcBuilderwith common methods for configuring filters, default request properties, global expectations and global result actions.Subclasses can use different strategies to prepare the Spring
WebApplicationContextthat will be passed to theDispatcherServlet.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Stephane Nicoll
构造器概要
构造器 构造器 说明 AbstractMockMvcBuilder()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 <T extends B>
TaddDispatcherServletCustomizer(DispatcherServletCustomizer customizer)<T extends B>
TaddFilter(Filter filter, String... urlPatterns)Add a filter mapped to a specific set of patterns.<T extends B>
TaddFilters(Filter... filters)Add filters mapped to any request (i.e. "/*").<T extends B>
TalwaysDo(ResultHandler resultHandler)Define a global action that should always be applied to every response.<T extends B>
TalwaysExpect(ResultMatcher resultMatcher)Define a global expectation that should always be applied to every response.<T extends B>
Tapply(MockMvcConfigurer configurer)Add aMockMvcConfigurerthat automates MockMvc setup and configures it for some specific purpose (e.g. security).MockMvcbuild()Build aMockMvcinstance.<T extends B>
TdefaultRequest(RequestBuilder requestBuilder)Define default request properties that should be merged into all performed requests.<T extends B>
TdispatchOptions(boolean dispatchOptions)Whether to enable the DispatcherServlet propertydispatchOptionsRequestwhich allows processing of HTTP OPTIONS requests.protected abstract WebApplicationContextinitWebAppContext()A method to obtain theWebApplicationContextto be passed to theDispatcherServlet.protected <T extends B>
Tself()从类继承的方法 org.springframework.test.web.servlet.MockMvcBuilderSupport
createMockMvc
构造器详细资料
AbstractMockMvcBuilder
public AbstractMockMvcBuilder()
方法详细资料
addFilters
public final <T extends B> T addFilters(Filter... filters)
从接口复制的说明:ConfigurableMockMvcBuilderAdd filters mapped to any request (i.e. "/*"). For example:mockMvcBuilder.addFilters(springSecurityFilterChain);
is the equivalent of the following web.xml configuration:
<filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>Filters will be invoked in the order in which they are provided.
- 指定者:
addFilters在接口中ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>- 参数:
filters- the filters to add
addFilter
public final <T extends B> T addFilter(Filter filter, String... urlPatterns)
从接口复制的说明:ConfigurableMockMvcBuilderAdd a filter mapped to a specific set of patterns. For example:mockMvcBuilder.addFilters(myResourceFilter, "/resources/*");
is the equivalent of:
<filter-mapping> <filter-name>myResourceFilter</filter-name> <url-pattern>/resources/*</url-pattern> </filter-mapping>Filters will be invoked in the order in which they are provided.
- 指定者:
addFilter在接口中ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>- 参数:
filter- the filter to addurlPatterns- the URL patterns to map to; if empty, "/*" is used by default
defaultRequest
public final <T extends B> T defaultRequest(RequestBuilder requestBuilder)
从接口复制的说明:ConfigurableMockMvcBuilderDefine default request properties that should be merged into all performed requests. In effect this provides a mechanism for defining common initialization for all requests such as the content type, request parameters, session attributes, and any other request property.Properties specified at the time of performing a request override the default properties defined here.
- 指定者:
defaultRequest在接口中ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>- 参数:
requestBuilder- a RequestBuilder; see static factory methods inMockMvcRequestBuilders
alwaysExpect
public final <T extends B> T alwaysExpect(ResultMatcher resultMatcher)
从接口复制的说明:ConfigurableMockMvcBuilderDefine a global expectation that should always be applied to every response. For example, status code 200 (OK), content type"application/json", etc.- 指定者:
alwaysExpect在接口中ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>- 参数:
resultMatcher- a ResultMatcher; see static factory methods inMockMvcResultMatchers
alwaysDo
public final <T extends B> T alwaysDo(ResultHandler resultHandler)
从接口复制的说明:ConfigurableMockMvcBuilderDefine a global action that should always be applied to every response. For example, writing detailed information about the performed request and resulting response toSystem.out.- 指定者:
alwaysDo在接口中ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>- 参数:
resultHandler- a ResultHandler; see static factory methods inMockMvcResultHandlers
addDispatcherServletCustomizer
public final <T extends B> T addDispatcherServletCustomizer(DispatcherServletCustomizer customizer)
dispatchOptions
public final <T extends B> T dispatchOptions(boolean dispatchOptions)
从接口复制的说明:ConfigurableMockMvcBuilderWhether to enable the DispatcherServlet propertydispatchOptionsRequestwhich allows processing of HTTP OPTIONS requests.- 指定者:
dispatchOptions在接口中ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
apply
public final <T extends B> T apply(MockMvcConfigurer configurer)
从接口复制的说明:ConfigurableMockMvcBuilderAdd aMockMvcConfigurerthat automates MockMvc setup and configures it for some specific purpose (e.g. security).There is a built-in
SharedHttpSessionConfigurerthat can be used to re-use the HTTP session across requests. 3rd party frameworks like Spring Security also use this mechanism to provide configuration shortcuts.- 指定者:
apply在接口中ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>- 另请参阅:
SharedHttpSessionConfigurer
build
public final MockMvc build()
Build aMockMvcinstance.- 指定者:
build在接口中MockMvcBuilder
initWebAppContext
protected abstract WebApplicationContext initWebAppContext()