Class MockMvcHtmlUnitDriverBuilder
- java.lang.Object
- org.springframework.test.web.servlet.htmlunit.MockMvcWebConnectionBuilderSupport<MockMvcHtmlUnitDriverBuilder>
- org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder
public class MockMvcHtmlUnitDriverBuilder extends MockMvcWebConnectionBuilderSupport<MockMvcHtmlUnitDriverBuilder>
MockMvcHtmlUnitDriverBuildersimplifies the building of anHtmlUnitDriverthat delegates toMockMvcand optionally delegates to an actual connection for specific requests.By default, the driver will delegate to
MockMvcto handle requests tolocalhostand to aWebClientto handle any other URL (i.e. to perform an actual HTTP request).- Since:
- 4.2
- Author:
- Rob Winch, Sam Brannen
- See Also:
mockMvcSetup(MockMvc),webAppContextSetup(WebApplicationContext),webAppContextSetup(WebApplicationContext, MockMvcConfigurer),javascriptEnabled(boolean),withDelegate(WebConnectionHtmlUnitDriver),build()
Constructor Summary
Constructors Modifier Constructor Description protectedMockMvcHtmlUnitDriverBuilder(MockMvc mockMvc)protectedMockMvcHtmlUnitDriverBuilder(WebApplicationContext context)protectedMockMvcHtmlUnitDriverBuilder(WebApplicationContext context, MockMvcConfigurer configurer)
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.openqa.selenium.htmlunit.HtmlUnitDriverbuild()Build theHtmlUnitDriverconfigured via this builder.MockMvcHtmlUnitDriverBuilderjavascriptEnabled(boolean javascriptEnabled)Specify whether JavaScript should be enabled.static MockMvcHtmlUnitDriverBuildermockMvcSetup(MockMvc mockMvc)Create a newMockMvcHtmlUnitDriverBuilderbased on the suppliedMockMvcinstance.static MockMvcHtmlUnitDriverBuilderwebAppContextSetup(WebApplicationContext context)Create a newMockMvcHtmlUnitDriverBuilderbased on the suppliedWebApplicationContext.static MockMvcHtmlUnitDriverBuilderwebAppContextSetup(WebApplicationContext context, MockMvcConfigurer configurer)Create a newMockMvcHtmlUnitDriverBuilderbased on the suppliedWebApplicationContextandMockMvcConfigurer.MockMvcHtmlUnitDriverBuilderwithDelegate(WebConnectionHtmlUnitDriver driver)Methods inherited from class org.springframework.test.web.servlet.htmlunit.MockMvcWebConnectionBuilderSupport
alwaysUseMockMvc, contextPath, createConnection, createConnection, useMockMvc, useMockMvcForHosts
Constructor Detail
MockMvcHtmlUnitDriverBuilder
protected MockMvcHtmlUnitDriverBuilder(MockMvc mockMvc)
MockMvcHtmlUnitDriverBuilder
protected MockMvcHtmlUnitDriverBuilder(WebApplicationContext context)
MockMvcHtmlUnitDriverBuilder
protected MockMvcHtmlUnitDriverBuilder(WebApplicationContext context, MockMvcConfigurer configurer)
Method Detail
mockMvcSetup
public static MockMvcHtmlUnitDriverBuilder mockMvcSetup(MockMvc mockMvc)
Create a newMockMvcHtmlUnitDriverBuilderbased on the suppliedMockMvcinstance.- Parameters:
mockMvc- theMockMvcinstance to use (nevernull)- Returns:
- the MockMvcHtmlUnitDriverBuilder to customize
webAppContextSetup
public static MockMvcHtmlUnitDriverBuilder webAppContextSetup(WebApplicationContext context)
Create a newMockMvcHtmlUnitDriverBuilderbased on the suppliedWebApplicationContext.- Parameters:
context- theWebApplicationContextto create aMockMvcinstance from (nevernull)- Returns:
- the MockMvcHtmlUnitDriverBuilder to customize
webAppContextSetup
public static MockMvcHtmlUnitDriverBuilder webAppContextSetup(WebApplicationContext context, MockMvcConfigurer configurer)
Create a newMockMvcHtmlUnitDriverBuilderbased on the suppliedWebApplicationContextandMockMvcConfigurer.- Parameters:
context- theWebApplicationContextto create aMockMvcinstance from (nevernull)configurer- theMockMvcConfigurerto apply (nevernull)- Returns:
- the MockMvcHtmlUnitDriverBuilder to customize
javascriptEnabled
public MockMvcHtmlUnitDriverBuilder javascriptEnabled(boolean javascriptEnabled)
Specify whether JavaScript should be enabled.Default is
true.- Parameters:
javascriptEnabled-trueif JavaScript should be enabled- Returns:
- this builder for further customizations
- See Also:
build()
withDelegate
public MockMvcHtmlUnitDriverBuilder withDelegate(WebConnectionHtmlUnitDriver driver)
Supply theWebConnectionHtmlUnitDriverthat the driver built by this builder should delegate to when processing non-matching requests.- Parameters:
driver- theWebConnectionHtmlUnitDriverto delegate to for requests that do not match (nevernull)- Returns:
- this builder for further customizations
- See Also:
build()
build
public org.openqa.selenium.htmlunit.HtmlUnitDriver build()
Build theHtmlUnitDriverconfigured via this builder.The returned driver will use the configured
MockMvcinstance for processing any matching requests and a delegateHtmlUnitDriverfor all other requests.If a delegate has been explicitly configured, it will be used; otherwise, a default
WebConnectionHtmlUnitDriverwith theBrowserVersionset toCHROMEwill be configured as the delegate.- Returns:
- the
HtmlUnitDriverto use - See Also:
withDelegate(WebConnectionHtmlUnitDriver)