类 StandaloneMockMvcBuilder
java.lang.Object
cn.taketoday.test.web.servlet.MockMvcBuilderSupport
cn.taketoday.test.web.servlet.setup.AbstractMockMvcBuilder<StandaloneMockMvcBuilder>
cn.taketoday.test.web.servlet.setup.StandaloneMockMvcBuilder
A
MockMvcBuilder that accepts @Controller registrations
thus allowing full control over the instantiation and 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 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...)).
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Harry Yang
-
嵌套类概要
嵌套类修饰符和类型类说明private classUsing the MVC Java configuration as the starting point for the "standalone" setup.private static classAViewResolverthat always returns same View.(专用程序包) static class -
字段概要
字段修饰符和类型字段说明private Longprivate cn.taketoday.web.accept.ContentNegotiationManagerprivate cn.taketoday.format.support.FormattingConversionServiceprivate List<cn.taketoday.web.bind.resolver.ParameterResolvingStrategy>private List<cn.taketoday.web.ReturnValueHandler>private cn.taketoday.web.view.RedirectModelManagerprivate List<cn.taketoday.web.HandlerExceptionHandler>private Supplier<cn.taketoday.web.handler.method.RequestMappingHandlerMapping>private cn.taketoday.web.LocaleResolverprivate final List<cn.taketoday.web.handler.MappedInterceptor>private List<cn.taketoday.http.converter.HttpMessageConverter<?>>private cn.taketoday.web.bind.resolver.ParameterResolvingRegistryprivate cn.taketoday.web.view.RedirectModelManagerprivate cn.taketoday.web.handler.ReturnValueHandlerManagerprivate booleanprivate cn.taketoday.validation.Validatorprivate List<cn.taketoday.web.view.ViewResolver> -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明addInterceptors(cn.taketoday.web.HandlerInterceptor... interceptors) Add interceptors mapped to all incoming requests.addMappedInterceptors(String[] pathPatterns, cn.taketoday.web.HandlerInterceptor... interceptors) Add interceptors mapped to a set of path patterns.addPlaceholderValue(String name, Object value) In a standalone setup there is no support for placeholder values embedded in request mappings.extendMvcSingletons(jakarta.servlet.ServletContext servletContext) This method could be used from a subclass to register additional Infra MVC infrastructure such as additionalHandlerMapping,HandlerAdapter, and others.protected cn.taketoday.web.servlet.WebApplicationContextA method to obtain theWebApplicationContextto be passed to theDispatcherServlet.instantiateIfNecessary(Object[] specified) private voidsetAsyncRequestTimeout(long timeout) Specify the timeout value for async execution.setContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager manager) Set a ContentNegotiationManager.setControllerAdvice(Object... controllerAdvice) Register one or moreControllerAdviceinstances to be used in tests (specifiedClasswill be turned into instance).setConversionService(cn.taketoday.format.support.FormattingConversionService conversionService) Provide a conversion service with custom formatters and converters.setCustomArgumentResolvers(cn.taketoday.web.bind.resolver.ParameterResolvingStrategy... argumentResolvers) Provide custom resolvers for controller method arguments.setCustomHandlerMapping(Supplier<cn.taketoday.web.handler.method.RequestMappingHandlerMapping> factory) Configure factory to create a customRequestMappingHandlerMapping.setCustomReturnValueHandlers(cn.taketoday.web.handler.result.HandlerMethodReturnValueHandler... handlers) Provide custom handlers for controller method return values.setFlashMapManager(cn.taketoday.web.view.RedirectModelManager flashMapManager) Provide a custom FlashMapManager instance.setHandlerExceptionHandlers(cn.taketoday.web.HandlerExceptionHandler... exceptionResolvers) Set the HandlerExceptionHandler types to use as an array.setHandlerExceptionHandlers(List<cn.taketoday.web.HandlerExceptionHandler> exceptionResolvers) Set the HandlerExceptionHandler types to use as a list.setLocaleResolver(cn.taketoday.web.LocaleResolver localeResolver) Provide a LocaleResolver instance.setMessageConverters(cn.taketoday.http.converter.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.setParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry parameterResolvingRegistry) setRedirectModelManager(cn.taketoday.web.view.RedirectModelManager redirectModelManager) setReturnValueHandlerManager(cn.taketoday.web.handler.ReturnValueHandlerManager returnValueHandlerManager) setSingleView(cn.taketoday.web.view.View view) Sets up a singleViewResolverthat always returns the provided view instance.setUseTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch) Whether to match to URLs irrespective of the presence of a trailing slash.setValidator(cn.taketoday.validation.Validator validator) Provide a customValidatorinstead of the one created by default.setViewResolvers(cn.taketoday.web.view.ViewResolver... resolvers) Set up view resolution with the givenViewResolvers.从类继承的方法 cn.taketoday.test.web.servlet.setup.AbstractMockMvcBuilder
addDispatcherServletCustomizer, addFilter, addFilter, addFilters, alwaysDo, alwaysExpect, apply, build, defaultRequest, defaultResponseCharacterEncoding, self从类继承的方法 cn.taketoday.test.web.servlet.MockMvcBuilderSupport
createMockMvc, createMockMvc从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.test.web.servlet.MockMvcBuilder
perform
-
字段详细资料
-
controllers
-
controllerAdvice
-
messageConverters
-
customArgumentResolvers
-
customReturnValueHandlers
-
mappedInterceptors
-
validator
@Nullable private cn.taketoday.validation.Validator validator -
contentNegotiationManager
@Nullable private cn.taketoday.web.accept.ContentNegotiationManager contentNegotiationManager -
conversionService
@Nullable private cn.taketoday.format.support.FormattingConversionService conversionService -
handlerExceptionHandlers
-
asyncRequestTimeout
-
viewResolvers
-
localeResolver
@Nullable private cn.taketoday.web.LocaleResolver localeResolver -
flashMapManager
@Nullable private cn.taketoday.web.view.RedirectModelManager flashMapManager -
useTrailingSlashPatternMatch
private boolean useTrailingSlashPatternMatch -
placeholderValues
-
handlerMappingFactory
private Supplier<cn.taketoday.web.handler.method.RequestMappingHandlerMapping> handlerMappingFactory -
redirectModelManager
@Nullable private cn.taketoday.web.view.RedirectModelManager redirectModelManager -
returnValueHandlerManager
@Nullable private cn.taketoday.web.handler.ReturnValueHandlerManager returnValueHandlerManager -
parameterResolvingRegistry
@Nullable private cn.taketoday.web.bind.resolver.ParameterResolvingRegistry parameterResolvingRegistry
-
-
构造器详细资料
-
StandaloneMockMvcBuilder
Protected constructor. Not intended for direct instantiation.
-
-
方法详细资料
-
instantiateIfNecessary
-
setControllerAdvice
Register one or moreControllerAdviceinstances to be used in tests (specifiedClasswill be turned into instance).Normally
@ControllerAdviceare auto-detected as long as they're declared as Infra beans. However since the standalone setup does not load any Infra config, they need to be registered explicitly here instead much like controllers. -
setMessageConverters
public StandaloneMockMvcBuilder setMessageConverters(cn.taketoday.http.converter.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. -
setValidator
Provide a customValidatorinstead of the one created by default. The default implementation used, assuming JSR-303 is on the classpath, isLocalValidatorFactoryBean. -
setConversionService
public StandaloneMockMvcBuilder setConversionService(cn.taketoday.format.support.FormattingConversionService conversionService) Provide a conversion service with custom formatters and converters. If not set, aDefaultFormattingConversionServiceis used by default. -
addInterceptors
public StandaloneMockMvcBuilder addInterceptors(cn.taketoday.web.HandlerInterceptor... interceptors) Add interceptors mapped to all incoming requests. -
addMappedInterceptors
public StandaloneMockMvcBuilder addMappedInterceptors(@Nullable String[] pathPatterns, cn.taketoday.web.HandlerInterceptor... interceptors) Add interceptors mapped to a set of path patterns. -
setContentNegotiationManager
public StandaloneMockMvcBuilder setContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager manager) Set a ContentNegotiationManager. -
setAsyncRequestTimeout
Specify the timeout value for async execution. In Web MVC Test, this value is used to determine how to long to wait for async execution to complete so that a test can verify the results synchronously.- 参数:
timeout- the timeout value in milliseconds
-
setCustomArgumentResolvers
public StandaloneMockMvcBuilder setCustomArgumentResolvers(cn.taketoday.web.bind.resolver.ParameterResolvingStrategy... argumentResolvers) Provide custom resolvers for controller method arguments. -
setCustomReturnValueHandlers
public StandaloneMockMvcBuilder setCustomReturnValueHandlers(cn.taketoday.web.handler.result.HandlerMethodReturnValueHandler... handlers) Provide custom handlers for controller method return values. -
setHandlerExceptionHandlers
public StandaloneMockMvcBuilder setHandlerExceptionHandlers(List<cn.taketoday.web.HandlerExceptionHandler> exceptionResolvers) Set the HandlerExceptionHandler types to use as a list. -
setHandlerExceptionHandlers
public StandaloneMockMvcBuilder setHandlerExceptionHandlers(cn.taketoday.web.HandlerExceptionHandler... exceptionResolvers) Set the HandlerExceptionHandler types to use as an array. -
setViewResolvers
Set up view resolution with the givenViewResolvers. If not set, anInternalResourceViewResolveris used by default. -
setSingleView
Sets up a singleViewResolverthat 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). -
setLocaleResolver
Provide a LocaleResolver instance. If not provided, the default one used isAcceptHeaderLocaleResolver. -
setFlashMapManager
public StandaloneMockMvcBuilder setFlashMapManager(cn.taketoday.web.view.RedirectModelManager flashMapManager) Provide a custom FlashMapManager instance. If not provided,SessionFlashMapManageris used by default. -
setUseTrailingSlashPatternMatch
public StandaloneMockMvcBuilder setUseTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch) Whether to match to URLs irrespective of the presence of a trailing slash. If enabled a method mapped to "/users" also matches to "/users/". -
addPlaceholderValue
In a standalone setup there is no support for placeholder values embedded in request mappings. This method allows manually provided placeholder values so they can be resolved. Alternatively consider creating a test that initializes aWebApplicationContext. -
setCustomHandlerMapping
public StandaloneMockMvcBuilder setCustomHandlerMapping(Supplier<cn.taketoday.web.handler.method.RequestMappingHandlerMapping> factory) Configure factory to create a customRequestMappingHandlerMapping.- 参数:
factory- the factory
-
setRedirectModelManager
public StandaloneMockMvcBuilder setRedirectModelManager(@Nullable cn.taketoday.web.view.RedirectModelManager redirectModelManager) -
setReturnValueHandlerManager
public StandaloneMockMvcBuilder setReturnValueHandlerManager(cn.taketoday.web.handler.ReturnValueHandlerManager returnValueHandlerManager) -
setParameterResolvingRegistry
public StandaloneMockMvcBuilder setParameterResolvingRegistry(cn.taketoday.web.bind.resolver.ParameterResolvingRegistry parameterResolvingRegistry) -
initWebAppContext
protected cn.taketoday.web.servlet.WebApplicationContext initWebAppContext()从类复制的说明:AbstractMockMvcBuilderA method to obtain theWebApplicationContextto be passed to theDispatcherServlet. Invoked fromAbstractMockMvcBuilder.build()before theMockMvcinstance is created. -
registerMvcSingletons
-
extendMvcSingletons
protected Map<String,Object> extendMvcSingletons(@Nullable jakarta.servlet.ServletContext servletContext) This method could be used from a subclass to register additional Infra MVC infrastructure such as additionalHandlerMapping,HandlerAdapter, and others.- 参数:
servletContext- the ServletContext- 返回:
- a map with additional MVC infrastructure object instances
-