Upgrade to HtmlUnit 2.25 and Jackson 2.9 PR1

Includes Log4J 2.8.1 and Selenium 3.2 as well.

Issue: SPR-15319
This commit is contained in:
Juergen Hoeller 2017-03-06 17:54:28 +01:00
parent 47c4cf7abf
commit e61e8d5062
5 changed files with 50 additions and 55 deletions

View File

@ -55,7 +55,7 @@ configure(allprojects) { project ->
ext.httpasyncVersion = "4.1.3"
ext.httpclientVersion = "4.5.3"
ext.interceptorApiVersion = "1.2"
ext.jackson2Version = "2.8.7"
ext.jackson2Version = "2.9.0.pr1"
ext.javamailVersion = "1.5.6"
ext.jaxbVersion = "2.2.11"
ext.jaxwsVersion = "2.2.11"
@ -71,9 +71,8 @@ configure(allprojects) { project ->
ext.junitJupiterVersion = '5.0.0-M3'
ext.junitPlatformVersion = '1.0.0-M3'
ext.kotlinVersion = "1.1.0" // also change kotlin-gradle-plugin version when upgrading
ext.log4jVersion = '2.8'
ext.log4jVersion = '2.8.1'
ext.nettyVersion = "4.1.8.Final"
ext.okhttpVersion = "2.7.5"
ext.okhttp3Version = "3.6.0"
ext.poiVersion = "3.15"
ext.protobufVersion = "3.1.0"
@ -763,7 +762,6 @@ project("spring-web") {
optional("org.apache.httpcomponents:httpclient:${httpclientVersion}")
optional("org.apache.httpcomponents:httpasyncclient:${httpasyncVersion}")
optional("io.netty:netty-all:${nettyVersion}")
optional("com.squareup.okhttp:okhttp:${okhttpVersion}")
optional("com.squareup.okhttp3:okhttp:${okhttp3Version}")
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")
optional("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${jackson2Version}")
@ -972,7 +970,7 @@ project("spring-webmvc") {
testCompile("org.hibernate:hibernate-validator:${hibval5Version}")
testCompile("org.apache.httpcomponents:httpclient:${httpclientVersion}")
testCompile("commons-fileupload:commons-fileupload:${fileuploadVersion}")
testCompile("commons-io:commons-io:1.3")
testCompile("commons-io:commons-io:2.5")
testCompile("joda-time:joda-time:${jodaVersion}")
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
testCompile("org.mozilla:rhino:1.7.7.1")
@ -1074,9 +1072,9 @@ project("spring-test") {
optional("org.codehaus.groovy:groovy-all:${groovyVersion}")
optional("org.hamcrest:hamcrest-core:${hamcrestVersion}")
optional("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
optional("net.sourceforge.htmlunit:htmlunit:2.24")
optional("org.seleniumhq.selenium:htmlunit-driver:2.24")
optional("org.seleniumhq.selenium:selenium-java:3.1.0") {
optional("net.sourceforge.htmlunit:htmlunit:2.25")
optional("org.seleniumhq.selenium:htmlunit-driver:2.25")
optional("org.seleniumhq.selenium:selenium-java:3.2.0") {
exclude group: "io.netty", module: "netty"
}
optional("org.skyscreamer:jsonassert:1.4.0")

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,6 +19,8 @@ package org.springframework.test.web.servlet.htmlunit;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
@ -59,7 +61,7 @@ import org.springframework.web.util.UriComponentsBuilder;
* Internal class used to transform a {@link WebRequest} into a
* {@link MockHttpServletRequest} using Spring MVC Test's {@link RequestBuilder}.
*
* <p>By default the first path segment of the URL is used as the contextPath.
* <p>By default the first path segment of the URL is used as the context path.
* To override this default see {@link #setContextPath(String)}.
*
* @author Rob Winch
@ -71,6 +73,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
private static final Pattern LOCALE_PATTERN = Pattern.compile("^\\s*(\\w{2})(?:-(\\w{2}))?(?:;q=(\\d+\\.\\d+))?$");
private final Map<String, MockHttpSession> sessions;
private final WebClient webClient;
@ -98,23 +101,23 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
Assert.notNull(sessions, "Sessions Map must not be null");
Assert.notNull(webClient, "WebClient must not be null");
Assert.notNull(webRequest, "WebRequest must not be null");
this.sessions = sessions;
this.webClient = webClient;
this.webRequest = webRequest;
}
public MockHttpServletRequest buildRequest(ServletContext servletContext) {
String charset = getCharset();
Charset charset = getCharset();
String httpMethod = this.webRequest.getHttpMethod().name();
UriComponents uriComponents = uriComponents();
MockHttpServletRequest request = new HtmlUnitMockHttpServletRequest(
servletContext, httpMethod, uriComponents.getPath());
parent(request, this.parentBuilder);
request.setServerName(uriComponents.getHost()); // needs to be first for additional headers
request.setServerName(uriComponents.getHost()); // needs to be first for additional headers
authType(request);
request.setCharacterEncoding(charset);
request.setCharacterEncoding(charset.name());
content(request, charset);
contextPath(request, uriComponents);
contentType(request);
@ -132,6 +135,11 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
return postProcess(request);
}
private Charset getCharset() {
Charset charset = this.webRequest.getCharset();
return (charset != null ? charset : StandardCharsets.ISO_8859_1);
}
private MockHttpServletRequest postProcess(MockHttpServletRequest request) {
if (this.parentPostProcessor != null) {
request = this.parentPostProcessor.postProcessRequest(request);
@ -220,17 +228,12 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
}
}
private void content(MockHttpServletRequest request, String charset) {
private void content(MockHttpServletRequest request, Charset charset) {
String requestBody = this.webRequest.getRequestBody();
if (requestBody == null) {
return;
}
try {
request.setContent(requestBody.getBytes(charset));
}
catch (UnsupportedEncodingException ex) {
throw new IllegalStateException(ex);
}
request.setContent(requestBody.getBytes(charset));
}
private void contentType(MockHttpServletRequest request) {
@ -301,14 +304,6 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
}
}
private String getCharset() {
String charset = this.webRequest.getCharset();
if (charset == null) {
return "ISO-8859-1";
}
return charset;
}
private String header(String headerName) {
return this.webRequest.getAdditionalHeaders().get(headerName);
}

View File

@ -56,6 +56,13 @@ import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class DelegatingWebConnectionTests {
private DelegatingWebConnection webConnection;
private WebRequest request;
private WebResponse expectedResponse;
@Mock
private WebRequestMatcher matcher1;
@ -72,15 +79,8 @@ public class DelegatingWebConnectionTests {
private WebConnection connection2;
private DelegatingWebConnection webConnection;
private WebRequest request;
private WebResponse expectedResponse;
@Before
public void setUp() throws Exception {
public void setup() throws Exception {
request = new WebRequest(new URL("http://localhost/"));
WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections.<NameValuePair> emptyList());
expectedResponse = new WebResponse(data, request, 100L);
@ -88,6 +88,7 @@ public class DelegatingWebConnectionTests {
new DelegateWebConnection(matcher1, connection1), new DelegateWebConnection(matcher2, connection2));
}
@Test
public void getResponseDefault() throws Exception {
when(defaultConnection.getResponse(request)).thenReturn(expectedResponse);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.test.web.servlet.htmlunit;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@ -28,9 +29,12 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
import com.gargoylesoftware.htmlunit.FormEncodingType;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import org.apache.commons.io.IOUtils;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.junit.Before;
import org.junit.Test;
@ -41,15 +45,10 @@ import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import static java.util.Arrays.asList;
import static java.util.Arrays.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
/**
* Unit tests for {@link HtmlUnitRequestBuilder}.
@ -72,12 +71,13 @@ public class HtmlUnitRequestBuilderTests {
@Before
public void setUp() throws Exception {
public void setup() throws Exception {
webRequest = new WebRequest(new URL("http://example.com:80/test/this/here"));
webRequest.setHttpMethod(HttpMethod.GET);
requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);
}
// --- constructor
@Test(expected = IllegalArgumentException.class)
@ -95,6 +95,7 @@ public class HtmlUnitRequestBuilderTests {
new HtmlUnitRequestBuilder(sessions, webClient, null);
}
// --- buildRequest
@Test
@ -114,12 +115,11 @@ public class HtmlUnitRequestBuilderTests {
@Test
public void buildRequestCharacterEncoding() {
String charset = "UTF-8";
webRequest.setCharset(charset);
webRequest.setCharset(StandardCharsets.UTF_8);
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
assertThat(actualRequest.getCharacterEncoding(), equalTo(charset));
assertThat(actualRequest.getCharacterEncoding(), equalTo("UTF-8"));
}
@Test
@ -151,7 +151,7 @@ public class HtmlUnitRequestBuilderTests {
assertThat(actualRequest.getHeader("Content-Type"), equalTo(contentType));
}
@Test // SPR-14916
@Test // SPR-14916
public void buildRequestContentTypeWithFormSubmission() {
webRequest.setEncodingType(FormEncodingType.URL_ENCODED);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.springframework.test.web.servlet.htmlunit;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
import javax.servlet.http.Cookie;
@ -47,7 +48,7 @@ public class MockWebResponseBuilderTests {
@Before
public void setUp() throws Exception {
public void setup() throws Exception {
this.webRequest = new WebRequest(new URL("http://example.com:80/test/this/here"));
this.responseBuilder = new MockWebResponseBuilder(System.currentTimeMillis(), this.webRequest, this.response);
}
@ -81,7 +82,7 @@ public class MockWebResponseBuilderTests {
this.response.addHeader("Content-Type", "text/html; charset=UTF-8");
WebResponse webResponse = this.responseBuilder.build();
assertThat(webResponse.getContentCharset(), equalTo("UTF-8"));
assertThat(webResponse.getContentCharset(), equalTo(StandardCharsets.UTF_8));
}
@Test