StandaloneMockMvcBuilder (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.test.web.servlet.setup

## Class StandaloneMockMvcBuilder

- java.lang.Object
- - org.springframework.test.web.servlet.MockMvcBuilderSupport
  - - org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder<StandaloneMockMvcBuilder>
    - - org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder

- All Implemented Interfaces:
    MockMvcBuilder

      public class StandaloneMockMvcBuilder
      extends DefaultMockMvcBuilder<StandaloneMockMvcBuilder>

  A MockMvcBuilder that accepts `@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...)`.

  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `StandaloneMockMvcBuilder(Object... controllers)` Protected constructor.

  - ### Method Summary

    Methods
    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.
    `protected void` | `initWebAppContext(WebApplicationContext cxt)` Invoked from `DefaultMockMvcBuilder.build()` before the `MockMvc` instance is created.
    `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(List<HandlerExceptionResolver> exceptionResolvers)` Set the HandlerExceptionResolver types to use.
    `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` | `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.

    - ### Methods inherited from class org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder

      `addFilter, addFilters, alwaysDo, alwaysExpect, build, defaultRequest, dispatchOptions`

    - ### Methods inherited from class org.springframework.test.web.servlet.MockMvcBuilderSupport

      `createMockMvc`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StandaloneMockMvcBuilder

          protected StandaloneMockMvcBuilder(Object... controllers)

      Protected constructor. Not intended for direct instantiation.
      See Also:
        `MockMvcBuilders.standaloneSetup(Object...)`

  - ### Method Detail

    - #### setMessageConverters

          public 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. If no message converters are added to the list, a default list of converters is added instead.

    - #### setValidator

          public StandaloneMockMvcBuilder setValidator(Validator validator)

      Provide a custom `Validator` instead of the one created by default. The default implementation used, assuming JSR-303 is on the classpath, is `LocalValidatorFactoryBean`.

    - #### setConversionService

          public StandaloneMockMvcBuilder setConversionService(FormattingConversionService conversionService)

      Provide a conversion service with custom formatters and converters. If not set, a `DefaultFormattingConversionService` is used by default.

    - #### addInterceptors

          public StandaloneMockMvcBuilder addInterceptors(HandlerInterceptor... interceptors)

      Add interceptors mapped to all incoming requests.

    - #### addMappedInterceptors

          public StandaloneMockMvcBuilder addMappedInterceptors(String[] pathPatterns,
                                                       HandlerInterceptor... interceptors)

      Add interceptors mapped to a set of path patterns.

    - #### setContentNegotiationManager

          protected StandaloneMockMvcBuilder setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)

      Set a ContentNegotiationManager.

    - #### setAsyncRequestTimeout

          public StandaloneMockMvcBuilder setAsyncRequestTimeout(long timeout)

      Specify the timeout value for async execution. In Spring 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.
      Parameters:
        `timeout` - the timeout value in milliseconds

    - #### setCustomArgumentResolvers

          public StandaloneMockMvcBuilder setCustomArgumentResolvers(HandlerMethodArgumentResolver... argumentResolvers)

      Provide custom resolvers for controller method arguments.

    - #### setCustomReturnValueHandlers

          public StandaloneMockMvcBuilder setCustomReturnValueHandlers(HandlerMethodReturnValueHandler... handlers)

      Provide custom handlers for controller method return values.

    - #### setHandlerExceptionResolvers

          public StandaloneMockMvcBuilder setHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers)

      Set the HandlerExceptionResolver types to use.

    - #### setViewResolvers

          public StandaloneMockMvcBuilder setViewResolvers(ViewResolver... resolvers)

      Set up view resolution with the given `ViewResolver`s. If not set, an `InternalResourceViewResolver` is used by default.

    - #### setSingleView

          public StandaloneMockMvcBuilder setSingleView(View view)

      Sets up a single `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).

    - #### setLocaleResolver

          public StandaloneMockMvcBuilder setLocaleResolver(LocaleResolver localeResolver)

      Provide a LocaleResolver instance. If not provided, the default one used is `AcceptHeaderLocaleResolver`.

    - #### setFlashMapManager

          public StandaloneMockMvcBuilder setFlashMapManager(FlashMapManager flashMapManager)

      Provide a custom FlashMapManager instance. If not provided, `SessionFlashMapManager` is used by default.

    - #### setUseSuffixPatternMatch

          public StandaloneMockMvcBuilder setUseSuffixPatternMatch(boolean useSuffixPatternMatch)

      Whether to use suffix pattern match (".*") when matching patterns to requests. If enabled a method mapped to "/users" also matches to "/users.*".

      The default value is `true`.

    - #### 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/".

      The default value is `true`.

    - #### initWebAppContext

          protected void initWebAppContext(WebApplicationContext cxt)

      Description copied from class: `DefaultMockMvcBuilder`
      Invoked from `DefaultMockMvcBuilder.build()` before the `MockMvc` instance is created. Allows sub-classes to further initialize the `WebApplicationContext` and the `javax.servlet.ServletContext` it contains.
      Overrides:
        `initWebAppContext` in class `DefaultMockMvcBuilder<StandaloneMockMvcBuilder>`