Class MockMvcWebConnection
java.lang.Object
org.springframework.test.web.servlet.htmlunit.MockMvcWebConnection
- All Implemented Interfaces:
- AutoCloseable,- org.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, webClient); webClient.setWebConnection(webConnection); // Use webClient as normal ...
- Since:
- 4.2
- Author:
- Rob Winch, Sam Brannen
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionMockMvcWebConnection(MockMvc mockMvc, org.htmlunit.WebClient webClient) Create a new instance that assumes the context path of the application is""(i.e., the root context).MockMvcWebConnection(MockMvc mockMvc, org.htmlunit.WebClient webClient, String contextPath) Create a new instance with the specified context path.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()org.htmlunit.WebResponsegetResponse(org.htmlunit.WebRequest webRequest) voidsetWebClient(org.htmlunit.WebClient webClient) 
- 
Constructor Details- 
MockMvcWebConnectionCreate 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- the- MockMvcinstance to use; never- null
- webClient- the- WebClientto use. never- null
 
- 
MockMvcWebConnectionpublic MockMvcWebConnection(MockMvc mockMvc, org.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- the- MockMvcinstance to use (never- null)
- webClient- the- WebClientto use (never- null)
- contextPath- the contextPath to use
 
 
- 
- 
Method Details- 
setWebClientpublic void setWebClient(org.htmlunit.WebClient webClient) 
- 
getResponse- Specified by:
- getResponsein interface- org.htmlunit.WebConnection
- Throws:
- IOException
 
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- org.htmlunit.WebConnection
 
 
-