spring-framework / org.springframework.test.web.servlet.htmlunit / MockMvcWebConnection

MockMvcWebConnection

class MockMvcWebConnection : 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 ... 

Author
Rob Winch

Author
Sam Brannen

Since
4.2

See Also
org.springframework.test.web.servlet.htmlunit.webdriver.WebConnectionHtmlUnitDriver

Constructors

<init>

MockMvcWebConnection(mockMvc: MockMvc, 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.

MockMvcWebConnection(mockMvc: MockMvc, webClient: WebClient, contextPath: String)

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 javax.servlet.http.HttpServletRequest#getContextPath() which states that it can be an empty string and otherwise must start with a "/" character and not end with a "/" character.

Functions

close

fun close(): Unit

getResponse

fun getResponse(webRequest: WebRequest): WebResponse

setWebClient

fun setWebClient(webClient: WebClient): Unit