public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends MockMvcBuilderSupport implements MockMvcBuilder
MockMvcBuilder
with methods for
configuring filters, default request properties, and global expectations and
result actions.Modifier | Constructor and Description |
---|---|
protected |
DefaultMockMvcBuilder(WebApplicationContext webAppContext)
Protected constructor.
|
Modifier and Type | Method and Description |
---|---|
<T extends Self> |
addFilter(Filter filter,
String... urlPatterns)
Add a filter mapped to a specific set of patterns.
|
<T extends Self> |
addFilters(Filter... filters)
Add filters mapped to any request (i.e.
|
<T extends Self> |
alwaysDo(ResultHandler resultHandler)
Define a global action that should always be applied to every
response.
|
<T extends Self> |
alwaysExpect(ResultMatcher resultMatcher)
Define a global expectation that should always be applied to
every response.
|
MockMvc |
build()
Build a
MockMvc instance. |
<T extends Self> |
defaultRequest(RequestBuilder requestBuilder)
Define default request properties that should be merged into all
performed requests.
|
<T extends Self> |
dispatchOptions(boolean dispatchOptions)
Should the
DispatcherServlet dispatch OPTIONS request to controllers. |
protected void |
initWebAppContext(WebApplicationContext webAppContext)
|
createMockMvc
protected DefaultMockMvcBuilder(WebApplicationContext webAppContext)
public final <T extends Self> T addFilters(Filter... filters)
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.
filters
- the filters to addpublic final <T extends Self> T addFilter(Filter filter, String... urlPatterns)
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.
filter
- the filter to addurlPatterns
- URL patterns to map to; if empty, "/*" is used by defaultpublic final <T extends Self> T defaultRequest(RequestBuilder requestBuilder)
Properties specified at the time of performing a request override the default properties defined here.
requestBuilder
- a RequestBuilder; see static factory methods in
MockMvcRequestBuilders
.public final <T extends Self> T alwaysExpect(ResultMatcher resultMatcher)
"application/json"
, etc.resultMatcher
- a ResultMatcher; see static factory methods in
MockMvcResultMatchers
public final <T extends Self> T alwaysDo(ResultHandler resultHandler)
System.out
.resultHandler
- a ResultHandler; see static factory methods in
MockMvcResultHandlers
public final <T extends Self> T dispatchOptions(boolean dispatchOptions)
DispatcherServlet
dispatch OPTIONS request to controllers.dispatchOptions
- FrameworkServlet.setDispatchOptionsRequest(boolean)
public final MockMvc build()
MockMvc
instance.build
in interface MockMvcBuilder
protected void initWebAppContext(WebApplicationContext webAppContext)