Class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- Type Parameters:
- B- a self reference to the builder type
- All Implemented Interfaces:
- MockMvcBuilder,- ConfigurableMockMvcBuilder<B>
- Direct Known Subclasses:
- DefaultMockMvcBuilder,- RouterFunctionMockMvcBuilder,- StandaloneMockMvcBuilder
MockMvcBuilder with common methods for
 configuring filters, default request properties, global expectations and
 global result actions.
 Subclasses can use different strategies to prepare the Spring
 WebApplicationContext that will be passed to the
 DispatcherServlet.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev, Stephane Nicoll, Sam Brannen
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionfinal <T extends B>
 TA more advanced variant ofConfigurableMockMvcBuilder.dispatchOptions(boolean)that allows customizing anyDispatcherServletproperty.final <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.final <T extends B>
 TaddFilters(Filter... filters) Add filters mapped to all requests.final <T extends B>
 TalwaysDo(ResultHandler resultHandler) Define a global action that should always be applied to every response.final <T extends B>
 TalwaysExpect(ResultMatcher resultMatcher) Define a global expectation that should always be applied to every response.final <T extends B>
 Tapply(MockMvcConfigurer configurer) Add aMockMvcConfigurerthat automates MockMvc setup and configures it for some specific purpose (e.g.final MockMvcbuild()Build aMockMvcinstance.final <T extends B>
 TdefaultRequest(RequestBuilder requestBuilder) Define default request properties that should be merged into all performed requests.final <T extends B>
 TdefaultResponseCharacterEncoding(Charset defaultResponseCharacterEncoding) Define the default character encoding to be applied to every response.final <T extends B>
 TdispatchOptions(boolean dispatchOptions) Whether to enable the DispatcherServlet propertydispatchOptionsRequestwhich allows processing of HTTP OPTIONS requests.protected abstract WebApplicationContextA method to obtain theWebApplicationContextto be passed to theDispatcherServlet.protected <T extends B>
 Tself()Methods inherited from class org.springframework.test.web.servlet.MockMvcBuilderSupportcreateMockMvc, createMockMvc
- 
Constructor Details- 
AbstractMockMvcBuilderpublic AbstractMockMvcBuilder()
 
- 
- 
Method Details- 
addFiltersDescription copied from interface:ConfigurableMockMvcBuilderAdd 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 useConfigurableMockMvcBuilder.addFilter(Filter, String, Map, EnumSet, String...)instead.- Specified by:
- addFiltersin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- Parameters:
- filters- the filters to add
 
- 
addFilterDescription copied from interface:ConfigurableMockMvcBuilderAdd a filter mapped to specific patterns.Note: if you need the filter to be initialized with Filter.init(FilterConfig), please useConfigurableMockMvcBuilder.addFilter(Filter, String, Map, EnumSet, String...)instead.- Specified by:
- addFilterin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- Parameters:
- filter- the filter to add
- urlPatterns- the URL patterns to map to; if empty, matches all requests
 
- 
addFilterpublic <T extends B> T addFilter(Filter filter, @Nullable String filterName, Map<String, String> initParams, EnumSet<DispatcherType> dispatcherTypes, String... urlPatterns) Description copied from interface:ConfigurableMockMvcBuilderAdd 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.- Specified by:
- addFilterin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- Parameters:
- filter- the filter to add
- filterName- the name to use for the filter; if- null, then- MockFilterConfigis created without a name, which defaults to an empty String for the name
- initParams- the init parameters to initialize the filter with
- dispatcherTypes- dispatcher types the filter applies to
- urlPatterns- the URL patterns to map to; if empty, matches all requests
- See Also:
 
- 
defaultRequestDescription copied from interface: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. - Specified by:
- defaultRequestin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- Parameters:
- requestBuilder- a RequestBuilder; see static factory methods in- MockMvcRequestBuilders
 
- 
defaultResponseCharacterEncodingpublic final <T extends B> T defaultResponseCharacterEncoding(Charset defaultResponseCharacterEncoding) Define the default character encoding to be applied to every response.- Specified by:
- defaultResponseCharacterEncodingin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- Parameters:
- defaultResponseCharacterEncoding- the default response character encoding
- Since:
- 5.3.10
 
- 
alwaysExpectDescription copied from interface:ConfigurableMockMvcBuilderDefine a global expectation that should always be applied to every response. For example, status code 200 (OK), content type"application/json", etc.- Specified by:
- alwaysExpectin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- Parameters:
- resultMatcher- a ResultMatcher; see static factory methods in- MockMvcResultMatchers
 
- 
alwaysDoDescription copied from interface: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.- Specified by:
- alwaysDoin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- Parameters:
- resultHandler- a ResultHandler; see static factory methods in- MockMvcResultHandlers
 
- 
addDispatcherServletCustomizerDescription copied from interface:ConfigurableMockMvcBuilderA more advanced variant ofConfigurableMockMvcBuilder.dispatchOptions(boolean)that allows customizing anyDispatcherServletproperty.- Specified by:
- addDispatcherServletCustomizerin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
 
- 
dispatchOptionsDescription copied from interface:ConfigurableMockMvcBuilderWhether to enable the DispatcherServlet propertydispatchOptionsRequestwhich allows processing of HTTP OPTIONS requests.- Specified by:
- dispatchOptionsin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
 
- 
applyDescription copied from interface: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.- Specified by:
- applyin interface- ConfigurableMockMvcBuilder<B extends AbstractMockMvcBuilder<B>>
- See Also:
 
- 
self
- 
buildBuild aMockMvcinstance.- Specified by:
- buildin interface- MockMvcBuilder
 
- 
initWebAppContext
 
-