Skip to content

Commit 92d1ebe

Browse files
committed
Upgrade to HtmUnit 3.11.0
This commit upgrades to a major new release of HtmlUnit. This is a breaking change as HtmlUnit 3 moves to a `org.htmlunit` package and calling code needs to be restructured. Our use of Selenium has been adapted accordingly, moving to Selenium 3, using the new org.seleniumhq.selenium:htmlunit3-driver integration. Closes gh-30392
1 parent 71245f9 commit 92d1ebe

25 files changed

+103
-96
lines changed

framework-docs/modules/ROOT/pages/testing/spring-mvc-test-framework/server-htmlunit/mah.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ to use the raw HtmlUnit libraries.
88
== MockMvc and HtmlUnit Setup
99

1010
First, make sure that you have included a test dependency on
11-
`net.sourceforge.htmlunit:htmlunit`. In order to use HtmlUnit with Apache HttpComponents
12-
4.5+, you need to use HtmlUnit 2.18 or higher.
11+
`org.htmlunit:htmlunit`.
1312

1413
We can easily create an HtmlUnit `WebClient` that integrates with MockMvc by using the
1514
`MockMvcWebClientBuilder`, as follows:

framework-docs/modules/ROOT/pages/testing/spring-mvc-test-framework/server-htmlunit/webdriver.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ following sections to make this pattern much easier to implement.
166166
== MockMvc and WebDriver Setup
167167

168168
To use Selenium WebDriver with the Spring MVC Test framework, make sure that your project
169-
includes a test dependency on `org.seleniumhq.selenium:selenium-htmlunit-driver`.
169+
includes a test dependency on `org.seleniumhq.selenium:selenium-htmlunit3-driver`.
170170

171171
We can easily create a Selenium WebDriver that integrates with MockMvc by using the
172172
`MockMvcHtmlUnitDriverBuilder` as the following example shows:

framework-docs/modules/ROOT/pages/testing/spring-mvc-test-framework/server-htmlunit/why.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Kotlin::
8787

8888
This test has some obvious drawbacks. If we update our controller to use the parameter
8989
`message` instead of `text`, our form test continues to pass, even though the HTML form
90-
is out of synch with the controller. To resolve this we can combine our two tests, as
90+
is out of sync with the controller. To resolve this we can combine our two tests, as
9191
follows:
9292

9393
[tabs]

