public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneMockMvcBuilder>
@Controller
registrations thus allowing
full control over the instantiation and the initialization of controllers and
their dependencies similar to plain unit tests, and also making it possible
to test one controller at a time.
This builder creates the minimum infrastructure required by the
DispatcherServlet
to serve requests with annotated controllers and
also provides methods to customize it. The resulting configuration and
customizations possible are equivalent to using the MVC Java config except
using builder style methods.
To configure view resolution, either select a "fixed" view to use for every
performed request (see setSingleView(View)
) or provide a list of
ViewResolver
's, see setViewResolvers(ViewResolver...)
.
Modifier | Constructor and Description |
---|---|
protected |
StandaloneMockMvcBuilder(Object... controllers)
Protected constructor.
|
Modifier and Type | Method and Description |
---|---|
StandaloneMockMvcBuilder |
addInterceptors(HandlerInterceptor... interceptors)
Add interceptors mapped to all incoming requests.
|
StandaloneMockMvcBuilder |
addMappedInterceptors(String[] pathPatterns,
HandlerInterceptor... interceptors)
Add interceptors mapped to a set of path patterns.
|
StandaloneMockMvcBuilder |
addPlaceHolderValue(String name,
String value)
In a standalone setup there is no support for placeholder values embedded in
request mappings.
|
protected WebApplicationContext |
initWebAppContext()
A method to obtain the WebApplicationContext to be passed to the DispatcherServlet.
|
StandaloneMockMvcBuilder |
setAsyncRequestTimeout(long timeout)
Specify the timeout value for async execution.
|
protected StandaloneMockMvcBuilder |
setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)
Set a ContentNegotiationManager.
|
StandaloneMockMvcBuilder |
setConversionService(FormattingConversionService conversionService)
Provide a conversion service with custom formatters and converters.
|
StandaloneMockMvcBuilder |
setCustomArgumentResolvers(HandlerMethodArgumentResolver... argumentResolvers)
Provide custom resolvers for controller method arguments.
|
StandaloneMockMvcBuilder |
setCustomReturnValueHandlers(HandlerMethodReturnValueHandler... handlers)
Provide custom handlers for controller method return values.
|
StandaloneMockMvcBuilder |
setFlashMapManager(FlashMapManager flashMapManager)
Provide a custom FlashMapManager instance.
|
StandaloneMockMvcBuilder |
setHandlerExceptionResolvers(HandlerExceptionResolver... exceptionResolvers)
Set the HandlerExceptionResolver types to use as an array.
|
StandaloneMockMvcBuilder |
setHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
Set the HandlerExceptionResolver types to use as a list.
|
StandaloneMockMvcBuilder |
setLocaleResolver(LocaleResolver localeResolver)
Provide a LocaleResolver instance.
|
StandaloneMockMvcBuilder |
setMessageConverters(HttpMessageConverter<?>... messageConverters)
Set the message converters to use in argument resolvers and in return value
handlers, which support reading and/or writing to the body of the request
and response.
|
StandaloneMockMvcBuilder |
setRemoveSemicolonContent(boolean removeSemicolonContent)
Set if ";" (semicolon) content should be stripped from the request URI.
|
StandaloneMockMvcBuilder |
setSingleView(View view)
Sets up a single
ViewResolver that always returns the provided
view instance. |
StandaloneMockMvcBuilder |
setUseSuffixPatternMatch(boolean useSuffixPatternMatch)
Whether to use suffix pattern match (".*") when matching patterns to
requests.
|
StandaloneMockMvcBuilder |
setUseTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch)
Whether to match to URLs irrespective of the presence of a trailing slash.
|
StandaloneMockMvcBuilder |
setValidator(Validator validator)
Provide a custom
Validator instead of the one created by default. |
StandaloneMockMvcBuilder |
setViewResolvers(ViewResolver... resolvers)
Set up view resolution with the given
ViewResolver s. |
addFilter, addFilters, alwaysDo, alwaysExpect, build, defaultRequest, dispatchOptions
createMockMvc
protected StandaloneMockMvcBuilder(Object... controllers)
public StandaloneMockMvcBuilder setMessageConverters(HttpMessageConverter<?>... messageConverters)
public StandaloneMockMvcBuilder setValidator(Validator validator)
Validator
instead of the one created by default.
The default implementation used, assuming JSR-303 is on the classpath, is
LocalValidatorFactoryBean
.public StandaloneMockMvcBuilder setConversionService(FormattingConversionService conversionService)
DefaultFormattingConversionService
is used by default.public StandaloneMockMvcBuilder addInterceptors(HandlerInterceptor... interceptors)
public StandaloneMockMvcBuilder addMappedInterceptors(String[] pathPatterns, HandlerInterceptor... interceptors)
protected StandaloneMockMvcBuilder setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)
public StandaloneMockMvcBuilder setAsyncRequestTimeout(long timeout)
timeout
- the timeout value in millisecondspublic StandaloneMockMvcBuilder setCustomArgumentResolvers(HandlerMethodArgumentResolver... argumentResolvers)
public StandaloneMockMvcBuilder setCustomReturnValueHandlers(HandlerMethodReturnValueHandler... handlers)
public StandaloneMockMvcBuilder setHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)
public StandaloneMockMvcBuilder setHandlerExceptionResolvers(HandlerExceptionResolver... exceptionResolvers)
public StandaloneMockMvcBuilder setViewResolvers(ViewResolver... resolvers)
ViewResolver
s.
If not set, an InternalResourceViewResolver
is used by default.public StandaloneMockMvcBuilder setSingleView(View view)
ViewResolver
that always returns the provided
view instance. This is a convenient shortcut if you need to use one
View instance only -- e.g. rendering generated content (JSON, XML, Atom).public StandaloneMockMvcBuilder setLocaleResolver(LocaleResolver localeResolver)
AcceptHeaderLocaleResolver
.public StandaloneMockMvcBuilder setFlashMapManager(FlashMapManager flashMapManager)
SessionFlashMapManager
is used by default.public StandaloneMockMvcBuilder setUseSuffixPatternMatch(boolean useSuffixPatternMatch)
The default value is true
.
public StandaloneMockMvcBuilder setUseTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch)
The default value is true
.
public StandaloneMockMvcBuilder setRemoveSemicolonContent(boolean removeSemicolonContent)
AbstractHandlerMapping.setRemoveSemicolonContent(boolean)
.public StandaloneMockMvcBuilder addPlaceHolderValue(String name, String value)
WebApplicationContext
.protected WebApplicationContext initWebAppContext()
AbstractMockMvcBuilder
AbstractMockMvcBuilder.build()
before the
MockMvc
instance is created.initWebAppContext
in class AbstractMockMvcBuilder<StandaloneMockMvcBuilder>