public final class MockMvcWebConnection extends Object implements com.gargoylesoftware.htmlunit.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); mockConnection.setWebClient(webClient); webClient.setWebConnection(webConnection); // Use webClient as normal ...
WebConnectionHtmlUnitDriver
Constructor and Description |
---|
MockMvcWebConnection(MockMvc mockMvc)
Create a new instance that assumes the context path of the application
is
"" (i.e., the root context). |
MockMvcWebConnection(MockMvc mockMvc,
String contextPath)
Create a new instance with the specified context path.
|
Modifier and Type | Method and Description |
---|---|
com.gargoylesoftware.htmlunit.WebResponse |
getResponse(com.gargoylesoftware.htmlunit.WebRequest webRequest) |
void |
setWebClient(com.gargoylesoftware.htmlunit.WebClient webClient) |
public MockMvcWebConnection(MockMvc mockMvc)
""
(i.e., the root context).
For example, the URL http://localhost/test/this
would use
""
as the context path.
mockMvc
- the MockMvc
instance to use; never null
public MockMvcWebConnection(MockMvc mockMvc, String contextPath)
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.
mockMvc
- the MockMvc
instance to use; never null
contextPath
- the contextPath to usepublic com.gargoylesoftware.htmlunit.WebResponse getResponse(com.gargoylesoftware.htmlunit.WebRequest webRequest) throws IOException
getResponse
in interface com.gargoylesoftware.htmlunit.WebConnection
IOException
public void setWebClient(com.gargoylesoftware.htmlunit.WebClient webClient)