framework-platform/framework-platform.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ dependencies {
8989
api("jaxen:jaxen:1.2.0")
9090
api("junit:junit:4.13.2")
9191
api("net.sf.jopt-simple:jopt-simple:5.0.4")
92-
api("net.sourceforge.htmlunit:htmlunit:2.70.0")
9392
api("org.apache-extras.beanshell:bsh:2.0b6")
9493
api("org.apache.activemq:activemq-broker:5.17.6")
9594
api("org.apache.activemq:activemq-kahadb-store:5.17.6")
@@ -129,15 +128,16 @@ dependencies {
129128
api("org.hibernate:hibernate-core-jakarta:5.6.15.Final")
130129
api("org.hibernate:hibernate-validator:7.0.5.Final")
131130
api("org.hsqldb:hsqldb:2.7.2")
131+
api("org.htmlunit:htmlunit:3.11.0")
132132
api("org.javamoney:moneta:1.4.2")
133133
api("org.jruby:jruby:9.4.6.0")
134134
api("org.junit.support:testng-engine:1.0.5")
135135
api("org.mozilla:rhino:1.7.14")
136136
api("org.ogce:xpp3:1.1.6")
137137
api("org.python:jython-standalone:2.7.3")
138138
api("org.quartz-scheduler:quartz:2.3.2")
139-
api("org.seleniumhq.selenium:htmlunit-driver:2.70.0")
140-
api("org.seleniumhq.selenium:selenium-java:3.141.59")
139+
api("org.seleniumhq.selenium:htmlunit3-driver:4.18.1")
140+
api("org.seleniumhq.selenium:selenium-java:4.18.1")
141141
api("org.skyscreamer:jsonassert:1.5.1")
142142
api("org.slf4j:slf4j-api:2.0.12")
143143
api("org.testng:testng:7.9.0")

spring-test/spring-test.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ dependencies {
2929
optional("jakarta.xml.bind:jakarta.xml.bind-api")
3030
optional("javax.inject:javax.inject")
3131
optional("junit:junit")
32-
optional("net.sourceforge.htmlunit:htmlunit") {
33-
exclude group: "commons-logging", module: "commons-logging"
34-
}
3532
optional("org.apache.groovy:groovy")
3633
optional("org.apache.tomcat.embed:tomcat-embed-core")
3734
optional("org.aspectj:aspectjweaver")
3835
optional("org.hamcrest:hamcrest")
36+
optional("org.htmlunit:htmlunit") {
37+
exclude group: "commons-logging", module: "commons-logging"
38+
}
3939
optional("org.jetbrains.kotlin:kotlin-reflect")
4040
optional("org.jetbrains.kotlin:kotlin-stdlib")
4141
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core")
4242
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
4343
optional("org.junit.jupiter:junit-jupiter-api")
4444
optional("org.junit.platform:junit-platform-launcher") // for AOT processing
4545
optional("org.mockito:mockito-core")
46-
optional("org.seleniumhq.selenium:htmlunit-driver") {
46+
optional("org.seleniumhq.selenium:htmlunit3-driver") {
4747
exclude group: "commons-logging", module: "commons-logging"
4848
exclude group: "net.bytebuddy", module: "byte-buddy"
4949
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -20,9 +20,9 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23-
import com.gargoylesoftware.htmlunit.WebConnection;
24-
import com.gargoylesoftware.htmlunit.WebRequest;
25-
import com.gargoylesoftware.htmlunit.WebResponse;
23+
import org.htmlunit.WebConnection;
24+
import org.htmlunit.WebRequest;
25+
import org.htmlunit.WebResponse;
2626

2727
import org.springframework.util.Assert;
2828

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -21,7 +21,7 @@
2121
import java.util.HashSet;
2222
import java.util.Set;
2323

24-
import com.gargoylesoftware.htmlunit.WebRequest;
24+
import org.htmlunit.WebRequest;
2525

2626
/**
2727
* A {@link WebRequestMatcher} that allows matching on the host and optionally

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -30,15 +30,15 @@
3030
import java.util.Set;
3131
import java.util.StringTokenizer;
3232

33-
import com.gargoylesoftware.htmlunit.FormEncodingType;
34-
import com.gargoylesoftware.htmlunit.WebClient;
35-
import com.gargoylesoftware.htmlunit.WebRequest;
36-
import com.gargoylesoftware.htmlunit.util.KeyDataPair;
37-
import com.gargoylesoftware.htmlunit.util.NameValuePair;
3833
import jakarta.servlet.ServletContext;
3934
import jakarta.servlet.http.Cookie;
4035
import jakarta.servlet.http.HttpServletRequest;
4136
import jakarta.servlet.http.HttpSession;
37+
import org.htmlunit.FormEncodingType;
38+
import org.htmlunit.WebClient;
39+
import org.htmlunit.WebRequest;
40+
import org.htmlunit.util.KeyDataPair;
41+
import org.htmlunit.util.NameValuePair;
4242

4343
import org.springframework.beans.Mergeable;
4444
import org.springframework.http.MediaType;
@@ -301,8 +301,8 @@ private void cookies(MockHttpServletRequest request) {
301301
}
302302
}
303303

304-
Set<com.gargoylesoftware.htmlunit.util.Cookie> managedCookies = this.webClient.getCookies(this.webRequest.getUrl());
305-
for (com.gargoylesoftware.htmlunit.util.Cookie cookie : managedCookies) {
304+
Set<org.htmlunit.util.Cookie> managedCookies = this.webClient.getCookies(this.webRequest.getUrl());
305+
for (org.htmlunit.util.Cookie cookie : managedCookies) {
306306
processCookie(request, cookies, new Cookie(cookie.getName(), cookie.getValue()));
307307
}
308308

@@ -351,8 +351,8 @@ private void removeSessionCookie(MockHttpServletRequest request, String sessioni
351351
this.webClient.getCookieManager().removeCookie(createCookie(request, sessionid));
352352
}
353353

354-
private com.gargoylesoftware.htmlunit.util.Cookie createCookie(MockHttpServletRequest request, String sessionid) {
355-
return new com.gargoylesoftware.htmlunit.util.Cookie(request.getServerName(), "JSESSIONID", sessionid,
354+
private org.htmlunit.util.Cookie createCookie(MockHttpServletRequest request, String sessionid) {
355+
return new org.htmlunit.util.Cookie(request.getServerName(), "JSESSIONID", sessionid,
356356
request.getContextPath() + "/", null, request.isSecure(), true);
357357
}
358358

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.test.web.servlet.htmlunit;
1818

19-
import com.gargoylesoftware.htmlunit.WebClient;
19+
import org.htmlunit.WebClient;
2020

2121
import org.springframework.lang.Nullable;
2222
import org.springframework.test.web.servlet.MockMvc;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -21,13 +21,13 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24-
import com.gargoylesoftware.htmlunit.CookieManager;
25-
import com.gargoylesoftware.htmlunit.WebClient;
26-
import com.gargoylesoftware.htmlunit.WebConnection;
27-
import com.gargoylesoftware.htmlunit.WebRequest;
28-
import com.gargoylesoftware.htmlunit.WebResponse;
29-
import com.gargoylesoftware.htmlunit.util.Cookie;
3024
import org.apache.http.impl.cookie.BasicClientCookie;
25+
import org.htmlunit.CookieManager;
26+
import org.htmlunit.WebClient;
27+
import org.htmlunit.WebConnection;
28+
import org.htmlunit.WebRequest;
29+
import org.htmlunit.WebResponse;
30+
import org.htmlunit.util.Cookie;
3131

3232
import org.springframework.lang.Nullable;
3333
import org.springframework.mock.web.MockHttpServletResponse;
@@ -181,7 +181,7 @@ private void storeCookies(WebRequest webRequest, jakarta.servlet.http.Cookie[] c
181181
}
182182

183183
@SuppressWarnings("removal")
184-
private static com.gargoylesoftware.htmlunit.util.Cookie createCookie(jakarta.servlet.http.Cookie cookie) {
184+
private static Cookie createCookie(jakarta.servlet.http.Cookie cookie) {
185185
Date expires = null;
186186
if (cookie.getMaxAge() > -1) {
187187
expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000);
@@ -195,7 +195,7 @@ private static com.gargoylesoftware.htmlunit.util.Cookie createCookie(jakarta.se
195195
if (cookie.isHttpOnly()) {
196196
result.setAttribute("httponly", "true");
197197
}
198-
return new com.gargoylesoftware.htmlunit.util.Cookie(result);
198+
return new Cookie(result);
199199
}
200200

201201
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -20,8 +20,8 @@
2020
import java.util.Collections;
2121
import java.util.List;
2222

23-
import com.gargoylesoftware.htmlunit.WebClient;
24-
import com.gargoylesoftware.htmlunit.WebConnection;
23+
import org.htmlunit.WebClient;
24+
import org.htmlunit.WebConnection;
2525

2626
import org.springframework.test.web.servlet.MockMvc;
2727
import org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -21,10 +21,10 @@
2121
import java.util.Collection;
2222
import java.util.List;
2323

24-
import com.gargoylesoftware.htmlunit.WebRequest;
25-
import com.gargoylesoftware.htmlunit.WebResponse;
26-
import com.gargoylesoftware.htmlunit.WebResponseData;
27-
import com.gargoylesoftware.htmlunit.util.NameValuePair;
24+
import org.htmlunit.WebRequest;
25+
import org.htmlunit.WebResponse;
26+
import org.htmlunit.WebResponseData;
27+
import org.htmlunit.util.NameValuePair;
2828

2929
import org.springframework.http.HttpStatus;
3030
import org.springframework.mock.web.MockHttpServletResponse;

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

Lines changed: 2 additions & 2 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-2024 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,7 +18,7 @@
1818

1919
import java.util.regex.Pattern;
2020

21-
import com.gargoylesoftware.htmlunit.WebRequest;
21+
import org.htmlunit.WebRequest;
2222

2323
/**
2424
* A {@link WebRequestMatcher} that allows matching on

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

Lines changed: 2 additions & 2 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-2024 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.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.test.web.servlet.htmlunit;
1818

19-
import com.gargoylesoftware.htmlunit.WebRequest;
19+
import org.htmlunit.WebRequest;
2020

2121
/**
2222
* Strategy for matching on a {@link WebRequest}.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.test.web.servlet.htmlunit.webdriver;
1818

19-
import com.gargoylesoftware.htmlunit.BrowserVersion;
20-
import com.gargoylesoftware.htmlunit.WebClient;
19+
import org.htmlunit.BrowserVersion;
20+
import org.htmlunit.WebClient;
2121
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
2222

2323
import org.springframework.lang.Nullable;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -16,9 +16,9 @@
1616

1717
package org.springframework.test.web.servlet.htmlunit.webdriver;
1818

19-
import com.gargoylesoftware.htmlunit.BrowserVersion;
20-
import com.gargoylesoftware.htmlunit.WebClient;
21-
import com.gargoylesoftware.htmlunit.WebConnection;
19+
import org.htmlunit.BrowserVersion;
20+
import org.htmlunit.WebClient;
21+
import org.htmlunit.WebConnection;
2222
import org.openqa.selenium.Capabilities;
2323
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
2424

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 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,7 +19,7 @@
1919
import java.net.MalformedURLException;
2020
import java.net.URL;
2121

22-
import com.gargoylesoftware.htmlunit.WebRequest;
22+
import org.htmlunit.WebRequest;
2323

2424
import static org.assertj.core.api.Assertions.assertThat;
2525

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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,13 +19,13 @@
1919
import java.net.URL;
2020
import java.util.Collections;
2121

22-
import com.gargoylesoftware.htmlunit.HttpWebConnection;
23-
import com.gargoylesoftware.htmlunit.Page;
24-
import com.gargoylesoftware.htmlunit.WebClient;
25-
import com.gargoylesoftware.htmlunit.WebConnection;
26-
import com.gargoylesoftware.htmlunit.WebRequest;
27-
import com.gargoylesoftware.htmlunit.WebResponse;
28-
import com.gargoylesoftware.htmlunit.WebResponseData;
22+
import org.htmlunit.HttpWebConnection;
23+
import org.htmlunit.Page;
24+
import org.htmlunit.WebClient;
25+
import org.htmlunit.WebConnection;
26+
import org.htmlunit.WebRequest;
27+
import org.htmlunit.WebResponse;
28+
import org.htmlunit.WebResponseData;
2929
import org.junit.jupiter.api.BeforeEach;
3030
import org.junit.jupiter.api.Test;
3131
import org.junit.jupiter.api.extension.ExtendWith;

0 commit comments

Comments
 (0)