org.springframework.test.web.servlet.phpunit

Class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>>

  • java.lang.Object
    • org.springframework.test.web.servlet.phpunit.MockMvcWebConnectionBuilderSupport<T>
  • Type Parameters:
    T - a self reference to the builder type
    Direct Known Subclasses:
    MockMvcHtmlUnitDriverBuilder, MockMvcWebClientBuilder


    public abstract class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>>
    extends java.lang.Object
    Support class that simplifies the creation of a WebConnection that uses MockMvc and optionally delegates to a real WebConnection for specific requests.

    The default is to use MockMvc for requests to localhost and otherwise use a real WebConnection.

    Since:
    4.2
    Author:
    Rob Winch, Sam Brannen
    • Constructor Detail

      • MockMvcWebConnectionBuilderSupport

        protected MockMvcWebConnectionBuilderSupport(MockMvc mockMvc)
        Create a new instance using the supplied MockMvc instance.
        Parameters:
        mockMvc - the MockMvc instance to use; never null
      • MockMvcWebConnectionBuilderSupport

        protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context)
        Create a new instance using the supplied WebApplicationContext.
        Parameters:
        context - the WebApplicationContext to create a MockMvc instance from; never null
      • MockMvcWebConnectionBuilderSupport

        protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context,
                                                     MockMvcConfigurer configurer)
        Create a new instance using the supplied WebApplicationContext and MockMvcConfigurer.
        Parameters:
        context - the WebApplicationContext to create a MockMvc instance from; never null
        configurer - the MockMvcConfigurer to apply; never null
    • Method Detail

      • contextPath

        public T contextPath(java.lang.String contextPath)
        Set the context path to use.

        If the supplied value is null or empty, the first path segment of the request URL is assumed to be the context path.

        Default is "".

        Parameters:
        contextPath - the context path to use
        Returns:
        this builder for further customization
      • alwaysUseMockMvc

        public T alwaysUseMockMvc()
        Specify that MockMvc should always be used regardless of what the request looks like.
        Returns:
        this builder for further customization
      • useMockMvc

        public T useMockMvc(WebRequestMatcher... matchers)
        Add additional WebRequestMatcher instances that will ensure that MockMvc is used to process the request, if such a matcher matches against the web request.
        Parameters:
        matchers - additional WebRequestMatcher instances
        Returns:
        this builder for further customization
      • useMockMvcForHosts

        public T useMockMvcForHosts(java.lang.String... hosts)
        Add additional WebRequestMatcher instances that return true if a supplied host matches — for example, "example.com" or "example.com:8080".
        Parameters:
        hosts - additional hosts that ensure MockMvc gets invoked
        Returns:
        this builder for further customization
      • createConnection

        protected final com.gargoylesoftware.phpunit.WebConnection createConnection(com.gargoylesoftware.phpunit.WebClient webClient)
        Create a new WebConnection that will use a MockMvc instance if one of the specified WebRequestMatcher instances matches.
        Parameters:
        webClient - the WebClient to use if none of the specified WebRequestMatcher instances matches (never null)
        Returns:
        a new WebConnection that will use a MockMvc instance if one of the specified WebRequestMatcher matches
        Since:
        4.3
        See Also:
        alwaysUseMockMvc(), useMockMvc(WebRequestMatcher...), useMockMvcForHosts(String...)