Upgrade to HtmlUnit 2.19
This upgrade includes AutoCloseable support for HtmlUnit WebConnections as introduced in 2.19, while remaining compatible with 2.18. Issue: SPR-13686
This commit is contained in:
parent
ce5887795b
commit
5b901852e6
|
|
@ -45,7 +45,7 @@ configure(allprojects) { project ->
|
||||||
ext.hibval4Version = "4.3.2.Final"
|
ext.hibval4Version = "4.3.2.Final"
|
||||||
ext.hibval5Version = "5.2.2.Final"
|
ext.hibval5Version = "5.2.2.Final"
|
||||||
ext.hsqldbVersion = "2.3.3"
|
ext.hsqldbVersion = "2.3.3"
|
||||||
ext.htmlunitVersion = "2.18"
|
ext.htmlunitVersion = "2.19"
|
||||||
ext.httpasyncVersion = "4.1.1"
|
ext.httpasyncVersion = "4.1.1"
|
||||||
ext.httpclientVersion = "4.5.1"
|
ext.httpclientVersion = "4.5.1"
|
||||||
ext.jackson2Version = "2.6.3"
|
ext.jackson2Version = "2.6.3"
|
||||||
|
|
@ -66,7 +66,7 @@ configure(allprojects) { project ->
|
||||||
ext.reactorVersion = "2.0.7.RELEASE"
|
ext.reactorVersion = "2.0.7.RELEASE"
|
||||||
ext.romeVersion = "1.5.1"
|
ext.romeVersion = "1.5.1"
|
||||||
ext.seleniumVersion = "2.48.2"
|
ext.seleniumVersion = "2.48.2"
|
||||||
ext.slf4jVersion = "1.7.12"
|
ext.slf4jVersion = "1.7.13"
|
||||||
ext.snakeyamlVersion = "1.16"
|
ext.snakeyamlVersion = "1.16"
|
||||||
ext.snifferVersion = "1.14"
|
ext.snifferVersion = "1.14"
|
||||||
ext.testngVersion = "6.9.9"
|
ext.testngVersion = "6.9.9"
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@ import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebConnection;
|
import com.gargoylesoftware.htmlunit.WebConnection;
|
||||||
import com.gargoylesoftware.htmlunit.WebRequest;
|
import com.gargoylesoftware.htmlunit.WebRequest;
|
||||||
import com.gargoylesoftware.htmlunit.WebResponse;
|
import com.gargoylesoftware.htmlunit.WebResponse;
|
||||||
|
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link WebConnection} that allows delegating to various
|
* Implementation of {@link WebConnection} that allows delegating to various
|
||||||
* {@code WebConnection} implementations.
|
* {@code WebConnection} implementations.
|
||||||
|
|
@ -62,8 +62,8 @@ public final class DelegatingWebConnection implements WebConnection {
|
||||||
|
|
||||||
|
|
||||||
public DelegatingWebConnection(WebConnection defaultConnection, List<DelegateWebConnection> connections) {
|
public DelegatingWebConnection(WebConnection defaultConnection, List<DelegateWebConnection> connections) {
|
||||||
Assert.notNull(defaultConnection, "defaultConnection must not be null");
|
Assert.notNull(defaultConnection, "Default WebConnection must not be null");
|
||||||
Assert.notEmpty(connections, "connections must not be empty");
|
Assert.notEmpty(connections, "Connections List must not be empty");
|
||||||
this.connections = connections;
|
this.connections = connections;
|
||||||
this.defaultConnection = defaultConnection;
|
this.defaultConnection = defaultConnection;
|
||||||
}
|
}
|
||||||
|
|
@ -72,6 +72,7 @@ public final class DelegatingWebConnection implements WebConnection {
|
||||||
this(defaultConnection, Arrays.asList(connections));
|
this(defaultConnection, Arrays.asList(connections));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WebResponse getResponse(WebRequest request) throws IOException {
|
public WebResponse getResponse(WebRequest request) throws IOException {
|
||||||
for (DelegateWebConnection connection : this.connections) {
|
for (DelegateWebConnection connection : this.connections) {
|
||||||
|
|
@ -82,6 +83,10 @@ public final class DelegatingWebConnection implements WebConnection {
|
||||||
return this.defaultConnection.getResponse(request);
|
return this.defaultConnection.getResponse(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class DelegateWebConnection {
|
public static final class DelegateWebConnection {
|
||||||
|
|
||||||
|
|
@ -89,18 +94,17 @@ public final class DelegatingWebConnection implements WebConnection {
|
||||||
|
|
||||||
private final WebConnection delegate;
|
private final WebConnection delegate;
|
||||||
|
|
||||||
|
|
||||||
public DelegateWebConnection(WebRequestMatcher matcher, WebConnection delegate) {
|
public DelegateWebConnection(WebRequestMatcher matcher, WebConnection delegate) {
|
||||||
this.matcher = matcher;
|
this.matcher = matcher;
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebRequestMatcher getMatcher() {
|
private WebRequestMatcher getMatcher() {
|
||||||
return matcher;
|
return this.matcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebConnection getDelegate() {
|
private WebConnection getDelegate() {
|
||||||
return delegate;
|
return this.delegate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ final class ForwardRequestPostProcessor implements RequestPostProcessor {
|
||||||
|
|
||||||
|
|
||||||
public ForwardRequestPostProcessor(String forwardUrl) {
|
public ForwardRequestPostProcessor(String forwardUrl) {
|
||||||
Assert.hasText(forwardUrl, "forwardUrl must not be null or empty");
|
Assert.hasText(forwardUrl, "Forward URL must not be null or empty");
|
||||||
this.forwardUrl = forwardUrl;
|
this.forwardUrl = forwardUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,11 @@ import javax.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.CookieManager;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebRequest;
|
||||||
|
import com.gargoylesoftware.htmlunit.util.NameValuePair;
|
||||||
|
|
||||||
import org.springframework.beans.Mergeable;
|
import org.springframework.beans.Mergeable;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
|
@ -46,11 +51,6 @@ import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.web.util.UriComponents;
|
import org.springframework.web.util.UriComponents;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.CookieManager;
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient;
|
|
||||||
import com.gargoylesoftware.htmlunit.WebRequest;
|
|
||||||
import com.gargoylesoftware.htmlunit.util.NameValuePair;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal class used to transform a {@link WebRequest} into a
|
* Internal class used to transform a {@link WebRequest} into a
|
||||||
* {@link MockHttpServletRequest} using Spring MVC Test's {@link RequestBuilder}.
|
* {@link MockHttpServletRequest} using Spring MVC Test's {@link RequestBuilder}.
|
||||||
|
|
@ -91,9 +91,9 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
||||||
* {@link MockHttpServletRequest}; never {@code null}
|
* {@link MockHttpServletRequest}; never {@code null}
|
||||||
*/
|
*/
|
||||||
public HtmlUnitRequestBuilder(Map<String, MockHttpSession> sessions, WebClient webClient, WebRequest webRequest) {
|
public HtmlUnitRequestBuilder(Map<String, MockHttpSession> sessions, WebClient webClient, WebRequest webRequest) {
|
||||||
Assert.notNull(sessions, "sessions map must not be null");
|
Assert.notNull(sessions, "Sessions Map must not be null");
|
||||||
Assert.notNull(webClient, "webClient must not be null");
|
Assert.notNull(webClient, "WebClient must not be null");
|
||||||
Assert.notNull(webRequest, "webRequest must not be null");
|
Assert.notNull(webRequest, "WebRequest must not be null");
|
||||||
|
|
||||||
this.sessions = sessions;
|
this.sessions = sessions;
|
||||||
this.webClient = webClient;
|
this.webClient = webClient;
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.test.web.servlet.htmlunit;
|
package org.springframework.test.web.servlet.htmlunit;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
|
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code MockMvcWebClientBuilder} simplifies the creation of an HtmlUnit
|
* {@code MockMvcWebClientBuilder} simplifies the creation of an HtmlUnit
|
||||||
* {@link WebClient} that delegates to a {@link MockMvc} instance.
|
* {@link WebClient} that delegates to a {@link MockMvc} instance.
|
||||||
|
|
@ -57,6 +57,7 @@ public class MockMvcWebClientBuilder extends MockMvcWebConnectionBuilderSupport<
|
||||||
super(context, configurer);
|
super(context, configurer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@code MockMvcWebClientBuilder} based on the supplied
|
* Create a new {@code MockMvcWebClientBuilder} based on the supplied
|
||||||
* {@link MockMvc} instance.
|
* {@link MockMvc} instance.
|
||||||
|
|
@ -104,7 +105,7 @@ public class MockMvcWebClientBuilder extends MockMvcWebConnectionBuilderSupport<
|
||||||
* @see #build()
|
* @see #build()
|
||||||
*/
|
*/
|
||||||
public MockMvcWebClientBuilder withDelegate(WebClient webClient) {
|
public MockMvcWebClientBuilder withDelegate(WebClient webClient) {
|
||||||
Assert.notNull(webClient, "webClient must not be null");
|
Assert.notNull(webClient, "WebClient must not be null");
|
||||||
webClient.setWebConnection(createConnection(webClient.getWebConnection()));
|
webClient.setWebConnection(createConnection(webClient.getWebConnection()));
|
||||||
this.webClient = webClient;
|
this.webClient = webClient;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,11 @@ import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebConnection;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebRequest;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebResponse;
|
||||||
|
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
import org.springframework.mock.web.MockHttpSession;
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
@ -27,11 +32,6 @@ import org.springframework.test.web.servlet.RequestBuilder;
|
||||||
import org.springframework.test.web.servlet.ResultActions;
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient;
|
|
||||||
import com.gargoylesoftware.htmlunit.WebConnection;
|
|
||||||
import com.gargoylesoftware.htmlunit.WebRequest;
|
|
||||||
import com.gargoylesoftware.htmlunit.WebResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code MockMvcWebConnection} enables {@link MockMvc} to transform a
|
* {@code MockMvcWebConnection} enables {@link MockMvc} to transform a
|
||||||
* {@link WebRequest} into a {@link WebResponse}.
|
* {@link WebRequest} into a {@link WebResponse}.
|
||||||
|
|
@ -86,7 +86,7 @@ public final class MockMvcWebConnection implements WebConnection {
|
||||||
* @param contextPath the contextPath to use
|
* @param contextPath the contextPath to use
|
||||||
*/
|
*/
|
||||||
public MockMvcWebConnection(MockMvc mockMvc, String contextPath) {
|
public MockMvcWebConnection(MockMvc mockMvc, String contextPath) {
|
||||||
Assert.notNull(mockMvc, "mockMvc must not be null");
|
Assert.notNull(mockMvc, "MockMvc must not be null");
|
||||||
validateContextPath(contextPath);
|
validateContextPath(contextPath);
|
||||||
|
|
||||||
this.webClient = new WebClient();
|
this.webClient = new WebClient();
|
||||||
|
|
@ -94,13 +94,19 @@ public final class MockMvcWebConnection implements WebConnection {
|
||||||
this.contextPath = contextPath;
|
this.contextPath = contextPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setWebClient(WebClient webClient) {
|
||||||
|
Assert.notNull(webClient, "WebClient must not be null");
|
||||||
|
this.webClient = webClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public WebResponse getResponse(WebRequest webRequest) throws IOException {
|
public WebResponse getResponse(WebRequest webRequest) throws IOException {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
HtmlUnitRequestBuilder requestBuilder = new HtmlUnitRequestBuilder(this.sessions, this.webClient, webRequest);
|
HtmlUnitRequestBuilder requestBuilder = new HtmlUnitRequestBuilder(this.sessions, this.webClient, webRequest);
|
||||||
requestBuilder.setContextPath(this.contextPath);
|
requestBuilder.setContextPath(this.contextPath);
|
||||||
|
|
||||||
MockHttpServletResponse httpServletResponse = getResponse(requestBuilder);
|
MockHttpServletResponse httpServletResponse = getResponse(requestBuilder);
|
||||||
|
|
||||||
String forwardedUrl = httpServletResponse.getForwardedUrl();
|
String forwardedUrl = httpServletResponse.getForwardedUrl();
|
||||||
while (forwardedUrl != null) {
|
while (forwardedUrl != null) {
|
||||||
requestBuilder.setForwardPostProcessor(new ForwardRequestPostProcessor(forwardedUrl));
|
requestBuilder.setForwardPostProcessor(new ForwardRequestPostProcessor(forwardedUrl));
|
||||||
|
|
@ -111,23 +117,23 @@ public final class MockMvcWebConnection implements WebConnection {
|
||||||
return new MockWebResponseBuilder(startTime, webRequest, httpServletResponse).build();
|
return new MockWebResponseBuilder(startTime, webRequest, httpServletResponse).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWebClient(WebClient webClient) {
|
|
||||||
Assert.notNull(webClient, "webClient must not be null");
|
|
||||||
this.webClient = webClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MockHttpServletResponse getResponse(RequestBuilder requestBuilder) throws IOException {
|
private MockHttpServletResponse getResponse(RequestBuilder requestBuilder) throws IOException {
|
||||||
ResultActions resultActions;
|
ResultActions resultActions;
|
||||||
try {
|
try {
|
||||||
resultActions = this.mockMvc.perform(requestBuilder);
|
resultActions = this.mockMvc.perform(requestBuilder);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception ex) {
|
||||||
throw (IOException) new IOException(e.getMessage()).initCause(e);
|
throw new IOException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultActions.andReturn().getResponse();
|
return resultActions.andReturn().getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the supplied {@code contextPath}.
|
* Validate the supplied {@code contextPath}.
|
||||||
* <p>If the value is not {@code null}, it must conform to
|
* <p>If the value is not {@code null}, it must conform to
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,14 @@ package org.springframework.test.web.servlet.htmlunit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.WebConnection;
|
||||||
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
|
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebConnection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Support class that simplifies the creation of a {@link WebConnection} that
|
* Support class that simplifies the creation of a {@link WebConnection} that
|
||||||
* uses {@link MockMvc} and optionally delegates to a real {@link WebConnection}
|
* uses {@link MockMvc} and optionally delegates to a real {@link WebConnection}
|
||||||
|
|
@ -55,7 +55,7 @@ public abstract class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebCon
|
||||||
* @param mockMvc the {@code MockMvc} instance to use; never {@code null}
|
* @param mockMvc the {@code MockMvc} instance to use; never {@code null}
|
||||||
*/
|
*/
|
||||||
protected MockMvcWebConnectionBuilderSupport(MockMvc mockMvc) {
|
protected MockMvcWebConnectionBuilderSupport(MockMvc mockMvc) {
|
||||||
Assert.notNull(mockMvc, "mockMvc must not be null");
|
Assert.notNull(mockMvc, "MockMvc must not be null");
|
||||||
this.mockMvc = mockMvc;
|
this.mockMvc = mockMvc;
|
||||||
this.mockMvcRequestMatchers.add(new HostRequestMatcher("localhost"));
|
this.mockMvcRequestMatchers.add(new HostRequestMatcher("localhost"));
|
||||||
}
|
}
|
||||||
|
|
@ -80,6 +80,7 @@ public abstract class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebCon
|
||||||
this(MockMvcBuilders.webAppContextSetup(context).apply(configurer).build());
|
this(MockMvcBuilders.webAppContextSetup(context).apply(configurer).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the context path to use.
|
* Set the context path to use.
|
||||||
* <p>If the supplied value is {@code null} or empty, the first path
|
* <p>If the supplied value is {@code null} or empty, the first path
|
||||||
|
|
@ -146,7 +147,7 @@ public abstract class MockMvcWebConnectionBuilderSupport<T extends MockMvcWebCon
|
||||||
* @see #useMockMvcForHosts(String...)
|
* @see #useMockMvcForHosts(String...)
|
||||||
*/
|
*/
|
||||||
protected final WebConnection createConnection(WebConnection defaultConnection) {
|
protected final WebConnection createConnection(WebConnection defaultConnection) {
|
||||||
Assert.notNull(defaultConnection, "defaultConnection must not be null");
|
Assert.notNull(defaultConnection, "Default WebConnection must not be null");
|
||||||
MockMvcWebConnection mockMvcWebConnection = new MockMvcWebConnection(this.mockMvc, this.contextPath);
|
MockMvcWebConnection mockMvcWebConnection = new MockMvcWebConnection(this.mockMvc, this.contextPath);
|
||||||
|
|
||||||
if (this.alwaysUseMockMvc) {
|
if (this.alwaysUseMockMvc) {
|
||||||
|
|
|
||||||
|
|
@ -21,16 +21,16 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebRequest;
|
import com.gargoylesoftware.htmlunit.WebRequest;
|
||||||
import com.gargoylesoftware.htmlunit.WebResponse;
|
import com.gargoylesoftware.htmlunit.WebResponse;
|
||||||
import com.gargoylesoftware.htmlunit.WebResponseData;
|
import com.gargoylesoftware.htmlunit.WebResponseData;
|
||||||
import com.gargoylesoftware.htmlunit.util.NameValuePair;
|
import com.gargoylesoftware.htmlunit.util.NameValuePair;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
|
|
@ -48,8 +48,8 @@ final class MockWebResponseBuilder {
|
||||||
|
|
||||||
|
|
||||||
public MockWebResponseBuilder(long startTime, WebRequest webRequest, MockHttpServletResponse response) {
|
public MockWebResponseBuilder(long startTime, WebRequest webRequest, MockHttpServletResponse response) {
|
||||||
Assert.notNull(webRequest, "webRequest must not be null");
|
Assert.notNull(webRequest, "WebRequest must not be null");
|
||||||
Assert.notNull(response, "response must not be null");
|
Assert.notNull(response, "HttpServletResponse must not be null");
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
this.webRequest = webRequest;
|
this.webRequest = webRequest;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
|
|
@ -63,8 +63,8 @@ final class MockWebResponseBuilder {
|
||||||
|
|
||||||
private WebResponseData webResponseData() throws IOException {
|
private WebResponseData webResponseData() throws IOException {
|
||||||
List<NameValuePair> responseHeaders = responseHeaders();
|
List<NameValuePair> responseHeaders = responseHeaders();
|
||||||
int statusCode = (this.response.getRedirectedUrl() != null ? HttpStatus.MOVED_PERMANENTLY.value()
|
int statusCode = (this.response.getRedirectedUrl() != null ?
|
||||||
: this.response.getStatus());
|
HttpStatus.MOVED_PERMANENTLY.value() : this.response.getStatus());
|
||||||
String statusMessage = statusMessage(statusCode);
|
String statusMessage = statusMessage(statusCode);
|
||||||
return new WebResponseData(this.response.getContentAsByteArray(), statusCode, statusMessage, responseHeaders);
|
return new WebResponseData(this.response.getContentAsByteArray(), statusCode, statusMessage, responseHeaders);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.test.web.servlet.htmlunit.webdriver;
|
package org.springframework.test.web.servlet.htmlunit.webdriver;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
||||||
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
@ -25,9 +27,6 @@ import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code MockMvcHtmlUnitDriverBuilder} simplifies the building of an
|
* {@code MockMvcHtmlUnitDriverBuilder} simplifies the building of an
|
||||||
* {@link HtmlUnitDriver} that delegates to {@link MockMvc} and optionally
|
* {@link HtmlUnitDriver} that delegates to {@link MockMvc} and optionally
|
||||||
|
|
@ -66,6 +65,7 @@ public class MockMvcHtmlUnitDriverBuilder extends MockMvcWebConnectionBuilderSup
|
||||||
super(context, configurer);
|
super(context, configurer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@code MockMvcHtmlUnitDriverBuilder} based on the supplied
|
* Create a new {@code MockMvcHtmlUnitDriverBuilder} based on the supplied
|
||||||
* {@link MockMvc} instance.
|
* {@link MockMvc} instance.
|
||||||
|
|
@ -99,6 +99,7 @@ public class MockMvcHtmlUnitDriverBuilder extends MockMvcWebConnectionBuilderSup
|
||||||
*/
|
*/
|
||||||
public static MockMvcHtmlUnitDriverBuilder webAppContextSetup(WebApplicationContext context,
|
public static MockMvcHtmlUnitDriverBuilder webAppContextSetup(WebApplicationContext context,
|
||||||
MockMvcConfigurer configurer) {
|
MockMvcConfigurer configurer) {
|
||||||
|
|
||||||
Assert.notNull(context, "WebApplicationContext must not be null");
|
Assert.notNull(context, "WebApplicationContext must not be null");
|
||||||
Assert.notNull(configurer, "MockMvcConfigurer must not be null");
|
Assert.notNull(configurer, "MockMvcConfigurer must not be null");
|
||||||
return new MockMvcHtmlUnitDriverBuilder(context, configurer);
|
return new MockMvcHtmlUnitDriverBuilder(context, configurer);
|
||||||
|
|
@ -126,7 +127,7 @@ public class MockMvcHtmlUnitDriverBuilder extends MockMvcWebConnectionBuilderSup
|
||||||
* @see #build()
|
* @see #build()
|
||||||
*/
|
*/
|
||||||
public MockMvcHtmlUnitDriverBuilder withDelegate(WebConnectionHtmlUnitDriver driver) {
|
public MockMvcHtmlUnitDriverBuilder withDelegate(WebConnectionHtmlUnitDriver driver) {
|
||||||
Assert.notNull(driver, "driver must not be null");
|
Assert.notNull(driver, "HtmlUnitDriver must not be null");
|
||||||
driver.setJavascriptEnabled(this.javascriptEnabled);
|
driver.setJavascriptEnabled(this.javascriptEnabled);
|
||||||
driver.setWebConnection(createConnection(driver.getWebConnection()));
|
driver.setWebConnection(createConnection(driver.getWebConnection()));
|
||||||
this.driver = driver;
|
this.driver = driver;
|
||||||
|
|
@ -146,8 +147,8 @@ public class MockMvcHtmlUnitDriverBuilder extends MockMvcWebConnectionBuilderSup
|
||||||
* @see #withDelegate(WebConnectionHtmlUnitDriver)
|
* @see #withDelegate(WebConnectionHtmlUnitDriver)
|
||||||
*/
|
*/
|
||||||
public HtmlUnitDriver build() {
|
public HtmlUnitDriver build() {
|
||||||
return (this.driver != null ? this.driver
|
return (this.driver != null ? this.driver :
|
||||||
: withDelegate(new WebConnectionHtmlUnitDriver(BrowserVersion.CHROME)).build());
|
withDelegate(new WebConnectionHtmlUnitDriver(BrowserVersion.CHROME)).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,15 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.test.web.servlet.htmlunit.webdriver;
|
package org.springframework.test.web.servlet.htmlunit.webdriver;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
import com.gargoylesoftware.htmlunit.WebConnection;
|
||||||
import org.openqa.selenium.Capabilities;
|
import org.openqa.selenium.Capabilities;
|
||||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient;
|
|
||||||
import com.gargoylesoftware.htmlunit.WebConnection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code WebConnectionHtmlUnitDriver} enables configuration of the
|
* {@code WebConnectionHtmlUnitDriver} enables configuration of the
|
||||||
* {@link WebConnection} for an {@link HtmlUnitDriver} instance.
|
* {@link WebConnection} for an {@link HtmlUnitDriver} instance.
|
||||||
|
|
@ -58,6 +57,7 @@ public class WebConnectionHtmlUnitDriver extends HtmlUnitDriver {
|
||||||
super(capabilities);
|
super(capabilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify the supplied {@link WebClient} and retain a reference to it
|
* Modify the supplied {@link WebClient} and retain a reference to it
|
||||||
* so that its {@link WebConnection} is {@linkplain #getWebConnection
|
* so that its {@link WebConnection} is {@linkplain #getWebConnection
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue