Class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>>
java.lang.Object
org.springframework.test.web.servlet.htmlunit.MockMvcWebConnectionBuilderSupport<T>
- Type Parameters:
- T- a self reference to the builder type
- Direct Known Subclasses:
- MockMvcHtmlUnitDriverBuilder,- MockMvcWebClientBuilder
public abstract class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebConnectionBuilderSupport<T>>
extends Object
Support class that simplifies the creation of a 
WebConnection that
 uses MockMvc and optionally delegates to a real WebConnection
 for specific requests.
 The default is to use MockMvc for requests to localhost
 and otherwise use a real WebConnection.
- Since:
- 4.2
- Author:
- Rob Winch, Sam Brannen
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCreate a new instance using the suppliedMockMvcinstance.protectedCreate a new instance using the suppliedWebApplicationContext.protectedMockMvcWebConnectionBuilderSupport(WebApplicationContext context, MockMvcConfigurer configurer) Create a new instance using the suppliedWebApplicationContextandMockMvcConfigurer.
- 
Method SummaryModifier and TypeMethodDescriptionSpecify thatMockMvcshould always be used regardless of what the request looks like.contextPath(String contextPath) Set the context path to use.protected final com.gargoylesoftware.htmlunit.WebConnectioncreateConnection(com.gargoylesoftware.htmlunit.WebClient webClient) Create a newWebConnectionthat will use aMockMvcinstance if one of the specifiedWebRequestMatcherinstances matches.useMockMvc(WebRequestMatcher... matchers) Add additionalWebRequestMatcherinstances that will ensure thatMockMvcis used to process the request, if such a matcher matches against the web request.useMockMvcForHosts(String... hosts) Add additionalWebRequestMatcherinstances that returntrueif a supplied host matches — for example,"example.com"or"example.com:8080".
- 
Constructor Details- 
MockMvcWebConnectionBuilderSupportCreate a new instance using the suppliedMockMvcinstance.- Parameters:
- mockMvc- the- MockMvcinstance to use; never- null
 
- 
MockMvcWebConnectionBuilderSupportCreate a new instance using the suppliedWebApplicationContext.- Parameters:
- context- the- WebApplicationContextto create a- MockMvcinstance from; never- null
 
- 
MockMvcWebConnectionBuilderSupportprotected MockMvcWebConnectionBuilderSupport(WebApplicationContext context, MockMvcConfigurer configurer) Create a new instance using the suppliedWebApplicationContextandMockMvcConfigurer.- Parameters:
- context- the- WebApplicationContextto create a- MockMvcinstance from; never- null
- configurer- the MockMvcConfigurer to apply; never- null
 
 
- 
- 
Method Details- 
contextPathSet 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
 
- 
alwaysUseMockMvcSpecify thatMockMvcshould always be used regardless of what the request looks like.- Returns:
- this builder for further customization
 
- 
useMockMvcAdd additionalWebRequestMatcherinstances that will ensure thatMockMvcis used to process the request, if such a matcher matches against the web request.- Parameters:
- matchers- additional- WebRequestMatcherinstances
- Returns:
- this builder for further customization
 
- 
useMockMvcForHostsAdd additionalWebRequestMatcherinstances that returntrueif a supplied host matches — for example,"example.com"or"example.com:8080".- Parameters:
- hosts- additional hosts that ensure- MockMvcgets invoked
- Returns:
- this builder for further customization
 
- 
createConnectionprotected 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 specified- WebRequestMatcherinstances matches (never- null)
- Returns:
- a new WebConnectionthat will use aMockMvcinstance if one of the specifiedWebRequestMatchermatches
- Since:
- 4.3
- See Also:
 
 
-