Class RouterFunctionMockMvcBuilder
- All Implemented Interfaces:
MockMvcBuilder
,ConfigurableMockMvcBuilder<RouterFunctionMockMvcBuilder>
MockMvcBuilder
that accepts RouterFunction
registrations
thus allowing full control over the instantiation and initialization of
router functions and their dependencies similar to plain unit tests, and also
making it possible to test one function at a time.
This builder creates the minimum infrastructure required by the
DispatcherServlet
to serve requests with router functions and
also provides methods for customization. The resulting configuration and
customization options are equivalent to using MVC Java config except
using builder style methods.
To configure view resolution, either select a "fixed" view to use for every
request performed (see setSingleView(View)
) or provide a list of
ViewResolver
s (see setViewResolvers(ViewResolver...)
).
- Since:
- 6.2
- Author:
- Arjen Poutsma
-
Constructor Summary
ModifierConstructorDescriptionprotected
RouterFunctionMockMvcBuilder
(RouterFunction<?>... routerFunctions) -
Method Summary
Modifier and TypeMethodDescriptionaddInterceptors
(HandlerInterceptor... interceptors) Add interceptors mapped to all incoming requests.addMappedInterceptors
(String[] pathPatterns, HandlerInterceptor... interceptors) Add interceptors mapped to a set of path patterns.protected WebApplicationContext
A method to obtain theWebApplicationContext
to be passed to theDispatcherServlet
.setAsyncRequestTimeout
(long timeout) Specify the timeout value for async execution.Configure the factory to create a customRequestMappingHandlerMapping
.setHandlerExceptionResolvers
(List<HandlerExceptionResolver> exceptionResolvers) Set the HandlerExceptionResolver types to use as a list.setHandlerExceptionResolvers
(HandlerExceptionResolver... exceptionResolvers) Set the HandlerExceptionResolver types to use as an array.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.setPatternParser
(PathPatternParser parser) Enable URL path matching with parsedPathPatterns
instead of String pattern matching with aPathMatcher
.setSingleView
(View view) Set up a singleViewResolver
that always returns the provided view instance.setViewResolvers
(ViewResolver... resolvers) Set up view resolution with the givenViewResolvers
.Methods inherited from class org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder
addDispatcherServletCustomizer, addFilter, addFilter, addFilters, alwaysDo, alwaysExpect, apply, build, defaultRequest, defaultResponseCharacterEncoding, dispatchOptions, self
Methods inherited from class org.springframework.test.web.servlet.MockMvcBuilderSupport
createMockMvc, createMockMvc
-
Constructor Details
-
RouterFunctionMockMvcBuilder
-
-
Method Details
-
setMessageConverters
public RouterFunctionMockMvcBuilder 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. If no message converters are added to the list, a default list of converters is added instead. -
addInterceptors
Add interceptors mapped to all incoming requests. -
addMappedInterceptors
public RouterFunctionMockMvcBuilder addMappedInterceptors(@Nullable String[] pathPatterns, HandlerInterceptor... interceptors) Add interceptors mapped to a set of path patterns. -
setHandlerExceptionResolvers
public RouterFunctionMockMvcBuilder setHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) Set the HandlerExceptionResolver types to use as a list. -
setHandlerExceptionResolvers
public RouterFunctionMockMvcBuilder setHandlerExceptionResolvers(HandlerExceptionResolver... exceptionResolvers) Set the HandlerExceptionResolver types to use as an array. -
setCustomHandlerMapping
public RouterFunctionMockMvcBuilder setCustomHandlerMapping(Supplier<RouterFunctionMapping> factory) Configure the factory to create a customRequestMappingHandlerMapping
.- Parameters:
factory
- the factory
-
setViewResolvers
Set up view resolution with the givenViewResolvers
.If not set, an
InternalResourceViewResolver
is used by default. -
setSingleView
Set up a singleViewResolver
that always returns the provided view instance.This is a convenient shortcut if you need to use one
View
instance only — for example, rendering generated content (JSON, XML, Atom). -
setAsyncRequestTimeout
Specify the timeout value for async execution.In Spring MVC Test, this value is used to determine how long to wait for async execution to complete so that a test can verify the results synchronously.
- Parameters:
timeout
- the timeout value in milliseconds
-
setPatternParser
Enable URL path matching with parsedPathPatterns
instead of String pattern matching with aPathMatcher
.- Parameters:
parser
- the parser to use
-
initWebAppContext
Description copied from class:AbstractMockMvcBuilder
A method to obtain theWebApplicationContext
to be passed to theDispatcherServlet
. Invoked fromAbstractMockMvcBuilder.build()
before theMockMvc
instance is created.- Specified by:
initWebAppContext
in classAbstractMockMvcBuilder<RouterFunctionMockMvcBuilder>
-