Class MockMvcWebConnection
- java.lang.Object
- org.springframework.test.web.servlet.htmlunit.MockMvcWebConnection
- All Implemented Interfaces:
com.gargoylesoftware.htmlunit.WebConnection,AutoCloseable
public final class MockMvcWebConnection extends Object implements com.gargoylesoftware.htmlunit.WebConnection
MockMvcWebConnectionenablesMockMvcto transform aWebRequestinto aWebResponse.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 Description MockMvcWebConnection(MockMvc mockMvc, com.gargoylesoftware.htmlunit.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.htmlunit.WebClient webClient, String contextPath)Create a new instance with the specified context path.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()com.gargoylesoftware.htmlunit.WebResponsegetResponse(com.gargoylesoftware.htmlunit.WebRequest webRequest)voidsetWebClient(com.gargoylesoftware.htmlunit.WebClient webClient)
Constructor Detail
MockMvcWebConnection
public MockMvcWebConnection(MockMvc mockMvc, com.gargoylesoftware.htmlunit.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/thiswould use""as the context path.- Parameters:
mockMvc- theMockMvcinstance to use; nevernullwebClient- theWebClientto use. nevernull
MockMvcWebConnection
public MockMvcWebConnection(MockMvc mockMvc, com.gargoylesoftware.htmlunit.WebClient webClient, @Nullable String contextPath)
Create a new instance with the specified context path.The path may be
nullin which case the first path segment of the URL is turned into the contextPath. Otherwise it must conform toHttpServletRequest.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- theMockMvcinstance to use (nevernull)webClient- theWebClientto use (nevernull)contextPath- the contextPath to use
Method Detail
setWebClient
public void setWebClient(com.gargoylesoftware.htmlunit.WebClient webClient)
getResponse
public com.gargoylesoftware.htmlunit.WebResponse getResponse(com.gargoylesoftware.htmlunit.WebRequest webRequest) throws IOException
- Specified by:
getResponsein interfacecom.gargoylesoftware.htmlunit.WebConnection- Throws:
IOException
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacecom.gargoylesoftware.htmlunit.WebConnection