java.lang.Object
com.c4_soft.springaddons.security.oauth2.test.mockmvc.MockMvcSupport

@Scope("prototype") public class MockMvcSupport extends Object

Just another wrapper for Spring MockMvc.
It would extend MockMvc if it was not final :-/

Highlighted features:
  • auto sets "Accept" and "Content-Type" headers according com.c4-soft.springaddons.test.web.default-media-type and com.c4-soft.springaddons.test.web.default-charset to test properties, defaulted to application/json and utf-8
  • serializes request body according to Content-type using registered message converters
  • provides with shortcuts to issue requests in basic but most common cases (no fancy headers, cookies, etc): get, post, patch, put and delete methods
  • wraps MockMvc perform and exposes request builder helpers for advanced cases (when you need to further customize MockHttpServletRequestBuilder with cookies or additional headers for instance)
Author:
Jérôme Wacongne <ch4mp@c4-soft.com>
  • Constructor Summary

    Constructors
    Constructor
    Description
    MockMvcSupport(org.springframework.test.web.servlet.MockMvc mockMvc, SerializationHelper serializationHelper, MockMvcProperties mockMvcProperties, org.springframework.boot.autoconfigure.web.ServerProperties serverProperties, com.c4_soft.springaddons.security.oauth2.config.SpringAddonsSecurityProperties securityProperties)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.test.web.servlet.ResultActions
    delete(String urlTemplate, Object... uriVars)
    Shortcut to issue a DELETE request (no header)
    org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    deleteRequestBuilder(String urlTemplate, Object... uriVars)
    Factory for a DELETE request builder.
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    feed(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder request, T payload, org.springframework.http.MediaType mediaType, Charset charset)
    Adds serialized payload to request content.
    org.springframework.test.web.servlet.ResultActions
    get(String urlTemplate, Object... uriVars)
    Shortcut to create a builder for a GET request with minimal headers and submit it (Accept header defaulted to what this helper was constructed with).
    org.springframework.test.web.servlet.ResultActions
    get(org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
    Shortcut to issue a GET request with minimal headers and submit it.
    org.springframework.web.servlet.DispatcherServlet
     
    org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    getRequestBuilder(String urlTemplate, Object... uriVars)
    Factory providing with a request builder to issue a GET request (with Accept header defaulted to what this helper is constructed with).
    org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    getRequestBuilder(org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
    Factory providing with a request builder to issue a GET request (with Accept header).
    org.springframework.test.web.servlet.ResultActions
    head(String urlTemplate, Object... uriVars)
    Shortcut to issue a HEAD request (no header)
    org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    headRequestBuilder(String urlTemplate, Object... uriVars)
    Factory for a HEAD request builder.
    org.springframework.test.web.servlet.ResultActions
    option(String urlTemplate, Object... uriVars)
    Shortcut to issue an OPTION request with default media-type as Accept header
    org.springframework.test.web.servlet.ResultActions
    option(org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
    Shortcut to issue an OPTION request with Accept header
    org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    optionRequestBuilder(String urlTemplate, Object... uriVars)
    Factory for an OPTION request initialized with an Accept header set to default media-type.
    org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    optionRequestBuilder(org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
    Factory for an OPTION request initialized with an Accept header.
    <T> org.springframework.test.web.servlet.ResultActions
    patch(T payload, String urlTemplate, Object... uriVars)
    Shortcut to issue a patch request with Content-type header and a body (using default media-type).
    <T> org.springframework.test.web.servlet.ResultActions
    patch(T payload, org.springframework.http.MediaType contentType, String urlTemplate, Object... uriVars)
    Shortcut to issue a patch request with Content-type header and a body.
    <T> org.springframework.test.web.servlet.ResultActions
    patch(T payload, org.springframework.http.MediaType contentType, Charset charset, String urlTemplate, Object... uriVars)
    Shortcut to issue a patch request with Content-type header and a body.
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    patchRequestBuilder(T payload, String urlTemplate, Object... uriVars)
    Factory for a patch request builder (with Content-type set to default media-type).
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    patchRequestBuilder(T payload, org.springframework.http.MediaType contentType, String urlTemplate, Object... uriVars)
    Factory for a patch request builder (with Content-type already set).
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    patchRequestBuilder(T payload, org.springframework.http.MediaType contentType, Charset charset, String urlTemplate, Object... uriVars)
    Factory for a patch request builder (with Content-type already set).
    org.springframework.test.web.servlet.ResultActions
    perform(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder requestBuilder)
    To be called with fully configured request builder (wraps MockMvc perform).
    <T> org.springframework.test.web.servlet.ResultActions
    post(T payload, String urlTemplate, Object... uriVars)
    Shortcut to issue a POST request with provided payload as body, using default media-type for serialization (and Content-type header).
    <T> org.springframework.test.web.servlet.ResultActions
    post(T payload, org.springframework.http.MediaType contentType, Charset charset, org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
    Shortcut to issue a POST request with provided payload as body, using given media-type for serialization (and Content-type header).
    <T> org.springframework.test.web.servlet.ResultActions
    post(T payload, org.springframework.http.MediaType contentType, org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
    Shortcut to issue a POST request with provided payload as body, using given media-type for serialization (and Content-type header).
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    postRequestBuilder(T payload, String urlTemplate, Object... uriVars)
    Factory for a POST request builder.
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    postRequestBuilder(T payload, org.springframework.http.MediaType contentType, Charset charset, org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
    Factory for a POST request builder containing a body set to payload serialized in given media type (with adequate Content-type header).
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    postRequestBuilder(T payload, org.springframework.http.MediaType contentType, org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
    Factory for a POST request builder containing a body set to payload serialized in given media type (with adequate Content-type header).
    <T> org.springframework.test.web.servlet.ResultActions
    put(T payload, String urlTemplate, Object... uriVars)
    Shortcut to issue a PUT request (with default media-type as Content-type).
    <T> org.springframework.test.web.servlet.ResultActions
    put(T payload, org.springframework.http.MediaType contentType, String urlTemplate, Object... uriVars)
    Shortcut to issue a PUT request.
    <T> org.springframework.test.web.servlet.ResultActions
    put(T payload, org.springframework.http.MediaType contentType, String charset, String urlTemplate, Object... uriVars)
    Shortcut to issue a PUT request.
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    putRequestBuilder(T payload, String urlTemplate, Object... uriVars)
    Factory for a POST request builder containing a body.
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    putRequestBuilder(T payload, org.springframework.http.MediaType contentType, String urlTemplate, Object... uriVars)
    Factory for a POST request builder containing a body.
    <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    putRequestBuilder(T payload, org.springframework.http.MediaType contentType, Charset charset, String urlTemplate, Object... uriVars)
    Factory for a POST request builder containing a body.
    org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
    requestBuilder(Optional<org.springframework.http.MediaType> accept, Optional<Charset> charset, org.springframework.http.HttpMethod method, String urlTemplate, Object... uriVars)
    Factory for a generic MockHttpServletRequestBuilder with relevant "Accept" and "Content-Type" headers.
     
    setCsrf(boolean isCsrf)
     
    setMediaType(org.springframework.http.MediaType mediaType)
     
    setSecure(boolean isSecure)
     
    with(org.springframework.test.web.servlet.request.RequestPostProcessor postProcessor)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MockMvcSupport

      public MockMvcSupport(org.springframework.test.web.servlet.MockMvc mockMvc, SerializationHelper serializationHelper, MockMvcProperties mockMvcProperties, org.springframework.boot.autoconfigure.web.ServerProperties serverProperties, com.c4_soft.springaddons.security.oauth2.config.SpringAddonsSecurityProperties securityProperties)
      Parameters:
      mockMvc - wrapped Spring MVC testing helper
      serializationHelper - used to serialize payloads to requested Content-type using Spring registered message converters
      mockMvcProperties - default values for media-type, charset and https usage
  • Method Details

    • setSecure

      public MockMvcSupport setSecure(boolean isSecure)
      Parameters:
      isSecure - if true, requests are sent with https instead of http
      Returns:
    • setCsrf

      public MockMvcSupport setCsrf(boolean isCsrf)
      Parameters:
      isCsrf - should MockMvcRequests be issued with CSRF
      Returns:
    • setMediaType

      public MockMvcSupport setMediaType(org.springframework.http.MediaType mediaType)
      Parameters:
      mediaType - override configured default media-type
      Returns:
    • setCharset

      public MockMvcSupport setCharset(Charset charset)
      Parameters:
      charset - override configured default charset
      Returns:
    • requestBuilder

      public org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder requestBuilder(Optional<org.springframework.http.MediaType> accept, Optional<Charset> charset, org.springframework.http.HttpMethod method, String urlTemplate, Object... uriVars)
      Factory for a generic MockHttpServletRequestBuilder with relevant "Accept" and "Content-Type" headers. You might prefer to use getRequestBuilder or alike which go further with request pre-configuration or even get, post(Object, String, Object...) and so on which issue simple requests in one step.
      Parameters:
      accept - should be non-empty when issuing response with body (GET, POST, OPTION), none otherwise
      charset - char-set to be used for serialized payloads
      method - whatever HTTP verb you need
      urlTemplate - end-point to be requested
      uriVars - end-point template placeholders values
      Returns:
      a request builder with minimal info you can tweak further: add headers, cookies, etc.
    • perform

      public org.springframework.test.web.servlet.ResultActions perform(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder requestBuilder)
      To be called with fully configured request builder (wraps MockMvc perform).
      Parameters:
      requestBuilder - fully configured request
      Returns:
      API answer to be tested
    • getRequestBuilder

      public org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder getRequestBuilder(org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
      Factory providing with a request builder to issue a GET request (with Accept header).
      Parameters:
      accept - determines request Accept header (and response body format)
      urlTemplate - API end-point to call
      uriVars - values to feed URL template placeholders
      Returns:
      a request builder to be further configured (additional headers, cookies, etc.)
    • getRequestBuilder

      public org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder getRequestBuilder(String urlTemplate, Object... uriVars)
      Factory providing with a request builder to issue a GET request (with Accept header defaulted to what this helper is constructed with).
      Parameters:
      urlTemplate - API end-point to call
      uriVars - values to feed URL template placeholders
      Returns:
      a request builder to be further configured (additional headers, cookies, etc.)
    • get

      public org.springframework.test.web.servlet.ResultActions get(org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
      Shortcut to issue a GET request with minimal headers and submit it.
      Parameters:
      accept - determines request Accept header (and response body format)
      urlTemplate - API endpoint to be requested
      uriVars - values to replace endpoint placeholders with
      Returns:
      API response to test
    • get

      public org.springframework.test.web.servlet.ResultActions get(String urlTemplate, Object... uriVars)
      Shortcut to create a builder for a GET request with minimal headers and submit it (Accept header defaulted to what this helper was constructed with).
      Parameters:
      urlTemplate - API endpoint to be requested
      uriVars - values to replace endpoint placeholders with
      Returns:
      API response to test
    • postRequestBuilder

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder postRequestBuilder(T payload, org.springframework.http.MediaType contentType, Charset charset, org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
      Factory for a POST request builder containing a body set to payload serialized in given media type (with adequate Content-type header).
      Type Parameters:
      T - payload type
      Parameters:
      payload - to be serialized as body in contentType format
      contentType - format to be used for payload serialization
      charset - char-set for request and response
      accept - how should the response body be serialized (if any)
      urlTemplate - API end-point to be requested
      uriVars - values to replace end-point placeholders with
      Returns:
      Request builder to further configure (cookies, additional headers, etc.)
    • postRequestBuilder

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder postRequestBuilder(T payload, org.springframework.http.MediaType contentType, org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
      Factory for a POST request builder containing a body set to payload serialized in given media type (with adequate Content-type header).
      Type Parameters:
      T - payload type
      Parameters:
      payload - to be serialized as body in contentType format
      contentType - format to be used for payload serialization
      accept - how should the response body be serialized (if any)
      urlTemplate - API end-point to be requested
      uriVars - values to replace end-point placeholders with
      Returns:
      Request builder to further configure (cookies, additional headers, etc.)
    • postRequestBuilder

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder postRequestBuilder(T payload, String urlTemplate, Object... uriVars)
      Factory for a POST request builder. Body is pre-set to payload. Both Content-type and Accept headers are set to default media-type.
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      urlTemplate - API end-point
      uriVars - values ofr URL template placeholders
      Returns:
      Request builder to further configure (cookies, additional headers, etc.)
    • post

      public <T> org.springframework.test.web.servlet.ResultActions post(T payload, org.springframework.http.MediaType contentType, Charset charset, org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
      Shortcut to issue a POST request with provided payload as body, using given media-type for serialization (and Content-type header).
      Type Parameters:
      T - payload type
      Parameters:
      payload - POST request body
      contentType - media type used to serialize payload and set Content-type header
      accept - media-type to be set as Accept header (and response serialization)
      charset - char-set for request and response
      urlTemplate - API end-point to be called
      uriVars - values ofr URL template placeholders
      Returns:
      API response to test
    • post

      public <T> org.springframework.test.web.servlet.ResultActions post(T payload, org.springframework.http.MediaType contentType, org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
      Shortcut to issue a POST request with provided payload as body, using given media-type for serialization (and Content-type header).
      Type Parameters:
      T - payload type
      Parameters:
      payload - POST request body
      contentType - media type used to serialize payload and set Content-type header
      accept - media-type to be set as Accept header (and response serialization)
      urlTemplate - API end-point to be called
      uriVars - values ofr URL template placeholders
      Returns:
      API response to test
    • post

      public <T> org.springframework.test.web.servlet.ResultActions post(T payload, String urlTemplate, Object... uriVars)
      Shortcut to issue a POST request with provided payload as body, using default media-type for serialization (and Content-type header).
      Type Parameters:
      T - payload type
      Parameters:
      payload - POST request body
      urlTemplate - API end-point to be called
      uriVars - values ofr URL template placeholders
      Returns:
      API response to test
    • putRequestBuilder

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder putRequestBuilder(T payload, org.springframework.http.MediaType contentType, Charset charset, String urlTemplate, Object... uriVars)
      Factory for a POST request builder containing a body.
      Type Parameters:
      T - payload type
      Parameters:
      payload - to be serialized as body in contentType format
      contentType - format to be used for payload serialization
      charset - char-set for request
      urlTemplate - API end-point to be requested
      uriVars - values to replace end-point placeholders with
      Returns:
      Request builder to further configure (cookies, additional headers, etc.)
    • putRequestBuilder

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder putRequestBuilder(T payload, org.springframework.http.MediaType contentType, String urlTemplate, Object... uriVars)
      Factory for a POST request builder containing a body.
      Type Parameters:
      T - payload type
      Parameters:
      payload - to be serialized as body in contentType format
      contentType - format to be used for payload serialization
      urlTemplate - API end-point to be requested
      uriVars - values to replace end-point placeholders with
      Returns:
      Request builder to further configure (cookies, additional headers, etc.)
    • putRequestBuilder

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder putRequestBuilder(T payload, String urlTemplate, Object... uriVars)
      Factory for a POST request builder containing a body. Default media-type is used for payload serialization (and Content-type header).
      Type Parameters:
      T - payload type
      Parameters:
      payload - to be serialized as body in contentType format
      urlTemplate - API end-point to be requested
      uriVars - values to replace end-point placeholders with
      Returns:
      Request builder to further configure (cookies, additional headers, etc.)
    • put

      public <T> org.springframework.test.web.servlet.ResultActions put(T payload, org.springframework.http.MediaType contentType, String charset, String urlTemplate, Object... uriVars)
      Shortcut to issue a PUT request.
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      contentType - payload serialization media-type
      charset - char-set for request and response
      urlTemplate - API end-point to request
      uriVars - values to be used in end-point URL placehoders
      Returns:
      API response to be tested
    • put

      public <T> org.springframework.test.web.servlet.ResultActions put(T payload, org.springframework.http.MediaType contentType, String urlTemplate, Object... uriVars)
      Shortcut to issue a PUT request.
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      contentType - payload serialization media-type
      urlTemplate - API end-point to request
      uriVars - values to be used in end-point URL placehoders
      Returns:
      API response to be tested
    • put

      public <T> org.springframework.test.web.servlet.ResultActions put(T payload, String urlTemplate, Object... uriVars)
      Shortcut to issue a PUT request (with default media-type as Content-type).
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      urlTemplate - API end-point to request
      uriVars - values to be used in end-point URL placehoders
      Returns:
      API response to be tested
    • patchRequestBuilder

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder patchRequestBuilder(T payload, org.springframework.http.MediaType contentType, Charset charset, String urlTemplate, Object... uriVars)
      Factory for a patch request builder (with Content-type already set).
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      charset - char-set to be used for serialized payloads
      contentType - payload serialization format
      urlTemplate - API end-point
      uriVars - values for end-point placeholders
      Returns:
      request builder to further configure (additional headers, cookies, etc.)
    • patchRequestBuilder

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder patchRequestBuilder(T payload, org.springframework.http.MediaType contentType, String urlTemplate, Object... uriVars)
      Factory for a patch request builder (with Content-type already set).
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      contentType - payload serialization format
      urlTemplate - API end-point
      uriVars - values for end-point placeholders
      Returns:
      request builder to further configure (additional headers, cookies, etc.)
    • patchRequestBuilder

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder patchRequestBuilder(T payload, String urlTemplate, Object... uriVars)
      Factory for a patch request builder (with Content-type set to default media-type).
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      urlTemplate - API end-point
      uriVars - values for end-point placeholders
      Returns:
      request builder to further configure (additional headers, cookies, etc.)
    • patch

      public <T> org.springframework.test.web.servlet.ResultActions patch(T payload, org.springframework.http.MediaType contentType, Charset charset, String urlTemplate, Object... uriVars)
      Shortcut to issue a patch request with Content-type header and a body.
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      contentType - to be used for payload serialization
      charset - to be used for payload serialization
      urlTemplate - end-point URL
      uriVars - values for end-point URL placeholders
      Returns:
      API response to be tested
    • patch

      public <T> org.springframework.test.web.servlet.ResultActions patch(T payload, org.springframework.http.MediaType contentType, String urlTemplate, Object... uriVars)
      Shortcut to issue a patch request with Content-type header and a body.
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      contentType - to be used for payload serialization
      urlTemplate - end-point URL
      uriVars - values for end-point URL placeholders
      Returns:
      API response to be tested
    • patch

      public <T> org.springframework.test.web.servlet.ResultActions patch(T payload, String urlTemplate, Object... uriVars)
      Shortcut to issue a patch request with Content-type header and a body (using default media-type).
      Type Parameters:
      T - payload type
      Parameters:
      payload - request body
      urlTemplate - end-point URL
      uriVars - values for end-point URL placeholders
      Returns:
      API response to be tested
    • deleteRequestBuilder

      public org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder deleteRequestBuilder(String urlTemplate, Object... uriVars)
      Factory for a DELETE request builder.
      Parameters:
      urlTemplate - API end-point
      uriVars - values for end-point URL placeholders
      Returns:
      request builder to further configure (additional headers, cookies, etc.)
    • delete

      public org.springframework.test.web.servlet.ResultActions delete(String urlTemplate, Object... uriVars)
      Shortcut to issue a DELETE request (no header)
      Parameters:
      urlTemplate - API end-point
      uriVars - values for end-point URL placeholders
      Returns:
      API response to be tested
    • headRequestBuilder

      public org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder headRequestBuilder(String urlTemplate, Object... uriVars)
      Factory for a HEAD request builder.
      Parameters:
      urlTemplate - API end-point
      uriVars - values for end-point URL placeholders
      Returns:
      request builder to further configure (additional headers, cookies, etc.)
    • head

      public org.springframework.test.web.servlet.ResultActions head(String urlTemplate, Object... uriVars)
      Shortcut to issue a HEAD request (no header)
      Parameters:
      urlTemplate - API end-point
      uriVars - values for end-point URL placeholders
      Returns:
      API response to be tested
    • optionRequestBuilder

      public org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder optionRequestBuilder(org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
      Factory for an OPTION request initialized with an Accept header.
      Parameters:
      accept - response body media-type
      urlTemplate - API end-point
      uriVars - values for end-point URL placeholders
      Returns:
      request builder to be further configured (additional headers, cookies, etc.)
    • optionRequestBuilder

      public org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder optionRequestBuilder(String urlTemplate, Object... uriVars)
      Factory for an OPTION request initialized with an Accept header set to default media-type.
      Parameters:
      urlTemplate - API end-point
      uriVars - values for end-point URL placeholders
      Returns:
      request builder to be further configured (additional headers, cookies, etc.)
    • option

      public org.springframework.test.web.servlet.ResultActions option(org.springframework.http.MediaType accept, String urlTemplate, Object... uriVars)
      Shortcut to issue an OPTION request with Accept header
      Parameters:
      accept - response body media-type
      urlTemplate - API end-point
      uriVars - values for end-point URL placeholders
      Returns:
      API response to be further configured
    • option

      public org.springframework.test.web.servlet.ResultActions option(String urlTemplate, Object... uriVars)
      Shortcut to issue an OPTION request with default media-type as Accept header
      Parameters:
      urlTemplate - API end-point
      uriVars - values for end-point URL placeholders
      Returns:
      API response to be further configured
    • feed

      public <T> org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder feed(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder request, T payload, org.springframework.http.MediaType mediaType, Charset charset)
      Adds serialized payload to request content. Rather low-level, consider using this class MockHttpServletRequestBuilder factories instead (getRequestBuilder, postRequestBuilder, etc.)
      Type Parameters:
      T - payload type
      Parameters:
      request - builder you want to set body to
      payload - object to be serialized as body
      mediaType - what format you want payload to be serialized to (corresponding HttpMessageConverter must be registered)
      charset - char-set to be used for payload serialization
      Returns:
      the request with provided payload as content
    • getDispatcherServlet

      public org.springframework.web.servlet.DispatcherServlet getDispatcherServlet()
    • with

      public MockMvcSupport with(org.springframework.test.web.servlet.request.RequestPostProcessor postProcessor)
      Parameters:
      postProcessor - request post-processor to be added to the list of those applied before request is performed
      Returns:
      this MockMvcSupport