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
 ViewResolvers (see setViewResolvers(ViewResolver...)).
- Since:
- 6.2
- Author:
- Arjen Poutsma
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedRouterFunctionMockMvcBuilder(RouterFunction<?>... routerFunctions) 
- 
Method SummaryModifier and TypeMethodDescriptionaddInterceptors(HandlerInterceptor... interceptors) Add interceptors mapped to all incoming requests.addMappedInterceptors(String @Nullable [] pathPatterns, HandlerInterceptor... interceptors) Add interceptors mapped to a set of path patterns.protected WebApplicationContextA method to obtain theWebApplicationContextto 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.Configure the parser to use forPathPatterns.setSingleView(View view) Set up a singleViewResolverthat 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.AbstractMockMvcBuilderaddDispatcherServletCustomizer, addFilter, addFilter, addFilters, alwaysDo, alwaysExpect, apply, build, defaultRequest, defaultResponseCharacterEncoding, dispatchOptions, selfMethods inherited from class org.springframework.test.web.servlet.MockMvcBuilderSupportcreateMockMvc, createMockMvc
- 
Constructor Details- 
RouterFunctionMockMvcBuilder
 
- 
- 
Method Details- 
setMessageConverterspublic 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.
- 
addInterceptorsAdd interceptors mapped to all incoming requests.
- 
addMappedInterceptorspublic RouterFunctionMockMvcBuilder addMappedInterceptors(String @Nullable [] pathPatterns, HandlerInterceptor... interceptors) Add interceptors mapped to a set of path patterns.
- 
setHandlerExceptionResolverspublic RouterFunctionMockMvcBuilder setHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) Set the HandlerExceptionResolver types to use as a list.
- 
setHandlerExceptionResolverspublic RouterFunctionMockMvcBuilder setHandlerExceptionResolvers(HandlerExceptionResolver... exceptionResolvers) Set the HandlerExceptionResolver types to use as an array.
- 
setCustomHandlerMappingpublic RouterFunctionMockMvcBuilder setCustomHandlerMapping(Supplier<RouterFunctionMapping> factory) Configure the factory to create a customRequestMappingHandlerMapping.- Parameters:
- factory- the factory
 
- 
setViewResolversSet up view resolution with the givenViewResolvers.If not set, an InternalResourceViewResolveris used by default.
- 
setSingleViewSet up a singleViewResolverthat always returns the provided view instance.This is a convenient shortcut if you need to use one Viewinstance only — for example, rendering generated content (JSON, XML, Atom).
- 
setAsyncRequestTimeoutSpecify 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
 
- 
setPatternParserConfigure the parser to use forPathPatterns.By default, this is a default instance of PathPatternParser.- Parameters:
- parser- the parser to use
 
- 
initWebAppContextDescription copied from class:AbstractMockMvcBuilderA method to obtain theWebApplicationContextto be passed to theDispatcherServlet. Invoked fromAbstractMockMvcBuilder.build()before theMockMvcinstance is created.- Specified by:
- initWebAppContextin class- AbstractMockMvcBuilder<RouterFunctionMockMvcBuilder>
 
 
-