Interface ConfigurableMockMvcBuilder<B extends ConfigurableMockMvcBuilder<B>>
- Type Parameters:
B
- a self reference to the builder type
- All Superinterfaces:
MockMvcBuilder
- All Known Implementing Classes:
AbstractMockMvcBuilder
,DefaultMockMvcBuilder
,RouterFunctionMockMvcBuilder
,StandaloneMockMvcBuilder
MockMvc
.- Since:
- 4.1
- Author:
- Rossen Stoyanchev, Sam Brannen
-
Method Summary
Modifier and TypeMethodDescription<T extends B>
TA more advanced variant ofdispatchOptions(boolean)
that allows customizing anyDispatcherServlet
property.<T extends B>
TAdd a filter mapped to specific patterns.<T extends B>
TaddFilter
(Filter filter, String filterName, Map<String, String> initParams, EnumSet<DispatcherType> dispatcherTypes, String... urlPatterns) Add a filter that will be initialized viaFilter.init(FilterConfig)
with the given init parameters, and will also apply only to requests that match the given dispatcher types and URL patterns.<T extends B>
TaddFilters
(Filter... filters) Add filters mapped to all requests.<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 aMockMvcConfigurer
that automates MockMvc setup and configures it for some specific purpose (e.g.<T extends B>
TdefaultRequest
(RequestBuilder requestBuilder) Define default request properties that should be merged into all performed requests.default <T extends B>
TdefaultResponseCharacterEncoding
(Charset defaultResponseCharacterEncoding) Define the default character encoding to be applied to every response.<T extends B>
TdispatchOptions
(boolean dispatchOptions) Whether to enable the DispatcherServlet propertydispatchOptionsRequest
which allows processing of HTTP OPTIONS requests.Methods inherited from interface org.springframework.test.web.servlet.MockMvcBuilder
build
-
Method Details
-
addFilters
Add filters mapped to all requests. Filters are invoked in the same order.Note: if you need the filter to be initialized with
Filter.init(FilterConfig)
, please useaddFilter(Filter, String, Map, EnumSet, String...)
instead.- Parameters:
filters
- the filters to add
-
addFilter
Add a filter mapped to specific patterns.Note: if you need the filter to be initialized with
Filter.init(FilterConfig)
, please useaddFilter(Filter, String, Map, EnumSet, String...)
instead.- Parameters:
filter
- the filter to addurlPatterns
- the URL patterns to map to; if empty, matches all requests
-
addFilter
<T extends B> T addFilter(Filter filter, @Nullable String filterName, Map<String, String> initParams, EnumSet<DispatcherType> dispatcherTypes, String... urlPatterns) Add a filter that will be initialized viaFilter.init(FilterConfig)
with the given init parameters, and will also apply only to requests that match the given dispatcher types and URL patterns.- Parameters:
filter
- the filter to addfilterName
- the name to use for the filter; ifnull
, thenMockFilterConfig
is created without a name, which defaults to an empty String for the nameinitParams
- the init parameters to initialize the filter withdispatcherTypes
- dispatcher types the filter applies tourlPatterns
- the URL patterns to map to; if empty, matches all requests- Since:
- 6.1
- See Also:
-
defaultRequest
Define 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.
- Parameters:
requestBuilder
- a RequestBuilder; see static factory methods inMockMvcRequestBuilders
-
defaultResponseCharacterEncoding
Define the default character encoding to be applied to every response.The default implementation of this method throws an
UnsupportedOperationException
. Concrete implementations are therefore encouraged to override this method.- Parameters:
defaultResponseCharacterEncoding
- the default response character encoding- Since:
- 5.3.10
-
alwaysExpect
Define a global expectation that should always be applied to every response. For example, status code 200 (OK), content type"application/json"
, etc.- Parameters:
resultMatcher
- a ResultMatcher; see static factory methods inMockMvcResultMatchers
-
alwaysDo
Define 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
.- Parameters:
resultHandler
- a ResultHandler; see static factory methods inMockMvcResultHandlers
-
dispatchOptions
Whether to enable the DispatcherServlet propertydispatchOptionsRequest
which allows processing of HTTP OPTIONS requests. -
addDispatcherServletCustomizer
A more advanced variant ofdispatchOptions(boolean)
that allows customizing anyDispatcherServlet
property.- Since:
- 5.3
-
apply
Add aMockMvcConfigurer
that automates MockMvc setup and configures it for some specific purpose (e.g. security).There is a built-in
SharedHttpSessionConfigurer
that 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.- See Also:
-