Skip to content

Commit e61e8d5

Browse files
committed
Upgrade to HtmlUnit 2.25 and Jackson 2.9 PR1
Includes Log4J 2.8.1 and Selenium 3.2 as well. Issue: SPR-15319
1 parent 47c4cf7 commit e61e8d5

File tree

5 files changed

+50
-55
lines changed

5 files changed

+50
-55
lines changed

build.gradle

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ configure(allprojects) { project ->
5555
ext.httpasyncVersion = "4.1.3"
5656
ext.httpclientVersion = "4.5.3"
5757
ext.interceptorApiVersion = "1.2"
58-
ext.jackson2Version = "2.8.7"
58+
ext.jackson2Version = "2.9.0.pr1"
5959
ext.javamailVersion = "1.5.6"
6060
ext.jaxbVersion = "2.2.11"
6161
ext.jaxwsVersion = "2.2.11"
@@ -71,9 +71,8 @@ configure(allprojects) { project ->
7171
ext.junitJupiterVersion = '5.0.0-M3'
7272
ext.junitPlatformVersion = '1.0.0-M3'
7373
ext.kotlinVersion = "1.1.0" // also change kotlin-gradle-plugin version when upgrading
74-
ext.log4jVersion = '2.8'
74+
ext.log4jVersion = '2.8.1'
7575
ext.nettyVersion = "4.1.8.Final"
76-
ext.okhttpVersion = "2.7.5"
7776
ext.okhttp3Version = "3.6.0"
7877
ext.poiVersion = "3.15"
7978
ext.protobufVersion = "3.1.0"
@@ -763,7 +762,6 @@ project("spring-web") {
763762
optional("org.apache.httpcomponents:httpclient:${httpclientVersion}")
764763
optional("org.apache.httpcomponents:httpasyncclient:${httpasyncVersion}")
765764
optional("io.netty:netty-all:${nettyVersion}")
766-
optional("com.squareup.okhttp:okhttp:${okhttpVersion}")
767765
optional("com.squareup.okhttp3:okhttp:${okhttp3Version}")
768766
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")
769767
optional("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${jackson2Version}")
@@ -972,7 +970,7 @@ project("spring-webmvc") {
972970
testCompile("org.hibernate:hibernate-validator:${hibval5Version}")
973971
testCompile("org.apache.httpcomponents:httpclient:${httpclientVersion}")
974972
testCompile("commons-fileupload:commons-fileupload:${fileuploadVersion}")
975-
testCompile("commons-io:commons-io:1.3")
973+
testCompile("commons-io:commons-io:2.5")
976974
testCompile("joda-time:joda-time:${jodaVersion}")
977975
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
978976
testCompile("org.mozilla:rhino:1.7.7.1")
@@ -1074,9 +1072,9 @@ project("spring-test") {
10741072
optional("org.codehaus.groovy:groovy-all:${groovyVersion}")
10751073
optional("org.hamcrest:hamcrest-core:${hamcrestVersion}")
10761074
optional("org.xmlunit:xmlunit-matchers:${xmlunitVersion}")
1077-
optional("net.sourceforge.htmlunit:htmlunit:2.24")
1078-
optional("org.seleniumhq.selenium:htmlunit-driver:2.24")
1079-
optional("org.seleniumhq.selenium:selenium-java:3.1.0") {
1075+
optional("net.sourceforge.htmlunit:htmlunit:2.25")
1076+
optional("org.seleniumhq.selenium:htmlunit-driver:2.25")
1077+
optional("org.seleniumhq.selenium:selenium-java:3.2.0") {
10801078
exclude group: "io.netty", module: "netty"
10811079
}
10821080
optional("org.skyscreamer:jsonassert:1.4.0")

spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@
1919
import java.io.UnsupportedEncodingException;
2020
import java.net.URL;
2121
import java.net.URLDecoder;
22+
import java.nio.charset.Charset;
23+
import java.nio.charset.StandardCharsets;
2224
import java.util.ArrayList;
2325
import java.util.Enumeration;
2426
import java.util.List;
@@ -59,7 +61,7 @@
5961
* Internal class used to transform a {@link WebRequest} into a
6062
* {@link MockHttpServletRequest} using Spring MVC Test's {@link RequestBuilder}.
6163
*
62-
* <p>By default the first path segment of the URL is used as the contextPath.
64+
* <p>By default the first path segment of the URL is used as the context path.
6365
* To override this default see {@link #setContextPath(String)}.
6466
*
6567
* @author Rob Winch
@@ -71,6 +73,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
7173

7274
private static final Pattern LOCALE_PATTERN = Pattern.compile("^\\s*(\\w{2})(?:-(\\w{2}))?(?:;q=(\\d+\\.\\d+))?$");
7375

76+
7477
private final Map<String, MockHttpSession> sessions;
7578

7679
private final WebClient webClient;
@@ -98,23 +101,23 @@ public HtmlUnitRequestBuilder(Map<String, MockHttpSession> sessions, WebClient w
98101
Assert.notNull(sessions, "Sessions Map must not be null");
99102
Assert.notNull(webClient, "WebClient must not be null");
100103
Assert.notNull(webRequest, "WebRequest must not be null");
101-
102104
this.sessions = sessions;
103105
this.webClient = webClient;
104106
this.webRequest = webRequest;
105107
}
106108

109+
107110
public MockHttpServletRequest buildRequest(ServletContext servletContext) {
108-
String charset = getCharset();
111+
Charset charset = getCharset();
109112
String httpMethod = this.webRequest.getHttpMethod().name();
110113
UriComponents uriComponents = uriComponents();
111114

112115
MockHttpServletRequest request = new HtmlUnitMockHttpServletRequest(
113116
servletContext, httpMethod, uriComponents.getPath());
114117
parent(request, this.parentBuilder);
115-
request.setServerName(uriComponents.getHost()); // needs to be first for additional headers
118+
request.setServerName(uriComponents.getHost()); // needs to be first for additional headers
116119
authType(request);
117-
request.setCharacterEncoding(charset);
120+
request.setCharacterEncoding(charset.name());
118121
content(request, charset);
119122
contextPath(request, uriComponents);
120123
contentType(request);
@@ -132,6 +135,11 @@ public MockHttpServletRequest buildRequest(ServletContext servletContext) {
132135
return postProcess(request);
133136
}
134137

138+
private Charset getCharset() {
139+
Charset charset = this.webRequest.getCharset();
140+
return (charset != null ? charset : StandardCharsets.ISO_8859_1);
141+
}
142+
135143
private MockHttpServletRequest postProcess(MockHttpServletRequest request) {
136144
if (this.parentPostProcessor != null) {
137145
request = this.parentPostProcessor.postProcessRequest(request);
@@ -220,17 +228,12 @@ private void authType(MockHttpServletRequest request) {
220228
}
221229
}
222230

223-
private void content(MockHttpServletRequest request, String charset) {
231+
private void content(MockHttpServletRequest request, Charset charset) {
224232
String requestBody = this.webRequest.getRequestBody();
225233
if (requestBody == null) {
226234
return;
227235
}
228-
try {
229-
request.setContent(requestBody.getBytes(charset));
230-
}
231-
catch (UnsupportedEncodingException ex) {
232-
throw new IllegalStateException(ex);
233-
}
236+
request.setContent(requestBody.getBytes(charset));
234237
}
235238

236239
private void contentType(MockHttpServletRequest request) {
@@ -301,14 +304,6 @@ private void processCookie(MockHttpServletRequest request, List<Cookie> cookies,
301304
}
302305
}
303306

304-
private String getCharset() {
305-
String charset = this.webRequest.getCharset();
306-
if (charset == null) {
307-
return "ISO-8859-1";
308-
}
309-
return charset;
310-
}
311-
312307
private String header(String headerName) {
313308
return this.webRequest.getAdditionalHeaders().get(headerName);
314309
}

spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/DelegatingWebConnectionTests.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
@RunWith(MockitoJUnitRunner.class)
5757
public class DelegatingWebConnectionTests {
5858

59+
private DelegatingWebConnection webConnection;
60+
61+
private WebRequest request;
62+
63+
private WebResponse expectedResponse;
64+
65+
5966
@Mock
6067
private WebRequestMatcher matcher1;
6168

@@ -72,22 +79,16 @@ public class DelegatingWebConnectionTests {
7279
private WebConnection connection2;
7380

7481

75-
private DelegatingWebConnection webConnection;
76-
77-
private WebRequest request;
78-
79-
private WebResponse expectedResponse;
80-
81-
8282
@Before
83-
public void setUp() throws Exception {
83+
public void setup() throws Exception {
8484
request = new WebRequest(new URL("http://localhost/"));
8585
WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections.<NameValuePair> emptyList());
8686
expectedResponse = new WebResponse(data, request, 100L);
8787
webConnection = new DelegatingWebConnection(defaultConnection,
8888
new DelegateWebConnection(matcher1, connection1), new DelegateWebConnection(matcher2, connection2));
8989
}
9090

91+
9192
@Test
9293
public void getResponseDefault() throws Exception {
9394
when(defaultConnection.getResponse(request)).thenReturn(expectedResponse);

spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.net.MalformedURLException;
2020
import java.net.URL;
21+
import java.nio.charset.StandardCharsets;
2122
import java.util.Collections;
2223
import java.util.HashMap;
2324
import java.util.List;
@@ -28,9 +29,12 @@
2829
import javax.servlet.http.HttpSession;
2930

3031
import com.gargoylesoftware.htmlunit.FormEncodingType;
32+
import com.gargoylesoftware.htmlunit.HttpMethod;
33+
import com.gargoylesoftware.htmlunit.WebClient;
34+
import com.gargoylesoftware.htmlunit.WebRequest;
35+
import com.gargoylesoftware.htmlunit.util.NameValuePair;
3136
import org.apache.commons.io.IOUtils;
3237
import org.apache.http.auth.UsernamePasswordCredentials;
33-
3438
import org.junit.Before;
3539
import org.junit.Test;
3640

@@ -41,15 +45,10 @@
4145
import org.springframework.test.web.servlet.MockMvc;
4246
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
4347

44-
import com.gargoylesoftware.htmlunit.HttpMethod;
45-
import com.gargoylesoftware.htmlunit.WebClient;
46-
import com.gargoylesoftware.htmlunit.WebRequest;
47-
import com.gargoylesoftware.htmlunit.util.NameValuePair;
48-
49-
import static java.util.Arrays.asList;
48+
import static java.util.Arrays.*;
5049
import static org.hamcrest.Matchers.*;
51-
import static org.junit.Assert.assertThat;
52-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
50+
import static org.junit.Assert.*;
51+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
5352

5453
/**
5554
* Unit tests for {@link HtmlUnitRequestBuilder}.
@@ -72,12 +71,13 @@ public class HtmlUnitRequestBuilderTests {
7271

7372

7473
@Before
75-
public void setUp() throws Exception {
74+
public void setup() throws Exception {
7675
webRequest = new WebRequest(new URL("http://example.com:80/test/this/here"));
7776
webRequest.setHttpMethod(HttpMethod.GET);
7877
requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);
7978
}
8079

80+
8181
// --- constructor
8282

8383
@Test(expected = IllegalArgumentException.class)
@@ -95,6 +95,7 @@ public void constructorNullWebRequest() {
9595
new HtmlUnitRequestBuilder(sessions, webClient, null);
9696
}
9797

98+
9899
// --- buildRequest
99100

100101
@Test
@@ -114,12 +115,11 @@ public void buildRequestBasicAuth() {
114115

115116
@Test
116117
public void buildRequestCharacterEncoding() {
117-
String charset = "UTF-8";
118-
webRequest.setCharset(charset);
118+
webRequest.setCharset(StandardCharsets.UTF_8);
119119

120120
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
121121

122-
assertThat(actualRequest.getCharacterEncoding(), equalTo(charset));
122+
assertThat(actualRequest.getCharacterEncoding(), equalTo("UTF-8"));
123123
}
124124

125125
@Test
@@ -151,7 +151,7 @@ public void buildRequestContentType() {
151151
assertThat(actualRequest.getHeader("Content-Type"), equalTo(contentType));
152152
}
153153

154-
@Test // SPR-14916
154+
@Test // SPR-14916
155155
public void buildRequestContentTypeWithFormSubmission() {
156156
webRequest.setEncodingType(FormEncodingType.URL_ENCODED);
157157

spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/MockWebResponseBuilderTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.test.web.servlet.htmlunit;
1818

1919
import java.net.URL;
20+
import java.nio.charset.StandardCharsets;
2021
import java.util.List;
2122
import javax.servlet.http.Cookie;
2223

@@ -47,7 +48,7 @@ public class MockWebResponseBuilderTests {
4748

4849

4950
@Before
50-
public void setUp() throws Exception {
51+
public void setup() throws Exception {
5152
this.webRequest = new WebRequest(new URL("http://example.com:80/test/this/here"));
5253
this.responseBuilder = new MockWebResponseBuilder(System.currentTimeMillis(), this.webRequest, this.response);
5354
}
@@ -81,7 +82,7 @@ public void buildContentCharset() throws Exception {
8182
this.response.addHeader("Content-Type", "text/html; charset=UTF-8");
8283
WebResponse webResponse = this.responseBuilder.build();
8384

84-
assertThat(webResponse.getContentCharset(), equalTo("UTF-8"));
85+
assertThat(webResponse.getContentCharset(), equalTo(StandardCharsets.UTF_8));
8586
}
8687

8788
@Test

0 commit comments

Comments
 (0)