|
17 | 17 | package hello;
|
18 | 18 |
|
19 | 19 | import io.vertx.core.Vertx;
|
| 20 | +import io.vertx.core.VertxOptions; |
20 | 21 | import io.vertx.ext.web.client.WebClient;
|
21 | 22 | import io.vertx.ext.web.codec.BodyCodec;
|
22 | 23 | import io.vertx.junit5.Checkpoint;
|
23 | 24 | import io.vertx.junit5.VertxExtension;
|
24 | 25 | import io.vertx.junit5.VertxTestContext;
|
25 | 26 | import org.assertj.core.api.Assertions;
|
26 |
| -import org.junit.jupiter.api.DisplayName; |
27 |
| -import org.junit.jupiter.api.RepeatedTest; |
28 |
| -import org.junit.jupiter.api.Test; |
| 27 | +import org.junit.jupiter.api.*; |
29 | 28 | import org.junit.jupiter.api.extension.ExtendWith;
|
30 | 29 |
|
31 | 30 | import java.util.concurrent.atomic.AtomicInteger;
|
@@ -80,4 +79,47 @@ void useSampleVerticle(Vertx vertx, VertxTestContext testContext) {
|
80 | 79 | }
|
81 | 80 | }));
|
82 | 81 | }
|
| 82 | + |
| 83 | + @DisplayName("➡️ A nested test with customized lifecycle") |
| 84 | + @Nested |
| 85 | + class CustomLifecycleTest { |
| 86 | + |
| 87 | + Vertx vertx; |
| 88 | + |
| 89 | + @BeforeEach |
| 90 | + void prepare() { |
| 91 | + vertx = Vertx.vertx(new VertxOptions() |
| 92 | + .setMaxEventLoopExecuteTime(1000) |
| 93 | + .setPreferNativeTransport(true) |
| 94 | + .setFileResolverCachingEnabled(true)); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + @DisplayName("⬆️ Deploy SampleVerticle") |
| 99 | + void deploySampleVerticle(VertxTestContext testContext) { |
| 100 | + vertx.deployVerticle(new SampleVerticle(), testContext.succeeding(id -> testContext.completeNow())); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + @DisplayName("🛂 Make a HTTP client request to SampleVerticle") |
| 105 | + void httpRequest(VertxTestContext testContext) { |
| 106 | + WebClient webClient = WebClient.create(vertx); |
| 107 | + vertx.deployVerticle(new SampleVerticle(), testContext.succeeding(id -> { |
| 108 | + webClient.get(11981, "localhost", "/yo") |
| 109 | + .as(BodyCodec.string()) |
| 110 | + .send(testContext.succeeding(resp -> { |
| 111 | + testContext.verify(() -> { |
| 112 | + assertThat(resp.statusCode()).isEqualTo(200); |
| 113 | + assertThat(resp.body()).contains("Yo!"); |
| 114 | + testContext.completeNow(); |
| 115 | + }); |
| 116 | + })); |
| 117 | + })); |
| 118 | + } |
| 119 | + |
| 120 | + @AfterEach |
| 121 | + void cleanup() { |
| 122 | + vertx.close(); |
| 123 | + } |
| 124 | + } |
83 | 125 | }
|
0 commit comments