Class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>>
- java.lang.Object
- org.springframework.test.web.servlet.htmlunit.MockMvcWebConnectionBuilderSupport<T>
- Direct Known Subclasses:
MockMvcHtmlUnitDriverBuilder,MockMvcWebClientBuilder
public abstract class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>> extends Object
Support class that simplifies the creation of aWebConnectionthat usesMockMvcand optionally delegates to a realWebConnectionfor specific requests.The default is to use
MockMvcfor requests tolocalhostand otherwise use a realWebConnection.- Since:
- 4.2
- Author:
- Rob Winch, Sam Brannen
Constructor Summary
Constructors Modifier Constructor Description protectedMockMvcWebConnectionBuilderSupport(MockMvc mockMvc)Create a new instance using the suppliedMockMvcinstance.protectedMockMvcWebConnectionBuilderSupport(WebApplicationContext context)Create a new instance using the suppliedWebApplicationContext.protectedMockMvcWebConnectionBuilderSupport(WebApplicationContext context, MockMvcConfigurer configurer)Create a new instance using the suppliedWebApplicationContextandMockMvcConfigurer.
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description TalwaysUseMockMvc()Specify thatMockMvcshould always be used regardless of what the request looks like.TcontextPath(String contextPath)Set the context path to use.protected com.gargoylesoftware.htmlunit.WebConnectioncreateConnection(com.gargoylesoftware.htmlunit.WebClient webClient)Create a newWebConnectionthat will use aMockMvcinstance if one of the specifiedWebRequestMatcherinstances matches.protected com.gargoylesoftware.htmlunit.WebConnectioncreateConnection(com.gargoylesoftware.htmlunit.WebConnection defaultConnection)Deprecated.UsecreateConnection(WebClient)insteadTuseMockMvc(WebRequestMatcher... matchers)Add additionalWebRequestMatcherinstances that will ensure thatMockMvcis used to process the request, if such a matcher matches against the web request.TuseMockMvcForHosts(String... hosts)Add additionalWebRequestMatcherinstances that returntrueif a supplied host matches — for example,"example.com"or"example.com:8080".
Constructor Detail
MockMvcWebConnectionBuilderSupport
protected MockMvcWebConnectionBuilderSupport(MockMvc mockMvc)
Create a new instance using the suppliedMockMvcinstance.- Parameters:
mockMvc- theMockMvcinstance to use; nevernull
MockMvcWebConnectionBuilderSupport
protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context)
Create a new instance using the suppliedWebApplicationContext.- Parameters:
context- theWebApplicationContextto create aMockMvcinstance from; nevernull
MockMvcWebConnectionBuilderSupport
protected MockMvcWebConnectionBuilderSupport(WebApplicationContext context, MockMvcConfigurer configurer)
Create a new instance using the suppliedWebApplicationContextandMockMvcConfigurer.- Parameters:
context- theWebApplicationContextto create aMockMvcinstance from; nevernullconfigurer- the MockMvcConfigurer to apply; nevernull
Method Detail
contextPath
public T contextPath(String contextPath)
Set the context path to use.If the supplied value is
nullor empty, the first path segment of the request URL is assumed to be the context path.Default is
"".- Parameters:
contextPath- the context path to use- Returns:
- this builder for further customization
alwaysUseMockMvc
public T alwaysUseMockMvc()
Specify thatMockMvcshould always be used regardless of what the request looks like.- Returns:
- this builder for further customization
useMockMvc
public T useMockMvc(WebRequestMatcher... matchers)
Add additionalWebRequestMatcherinstances that will ensure thatMockMvcis used to process the request, if such a matcher matches against the web request.- Parameters:
matchers- additionalWebRequestMatcherinstances- Returns:
- this builder for further customization
useMockMvcForHosts
public T useMockMvcForHosts(String... hosts)
Add additionalWebRequestMatcherinstances that returntrueif a supplied host matches — for example,"example.com"or"example.com:8080".- Parameters:
hosts- additional hosts that ensureMockMvcgets invoked- Returns:
- this builder for further customization
createConnection
@Deprecated protected final com.gargoylesoftware.htmlunit.WebConnection createConnection(com.gargoylesoftware.htmlunit.WebConnection defaultConnection)
Deprecated.UsecreateConnection(WebClient)insteadCreate a newWebConnectionthat will use aMockMvcinstance if one of the specifiedWebRequestMatcherinstances matches.- Parameters:
defaultConnection- the default WebConnection to use if none of the specifiedWebRequestMatcherinstances matches; nevernull- Returns:
- a new
WebConnectionthat will use aMockMvcinstance if one of the specifiedWebRequestMatchermatches - See Also:
alwaysUseMockMvc(),useMockMvc(WebRequestMatcher...),useMockMvcForHosts(String...)
createConnection
protected final com.gargoylesoftware.htmlunit.WebConnection createConnection(com.gargoylesoftware.htmlunit.WebClient webClient)
Create a newWebConnectionthat will use aMockMvcinstance if one of the specifiedWebRequestMatcherinstances matches.- Parameters:
webClient- the WebClient to use if none of the specifiedWebRequestMatcherinstances matches (nevernull)- Returns:
- a new
WebConnectionthat will use aMockMvcinstance if one of the specifiedWebRequestMatchermatches - Since:
- 4.3
- See Also:
alwaysUseMockMvc(),useMockMvc(WebRequestMatcher...),useMockMvcForHosts(String...)