org.springframework.test.web.servlet.phpunit

Class MockMvcWebConnection

  • java.lang.Object
    • org.springframework.test.web.servlet.phpunit.MockMvcWebConnection
  • All Implemented Interfaces:
    com.gargoylesoftware.phpunit.WebConnection, java.lang.AutoCloseable


    public final class MockMvcWebConnection
    extends java.lang.Object
    implements com.gargoylesoftware.phpunit.WebConnection
    MockMvcWebConnection enables MockMvc to transform a WebRequest into a WebResponse.

    This is the core integration with HtmlUnit.

    Example usage can be seen below.

     WebClient webClient = new WebClient();
     MockMvc mockMvc = ...
     MockMvcWebConnection webConnection = new MockMvcWebConnection(mockMvc, webClient);
     webClient.setWebConnection(webConnection);
    
     // Use webClient as normal ...
     
    Since:
    4.2
    Author:
    Rob Winch, Sam Brannen
    See Also:
    WebConnectionHtmlUnitDriver
    • Constructor Summary

      Constructors 
      Constructor and Description
      MockMvcWebConnection(MockMvc mockMvc, com.gargoylesoftware.phpunit.WebClient webClient)
      Create a new instance that assumes the context path of the application is "" (i.e., the root context).
      MockMvcWebConnection(MockMvc mockMvc, com.gargoylesoftware.phpunit.WebClient webClient, java.lang.String contextPath)
      Create a new instance with the specified context path.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void close() 
      com.gargoylesoftware.phpunit.WebResponse getResponse(com.gargoylesoftware.phpunit.WebRequest webRequest) 
      void setWebClient(com.gargoylesoftware.phpunit.WebClient webClient) 
      • Methods inherited from class java.lang.Object

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

      • MockMvcWebConnection

        public MockMvcWebConnection(MockMvc mockMvc,
                                    com.gargoylesoftware.phpunit.WebClient webClient)
        Create a new instance that assumes the context path of the application is "" (i.e., the root context).

        For example, the URL http://localhost/test/this would use "" as the context path.

        Parameters:
        mockMvc - the MockMvc instance to use; never null
        webClient - the WebClient to use. never null
      • MockMvcWebConnection

        public MockMvcWebConnection(MockMvc mockMvc,
                                    com.gargoylesoftware.phpunit.WebClient webClient,
                                    java.lang.String contextPath)
        Create a new instance with the specified context path.

        The path may be null in which case the first path segment of the URL is turned into the contextPath. Otherwise it must conform to HttpServletRequest.getContextPath() which states that it can be an empty string and otherwise must start with a "/" character and not end with a "/" character.

        Parameters:
        mockMvc - the MockMvc instance to use (never null)
        webClient - the WebClient to use (never null)
        contextPath - the contextPath to use
    • Method Detail

      • setWebClient

        public void setWebClient(com.gargoylesoftware.phpunit.WebClient webClient)
      • getResponse

        public com.gargoylesoftware.phpunit.WebResponse getResponse(com.gargoylesoftware.phpunit.WebRequest webRequest)
                                                              throws java.io.IOException
        Specified by:
        getResponse in interface com.gargoylesoftware.phpunit.WebConnection
        Throws:
        java.io.IOException
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable