Skip to content

Commit f64a5cb

Browse files
committed
Update vertx-web based tests to use WebClient over HttpClient to simplify the client part of the tests.
Some portions of this content were created with the assistance of Claude Code.
1 parent a77fe90 commit f64a5cb

File tree

63 files changed

+2143
-3054
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2143
-3054
lines changed

vertx-web-graphql/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@
5454
<artifactId>reactive-streams</artifactId>
5555
<version>1.0.3</version>
5656
</dependency>
57+
<dependency>
58+
<groupId>org.junit.vintage</groupId>
59+
<artifactId>junit-vintage-engine</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>io.vertx</groupId>
64+
<artifactId>vertx-web-client</artifactId>
65+
<scope>test</scope>
66+
</dependency>
5767
<dependency>
5868
<groupId>io.vertx</groupId>
5969
<artifactId>vertx-web</artifactId>

vertx-web-proxy/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
<artifactId>vertx-http-proxy</artifactId>
3838
</dependency>
3939
<!-- Testing -->
40+
<dependency>
41+
<groupId>org.junit.vintage</groupId>
42+
<artifactId>junit-vintage-engine</artifactId>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.vertx</groupId>
47+
<artifactId>vertx-web-client</artifactId>
48+
<scope>test</scope>
49+
</dependency>
4050
<dependency>
4151
<groupId>io.vertx</groupId>
4252
<artifactId>vertx-web</artifactId>

vertx-web-session-stores/vertx-web-sstore-caffeine/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,21 @@
3434
<groupId>com.github.ben-manes.caffeine</groupId>
3535
<artifactId>caffeine</artifactId>
3636
</dependency>
37+
<dependency>
38+
<groupId>org.junit.vintage</groupId>
39+
<artifactId>junit-vintage-engine</artifactId>
40+
<scope>test</scope>
41+
</dependency>
3742
<dependency>
3843
<groupId>io.vertx</groupId>
3944
<artifactId>vertx-unit</artifactId>
4045
<scope>test</scope>
4146
</dependency>
47+
<dependency>
48+
<groupId>io.vertx</groupId>
49+
<artifactId>vertx-web-client</artifactId>
50+
<scope>test</scope>
51+
</dependency>
4252
<dependency>
4353
<groupId>io.vertx</groupId>
4454
<artifactId>vertx-web</artifactId>

vertx-web-session-stores/vertx-web-sstore-cookie/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@
2626
</licenses>
2727

2828
<dependencies>
29+
<dependency>
30+
<groupId>org.junit.vintage</groupId>
31+
<artifactId>junit-vintage-engine</artifactId>
32+
<scope>test</scope>
33+
</dependency>
2934
<dependency>
3035
<groupId>io.vertx</groupId>
3136
<artifactId>vertx-web</artifactId>
3237
</dependency>
38+
<dependency>
39+
<groupId>io.vertx</groupId>
40+
<artifactId>vertx-web-client</artifactId>
41+
<scope>test</scope>
42+
</dependency>
3343
<dependency>
3444
<groupId>io.vertx</groupId>
3545
<artifactId>vertx-web</artifactId>

vertx-web-session-stores/vertx-web-sstore-cookie/src/test/java/io/vertx/ext/web/sstore/cookie/tests/CookieSessionHandlerTest.java

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919
import io.netty.handler.codec.http.HttpResponseStatus;
2020
import io.vertx.core.Future;
21+
import io.vertx.core.buffer.Buffer;
2122
import io.vertx.core.http.HttpMethod;
2223
import io.vertx.core.json.JsonObject;
24+
import io.vertx.ext.web.client.HttpResponse;
2325
import io.vertx.ext.auth.User;
2426
import io.vertx.ext.web.Session;
2527
import io.vertx.ext.web.handler.BodyHandler;
@@ -79,26 +81,18 @@ public void testSessionAndUser() throws Exception {
7981

8082
JsonObject myuser = new JsonObject().put("username", "myuser").put("password", System.currentTimeMillis());
8183
AtomicReference<String> cookie = new AtomicReference<>();
82-
testRequest(HttpMethod.POST, "/authenticate",
83-
req -> req.putHeader("content-type", "application/json").send(myuser.toString()),
84-
resp -> {
85-
String setCookie = resp.headers().get("set-cookie");
86-
cookie.set(setCookie.substring(0, setCookie.indexOf(";")));
87-
resp.body().compose(body -> {
88-
assertEquals("Authenticated", body.toString());
89-
return Future.succeededFuture();
90-
}).onFailure(this::fail);
91-
}, 200, "OK", null);
84+
HttpResponse<Buffer> resp = testRequest(webClient.post("/authenticate")
85+
.putHeader("content-type", "application/json")
86+
.sendBuffer(Buffer.buffer(myuser.toString())), 200, "OK");
87+
String setCookie = resp.headers().get("set-cookie");
88+
cookie.set(setCookie.substring(0, setCookie.indexOf(";")));
89+
assertEquals("Authenticated", resp.bodyAsString());
9290
assertNotNull(cookie.get());
9391

94-
testRequest(HttpMethod.GET, "/private/whoami", req -> {
95-
req.putHeader("cookie", cookie.get());
96-
}, resp -> {
97-
resp.body().compose(body -> {
98-
assertEquals(myuser, body.toJsonObject());
99-
return Future.succeededFuture();
100-
}).onFailure(this::fail);
101-
}, 200, "OK", null);
92+
HttpResponse<Buffer> resp2 = testRequest(webClient.get("/private/whoami")
93+
.putHeader("cookie", cookie.get())
94+
.send(), 200, "OK");
95+
assertEquals(myuser, resp2.bodyAsJsonObject());
10296
}
10397

10498
@Test
@@ -163,16 +157,16 @@ public void testSessionFixation() throws Exception {
163157
rc.response().end();
164158
});
165159

166-
testRequest(HttpMethod.GET, "/0", null, resp -> {
167-
String setCookie = resp.headers().get("set-cookie");
168-
assertNotNull(setCookie);
169-
}, 200, "OK", null);
160+
HttpResponse<Buffer> resp = testRequest(webClient.get("/0").send(), 200, "OK");
161+
String setCookie = resp.headers().get("set-cookie");
162+
assertNotNull(setCookie);
170163

171-
testRequest(HttpMethod.GET, "/1", req -> req.putHeader("cookie", "vertx-web.session=" + session.get() + "; Path=/"), resp -> {
172-
String setCookie = resp.headers().get("set-cookie");
173-
assertNotNull(setCookie);
174-
assertFalse(("vertx-web.session=" + session.get() + "; Path=/").equals(setCookie));
175-
}, 200, "OK", null);
164+
HttpResponse<Buffer> resp2 = testRequest(webClient.get("/1")
165+
.putHeader("cookie", "vertx-web.session=" + session.get() + "; Path=/")
166+
.send(), 200, "OK");
167+
String setCookie2 = resp2.headers().get("set-cookie");
168+
assertNotNull(setCookie2);
169+
assertFalse(("vertx-web.session=" + session.get() + "; Path=/").equals(setCookie2));
176170
}
177171

178172
@Test
@@ -235,12 +229,11 @@ public void testSessionFields() throws Exception {
235229
assertEquals(SessionHandler.DEFAULT_SESSION_TIMEOUT, sess.timeout());
236230
rc.response().end();
237231
});
238-
testRequest(HttpMethod.GET, "/", null, resp -> {
239-
String setCookie = resp.headers().get("set-cookie");
240-
assertTrue(setCookie.startsWith(SessionHandler.DEFAULT_SESSION_COOKIE_NAME + "="));
241-
int pos = setCookie.indexOf("; Path=" + SessionHandler.DEFAULT_SESSION_COOKIE_PATH);
242-
rsession.set(setCookie.substring(18, pos));
243-
}, 200, "OK", null);
232+
HttpResponse<Buffer> resp = testRequest(webClient.get("/").send(), 200, "OK");
233+
String setCookie = resp.headers().get("set-cookie");
234+
assertTrue(setCookie.startsWith(SessionHandler.DEFAULT_SESSION_COOKIE_NAME + "="));
235+
int pos = setCookie.indexOf("; Path=" + SessionHandler.DEFAULT_SESSION_COOKIE_PATH);
236+
rsession.set(setCookie.substring(18, pos));
244237

245238

246239
store

vertx-web-session-stores/vertx-web-sstore-cookie/src/test/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
open module io.vertx.web.sstore.cookie.tests {
1717
requires io.vertx.core;
1818
requires io.vertx.web;
19+
requires io.vertx.web.client;
1920
requires io.vertx.web.sstore.cookie;
2021
requires io.vertx.web.tests;
2122
requires junit;

vertx-web-session-stores/vertx-web-sstore-redis/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@
3535
<artifactId>vertx-redis-client</artifactId>
3636
<version>${project.version}</version>
3737
</dependency>
38+
<dependency>
39+
<groupId>org.junit.vintage</groupId>
40+
<artifactId>junit-vintage-engine</artifactId>
41+
<scope>test</scope>
42+
</dependency>
3843
<dependency>
3944
<groupId>io.vertx</groupId>
4045
<artifactId>vertx-unit</artifactId>
4146
<scope>test</scope>
4247
</dependency>
48+
<dependency>
49+
<groupId>io.vertx</groupId>
50+
<artifactId>vertx-web-client</artifactId>
51+
<scope>test</scope>
52+
</dependency>
4353
<dependency>
4454
<groupId>io.vertx</groupId>
4555
<artifactId>vertx-web</artifactId>

vertx-web/src/test/java/io/vertx/ext/web/it/RoutingContextDatabindTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import io.netty.handler.codec.http.HttpResponseStatus;
2020
import io.vertx.core.Vertx;
21+
import io.vertx.core.buffer.Buffer;
2122
import io.vertx.core.http.HttpMethod;
23+
import io.vertx.ext.web.client.HttpResponse;
2224
import io.vertx.ext.web.tests.WebTestBase;
2325
import io.vertx.ext.web.handler.BodyHandler;
2426
import org.junit.AfterClass;
@@ -76,8 +78,7 @@ public void testJsonBean() throws Exception {
7678
}).failureHandler(ctx -> {
7779
});
7880

79-
testRequest(HttpMethod.GET, "/", null, res -> {
80-
Assert.assertEquals("application/json", res.getHeader("Content-Type"));
81-
}, HttpResponseStatus.OK.code(), HttpResponseStatus.OK.reasonPhrase(), "{\"x\":10,\"y\":20}");
81+
HttpResponse<Buffer> res = testRequest(webClient.get("/").send(), HttpResponseStatus.OK.code(), HttpResponseStatus.OK.reasonPhrase(), "{\"x\":10,\"y\":20}");
82+
Assert.assertEquals("application/json", res.getHeader("Content-Type"));
8283
}
8384
}

vertx-web/src/test/java/io/vertx/ext/web/it/sstore/ClusteredSessionHandlerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.vertx.core.buffer.Buffer;
2020
import io.vertx.core.http.*;
21+
import io.vertx.ext.web.client.HttpResponse;
2122
import io.vertx.core.json.JsonObject;
2223
import io.vertx.core.spi.cluster.ClusterManager;
2324
import io.vertx.ext.web.Router;
@@ -162,12 +163,11 @@ public void testClusteredSession() throws Exception {
162163
});
163164

164165
AtomicReference<String> rSetCookie = new AtomicReference<>();
165-
testRequestBuffer(client, HttpMethod.GET, 8081, "/", null, resp -> {
166-
String setCookie = resp.headers().get("set-cookie");
167-
rSetCookie.set(setCookie);
168-
}, 200, "OK", null);
169-
testRequestBuffer(client, HttpMethod.GET, 8082, "/", req -> req.putHeader("cookie", rSetCookie.get()), null, 200, "OK", null);
170-
testRequestBuffer(client, HttpMethod.GET, 8083, "/", req -> req.putHeader("cookie", rSetCookie.get()), null, 200, "OK", null);
166+
HttpResponse<Buffer> resp = testRequest(webClient.get(8081, "localhost", "/").send(), 200, "OK");
167+
String setCookie = resp.headers().get("set-cookie");
168+
rSetCookie.set(setCookie);
169+
testRequest(webClient.get(8082, "localhost", "/").putHeader("cookie", rSetCookie.get()).send(), 200, "OK");
170+
testRequest(webClient.get(8083, "localhost", "/").putHeader("cookie", rSetCookie.get()).send(), 200, "OK");
171171
}
172172

173173
@Test

vertx-web/src/test/java/io/vertx/ext/web/tests/ForwardedTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
package io.vertx.ext.web.tests;
1818

19-
import io.vertx.core.http.HttpMethod;
19+
import io.vertx.core.buffer.Buffer;
2020
import io.vertx.core.http.HttpServerRequest;
2121
import io.vertx.core.http.WebSocketConnectOptions;
2222
import io.vertx.core.net.NetClient;
2323
import io.vertx.ext.web.Route;
24+
import io.vertx.ext.web.client.HttpRequest;
2425
import io.vertx.test.core.TestUtils;
2526
import org.junit.Assert;
2627
import org.junit.Test;
@@ -482,11 +483,11 @@ public void testForwardedDisabled() throws Exception {
482483

483484

484485
private void testRequest(String... headers) throws Exception {
485-
testRequest(HttpMethod.GET, "/", req -> {
486-
int i = 0;
487-
while (i < headers.length)
488-
req.putHeader(headers[i++], headers[i++]);
489-
}, 200, "OK", null);
486+
HttpRequest<Buffer> req = webClient.get("/");
487+
int i = 0;
488+
while (i < headers.length)
489+
req.putHeader(headers[i++], headers[i++]);
490+
testRequest(req, 200, "OK");
490491
}
491492

492493
@Test

0 commit comments

Comments
 (0)