public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneMockMvcBuilder>
@Controller
登録を受け入れる MockMvcBuilder
により、コントローラーのインスタンス化と初期化、単純な単体テストに類似したそれらの依存関係を完全に制御でき、同時に 1 つのコントローラーをテストすることもできます。 このビルダーは、DispatcherServlet
がアノテーション付きコントローラーでリクエストを処理するために必要な最小限のインフラストラクチャーを作成し、カスタマイズの方法も提供します。結果の構成およびカスタマイズオプションは、ビルダースタイルメソッドを使用することを除き、MVC Java 構成を使用するのと同等です。
ビューリゾルバーを設定するには、実行されるすべてのリクエストに使用する "fixed" ビューを選択するか(setSingleView(View)
を参照)、ViewResolver
のリストを提供します(setViewResolvers(ViewResolver...)
を参照)。
修飾子 | コンストラクターと説明 |
---|---|
protected | StandaloneMockMvcBuilder(ObjectSE... controllers) protected コンストラクター。 |
addDispatcherServletCustomizer, addFilter, addFilters, alwaysDo, alwaysExpect, apply, build, defaultRequest, dispatchOptions, self
createMockMvc
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
protected StandaloneMockMvcBuilder(ObjectSE... controllers)
public StandaloneMockMvcBuilder setControllerAdvice(ObjectSE... controllerAdvice)
ControllerAdvice
インスタンスを登録します(指定された Class
はインスタンスになります)。 通常、@ControllerAdvice
は、Spring Bean として宣言されている限り自動検出されます。ただし、スタンドアロンセットアップは Spring の設定をロードしないため、コントローラーのようにここで明示的に登録する必要があります。
public StandaloneMockMvcBuilder setMessageConverters(HttpMessageConverter<?>... messageConverters)
public StandaloneMockMvcBuilder setValidator(Validator validator)
Validator
を提供します。JSR-303 がクラスパス上にあると仮定すると、使用されるデフォルトの実装は LocalValidatorFactoryBean
です。public StandaloneMockMvcBuilder setConversionService(FormattingConversionService conversionService)
DefaultFormattingConversionService
がデフォルトで使用されます。public StandaloneMockMvcBuilder addInterceptors(HandlerInterceptor... interceptors)
public StandaloneMockMvcBuilder addMappedInterceptors(@Nullable StringSE[] pathPatterns, HandlerInterceptor... interceptors)
public StandaloneMockMvcBuilder setContentNegotiationManager(ContentNegotiationManager manager)
public StandaloneMockMvcBuilder setAsyncRequestTimeout(long timeout)
timeout
- ミリ秒単位のタイムアウト値 public StandaloneMockMvcBuilder setCustomArgumentResolvers(HandlerMethodArgumentResolver... argumentResolvers)
public StandaloneMockMvcBuilder setCustomReturnValueHandlers(HandlerMethodReturnValueHandler... handlers)
public StandaloneMockMvcBuilder setHandlerExceptionResolvers(ListSE<HandlerExceptionResolver> exceptionResolvers)
public StandaloneMockMvcBuilder setHandlerExceptionResolvers(HandlerExceptionResolver... exceptionResolvers)
public StandaloneMockMvcBuilder setViewResolvers(ViewResolver... resolvers)
ViewResolvers
でビューリゾルバーを設定します。設定されていない場合、デフォルトで InternalResourceViewResolver
が使用されます。public StandaloneMockMvcBuilder setSingleView(View view)
ViewResolver
を設定します。これは、1 つの View インスタンスのみを使用する必要がある場合に便利なショートカットです。生成されたコンテンツ(JSON、XML、Atom)のレンダリング。public StandaloneMockMvcBuilder setLocaleResolver(LocaleResolver localeResolver)
AcceptHeaderLocaleResolver
です。public StandaloneMockMvcBuilder setFlashMapManager(FlashMapManager flashMapManager)
SessionFlashMapManager
が使用されます。@DeprecatedSE public StandaloneMockMvcBuilder setUseSuffixPatternMatch(boolean useSuffixPatternMatch)
RequestMappingHandlerMapping
のクラスレベルの注記を参照してください。 デフォルト値は true
です。
public StandaloneMockMvcBuilder setUseTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch)
デフォルト値は true
です。
public StandaloneMockMvcBuilder setRemoveSemicolonContent(boolean removeSemicolonContent)
AbstractHandlerMapping.setRemoveSemicolonContent(boolean)
に順番に設定されます。public StandaloneMockMvcBuilder addPlaceholderValue(StringSE name, StringSE value)
WebApplicationContext
を初期化するテストの作成を検討してください。public StandaloneMockMvcBuilder setCustomHandlerMapping(SupplierSE<RequestMappingHandlerMapping> factory)
RequestMappingHandlerMapping
を作成します。factory
- ファクトリ protected WebApplicationContext initWebAppContext()
AbstractMockMvcBuilder
DispatcherServlet
に渡される WebApplicationContext
を取得するメソッド。MockMvc
インスタンスが作成される前に AbstractMockMvcBuilder.build()
から呼び出されます。protected MapSE<StringSE,ObjectSE> extendMvcSingletons(@Nullable ServletContextEE servletContext)
HandlerMapping
、HandlerAdapter
などの追加の Spring MVC インフラストラクチャを登録できます。servletContext
- ServletContext