public final class MockMvcWebConnection
extends java.lang.Object
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 ...
WebConnectionHtmlUnitDriver
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
contextPath |
private MockMvc |
mockMvc |
private java.util.Map<java.lang.String,MockHttpSession> |
sessions |
private WebClient |
webClient |
Constructor and Description |
---|
MockMvcWebConnection(MockMvc mockMvc,
WebClient webClient)
Create a new instance that assumes the context path of the application
is
"" (i.e., the root context). |
MockMvcWebConnection(MockMvc mockMvc,
WebClient webClient,
java.lang.String contextPath)
Create a new instance with the specified context path.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
WebResponse |
getResponse(WebRequest webRequest) |
void |
setWebClient(WebClient webClient) |
private void |
storeCookies(WebRequest webRequest,
javax.servlet.http.Cookie[] cookies) |
(package private) static void |
validateContextPath(java.lang.String contextPath)
Validate the supplied
contextPath . |
private final java.util.Map<java.lang.String,MockHttpSession> sessions
private final MockMvc mockMvc
private final java.lang.String contextPath
private WebClient webClient
public MockMvcWebConnection(MockMvc mockMvc, WebClient webClient)
""
(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
webClient
- the WebClient
to use. never null
public MockMvcWebConnection(MockMvc mockMvc, WebClient webClient, java.lang.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 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.
mockMvc
- the MockMvc
instance to use; never null
webClient
- the WebClient
to use. never null
contextPath
- the contextPath to usestatic void validateContextPath(java.lang.String contextPath)
contextPath
.
If the value is not null
, 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.
contextPath
- the path to validatepublic void setWebClient(WebClient webClient)
public WebResponse getResponse(WebRequest webRequest) throws java.io.IOException
java.io.IOException
private void storeCookies(WebRequest webRequest, javax.servlet.http.Cookie[] cookies)
public void close()