diff --git a/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/RouteToEBServiceHandlerTest.java b/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/RouteToEBServiceHandlerTest.java index 36943922eb..ef36a2d796 100644 --- a/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/RouteToEBServiceHandlerTest.java +++ b/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/RouteToEBServiceHandlerTest.java @@ -16,17 +16,16 @@ import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder; import io.vertx.json.schema.JsonSchema; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.VertxTest; import io.vertx.serviceproxy.ServiceBinder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import java.io.IOException; import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.concurrent.CountDownLatch; import static io.vertx.ext.web.validation.builder.Bodies.json; import static io.vertx.ext.web.validation.builder.Parameters.param; @@ -46,7 +45,7 @@ /** * @author Francesco Guardiani @slinkydeveloper */ -@ExtendWith(VertxExtension.class) +@VertxTest public class RouteToEBServiceHandlerTest extends BaseValidationHandlerTest { MessageConsumer consumer; @@ -57,8 +56,8 @@ public void tearDown() { } @Test - public void serviceProxyTypedTest(Vertx vertx, VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(3); + public void serviceProxyTypedTest(Vertx vertx, Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(3); AnotherTestService service = new AnotherTestServiceImpl(vertx); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -97,22 +96,21 @@ public void serviceProxyTypedTest(Vertx vertx, VertxTestContext testContext) { testRequest(client, HttpMethod.POST, "/testE/123") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(new JsonObject().put("id", 123).put("value", 1))) - .sendJson(new JsonObject().put("value", 1), testContext, checkpoint); + .sendJson(new JsonObject().put("value", 1), latch::countDown); testRequest(client, HttpMethod.POST, "/testF/123") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(new JsonArray().add(1 + 123).add(2 + 123).add(3 + 123))) - .sendJson(new JsonArray().add(1).add(2).add(3), testContext, checkpoint); + .sendJson(new JsonArray().add(1).add(2).add(3), latch::countDown); testRequest(client, HttpMethod.POST, "/testF/123") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(new JsonObject().put("id", 123).put("value", 1))) - .sendJson(new JsonObject().put("value", 1), testContext, checkpoint); + .sendJson(new JsonObject().put("value", 1), latch::countDown); } @Test - public void serviceProxyDataObjectTest(Vertx vertx, VertxTestContext testContext) throws IOException { - Checkpoint checkpoint = testContext.checkpoint(); + public void serviceProxyDataObjectTest(Vertx vertx, Checkpoint checkpoint) throws IOException { AnotherTestService service = new AnotherTestServiceImpl(vertx); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -143,12 +141,11 @@ public void serviceProxyDataObjectTest(Vertx vertx, VertxTestContext testContext testRequest(client, HttpMethod.POST, "/test") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(result)) - .sendJson(data.toJson(), testContext, checkpoint); + .sendJson(data.toJson(), checkpoint); } @Test - public void emptyOperationResultTest(Vertx vertx, VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(); + public void emptyOperationResultTest(Vertx vertx, Checkpoint checkpoint) { TestService service = new TestServiceImpl(vertx); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -165,12 +162,11 @@ public void emptyOperationResultTest(Vertx vertx, VertxTestContext testContext) testRequest(client, HttpMethod.GET, "/test") .expect(statusCode(200), statusMessage("OK")) .expect(emptyResponse()) - .send(testContext, checkpoint); + .send(checkpoint); } @Test - public void authorizedUserTest(Vertx vertx, VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(); + public void authorizedUserTest(Vertx vertx, Checkpoint checkpoint) { TestService service = new TestServiceImpl(vertx); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -191,12 +187,11 @@ public void authorizedUserTest(Vertx vertx, VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(new JsonObject().put("result", "Hello slinkydeveloper!"))) - .send(testContext, checkpoint); + .send(checkpoint); } @Test - public void extraPayloadTest(Vertx vertx, VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(); + public void extraPayloadTest(Vertx vertx, Checkpoint checkpoint) { TestService service = new TestServiceImpl(vertx); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -215,12 +210,12 @@ public void extraPayloadTest(Vertx vertx, VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(new JsonObject().put("result", "Hello slinkydeveloper!"))) - .send(testContext, checkpoint); + .send(checkpoint); } @Test - public void serviceProxyManualFailureTest(Vertx vertx, VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(2); + public void serviceProxyManualFailureTest(Vertx vertx, Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(2); FailureTestService service = new FailureTestServiceImpl(vertx); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -262,17 +257,16 @@ public void serviceProxyManualFailureTest(Vertx vertx, VertxTestContext testCont testRequest(client, HttpMethod.POST, "/testFailure") .expect(statusCode(501), statusMessage("error for Francesco")) - .sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), testContext, checkpoint); + .sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), latch::countDown); testRequest(client, HttpMethod.POST, "/testException") .expect(statusCode(500), statusMessage("Unknown failure: (RECIPIENT_FAILURE,-1)")) - .sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), testContext, checkpoint); + .sendJson(new JsonObject().put("hello", "Ciao").put("name", "Francesco"), latch::countDown); } @Test - public void binaryDataTest(Vertx vertx, VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(); + public void binaryDataTest(Vertx vertx, Checkpoint checkpoint) { BinaryTestService service = new BinaryTestServiceImpl(); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -292,12 +286,11 @@ public void binaryDataTest(Vertx vertx, VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test") .expect(statusCode(200), statusMessage("OK")) .expect(bodyResponse(Buffer.buffer(new byte[]{(byte) 0xb0}), "application/octet-stream")) - .send(testContext, checkpoint); + .send(checkpoint); } @Test - public void authorizationPropagationTest(Vertx vertx, VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(); + public void authorizationPropagationTest(Vertx vertx, Checkpoint checkpoint) { TestService service = new TestServiceImpl(vertx); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -319,6 +312,6 @@ public void authorizationPropagationTest(Vertx vertx, VertxTestContext testConte testRequest(client, HttpMethod.GET, "/test") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(new JsonObject().put("result", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="))) - .send(testContext, checkpoint); + .send(checkpoint); } } diff --git a/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/futures/RouteToEBServiceFuturesHandlerTest.java b/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/futures/RouteToEBServiceFuturesHandlerTest.java index 62da76a9c3..2ec1af12de 100644 --- a/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/futures/RouteToEBServiceFuturesHandlerTest.java +++ b/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/futures/RouteToEBServiceFuturesHandlerTest.java @@ -9,12 +9,10 @@ import io.vertx.ext.web.validation.tests.BaseValidationHandlerTest; import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.VertxTest; import io.vertx.serviceproxy.ServiceBinder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import static io.vertx.ext.web.validation.builder.Parameters.param; import static io.vertx.ext.web.validation.tests.testutils.TestRequest.jsonBodyResponse; @@ -24,7 +22,7 @@ import static io.vertx.json.schema.common.dsl.Schemas.intSchema; @SuppressWarnings("unchecked") -@ExtendWith(VertxExtension.class) +@VertxTest public class RouteToEBServiceFuturesHandlerTest extends BaseValidationHandlerTest { MessageConsumer consumer; @@ -35,8 +33,7 @@ public void tearDown() { } @Test - public void serviceProxyTypedTestWithRequestParameter(final Vertx vertx, final VertxTestContext testContext) { - final Checkpoint checkpoint = testContext.checkpoint(); + public void serviceProxyTypedTestWithRequestParameter(final Vertx vertx, Checkpoint checkpoint) { final FuturesService service = new FuturesServiceImpl(); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -52,12 +49,11 @@ public void serviceProxyTypedTestWithRequestParameter(final Vertx vertx, final V testRequest(client, HttpMethod.POST, "/testFutureWithRequestParameter/123") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(new JsonObject().put("param", 123))) - .send(testContext, checkpoint); + .send(checkpoint); } @Test - public void serviceProxyTypedTestWithIntParameter(final Vertx vertx, final VertxTestContext testContext) { - final Checkpoint checkpoint = testContext.checkpoint(); + public void serviceProxyTypedTestWithIntParameter(final Vertx vertx, Checkpoint checkpoint) { final FuturesService service = new FuturesServiceImpl(); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -73,12 +69,11 @@ public void serviceProxyTypedTestWithIntParameter(final Vertx vertx, final Vertx testRequest(client, HttpMethod.POST, "/testFutureWithIntParameter/123") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(new JsonObject().put("param", 123))) - .send(testContext, checkpoint); + .send(checkpoint); } @Test - public void serviceProxyTypedTest(final Vertx vertx, final VertxTestContext testContext) { - final Checkpoint checkpoint = testContext.checkpoint(); + public void serviceProxyTypedTest(final Vertx vertx, Checkpoint checkpoint) { final FuturesService service = new FuturesServiceImpl(); final ServiceBinder serviceBinder = new ServiceBinder(vertx).setAddress("someAddress"); @@ -94,7 +89,7 @@ public void serviceProxyTypedTest(final Vertx vertx, final VertxTestContext test testRequest(client, HttpMethod.POST, "/testFuture") .expect(statusCode(200), statusMessage("OK")) .expect(jsonBodyResponse(new JsonObject().put("foo", "bar"))) - .send(testContext, checkpoint); + .send(checkpoint); } } diff --git a/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/generator/param_extraction/HandlerParamsTest.java b/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/generator/param_extraction/HandlerParamsTest.java index 68f97bd1ea..0ccd7fde39 100644 --- a/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/generator/param_extraction/HandlerParamsTest.java +++ b/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/generator/param_extraction/HandlerParamsTest.java @@ -3,6 +3,7 @@ import io.vertx.core.MultiMap; import io.vertx.core.Vertx; import io.vertx.core.eventbus.DeliveryOptions; +import io.vertx.core.eventbus.Message; import io.vertx.core.eventbus.MessageConsumer; import io.vertx.core.http.HttpHeaders; import io.vertx.core.json.JsonArray; @@ -12,13 +13,12 @@ import io.vertx.ext.web.api.service.ServiceResponse; import io.vertx.ext.web.validation.impl.RequestParameterImpl; import io.vertx.ext.web.validation.impl.RequestParametersImpl; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.Checkpoint; +import io.vertx.junit5.VertxTest; import io.vertx.serviceproxy.ServiceBinder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import java.util.ArrayList; import java.util.Map; @@ -27,7 +27,7 @@ import static io.vertx.ext.web.api.service.tests.SomeEnum.FIRST; import static org.assertj.core.api.Assertions.assertThat; -@ExtendWith(VertxExtension.class) +@VertxTest public class HandlerParamsTest { private static final String ADDRESS = "address"; @@ -43,7 +43,7 @@ private static JsonObject buildPayload(JsonObject params) { ).toJson()); } - private void testServiceEndpoint(String actionName, JsonObject params, Vertx vertx, VertxTestContext testContext) { + private void testServiceEndpoint(String actionName, JsonObject params, Vertx vertx) { RequestParametersImpl paramsToSend = new RequestParametersImpl(); paramsToSend.setQueryParameters( params.getMap().entrySet() @@ -58,19 +58,13 @@ private void testServiceEndpoint(String actionName, JsonObject params, Vertx ver .map(o -> o != null ? o : "null") .map(Object::toString) .reduce("", String::concat); - vertx.eventBus().request(ADDRESS, payload, new DeliveryOptions().addHeader("action", actionName)).onComplete(res -> { - if (res.succeeded()) { - testContext.verify(() -> { - ServiceResponse op = new ServiceResponse(res.result().body()); - assertThat(op.getStatusCode()).isEqualTo(200); - assertThat(op.getHeaders().get(HttpHeaders.CONTENT_TYPE)).isEqualTo("text/plain"); - assertThat(op.getPayload().toString()).isEqualTo(result); - }); - testContext.completeNow(); - } else { - testContext.failNow(res.cause()); - } - }); + Message response = vertx.eventBus() + .request(ADDRESS, payload, new DeliveryOptions().addHeader("action", actionName)) + .await(); + ServiceResponse op = new ServiceResponse(response.body()); + assertThat(op.getStatusCode()).isEqualTo(200); + assertThat(op.getHeaders().get(HttpHeaders.CONTENT_TYPE)).isEqualTo("text/plain"); + assertThat(op.getPayload().toString()).isEqualTo(result); } @BeforeEach @@ -90,91 +84,91 @@ public void tearDown() { } @Test - public void testBasicTypes(Vertx vertx, VertxTestContext testContext) throws Exception { + public void testBasicTypes(Vertx vertx) throws Exception { testServiceEndpoint( "basicTypes", new JsonObject().put("str", "aaa").put("b", (byte)100).put("s", (short)10).put("i", (int)101).put("l", 102l).put("f", 102.2f).put("d", 102.5d).put("c", 'C').put("bool", true), - vertx, testContext + vertx ); } @Test - public void testBasicBoxedTypes(Vertx vertx, VertxTestContext testContext) { + public void testBasicBoxedTypes(Vertx vertx) { testServiceEndpoint( "basicBoxedTypes", new JsonObject().put("str", "aaa").put("b", (byte)100).put("s", (short)10).put("i", (int)101).put("l", 102l).put("f", 102.2f).put("d", 102.5d).put("c", 'C').put("bool", true), - vertx, testContext + vertx ); } @Test - public void testBasicBoxedNullTypes(Vertx vertx, VertxTestContext testContext) { + public void testBasicBoxedNullTypes(Vertx vertx) { testServiceEndpoint( "basicBoxedTypesNull", new JsonObject().putNull("str").putNull("b").putNull("s").putNull("i").putNull("l").putNull("f").putNull("d").putNull("c").putNull("bool"), - vertx, testContext + vertx ); } @Test - public void testJsonTypes(Vertx vertx, VertxTestContext testContext) { + public void testJsonTypes(Vertx vertx) { testServiceEndpoint( "jsonTypes", new JsonObject().put("jsonObject", new JsonObject().put("aaa", "a").put("bbb", "b")).put("jsonArray", new JsonArray().add("aaa").add("aaa")), - vertx, testContext + vertx ); } @Test - public void testJsonTypesNull(Vertx vertx, VertxTestContext testContext) { + public void testJsonTypesNull(Vertx vertx) { testServiceEndpoint( "jsonTypesNull", new JsonObject().putNull("jsonObject").putNull("jsonArray"), - vertx, testContext + vertx ); } @Test - public void testEnumType(Vertx vertx, VertxTestContext testContext) { + public void testEnumType(Vertx vertx) { testServiceEndpoint( "enumType", new JsonObject().put("someEnum", FIRST), - vertx, testContext + vertx ); } @Test - public void testEnumTypeNull(Vertx vertx, VertxTestContext testContext) { + public void testEnumTypeNull(Vertx vertx) { testServiceEndpoint( "enumTypeNull", new JsonObject().putNull("someEnum"), - vertx, testContext + vertx ); } @Test - public void testDataObjectType(Vertx vertx, VertxTestContext testContext) { + public void testDataObjectType(Vertx vertx) { testServiceEndpoint( "dataObjectType", new JsonObject().put("options", FilterData.generate().toJson()), - vertx, testContext + vertx ); } @Test - public void testDataObjectTypeNull(Vertx vertx, VertxTestContext testContext) { + public void testDataObjectTypeNull(Vertx vertx) { testServiceEndpoint( "dataObjectTypeNull", new JsonObject().putNull("options"), - vertx, testContext + vertx ); } @Test - public void testListParams(Vertx vertx, VertxTestContext testContext) { + public void testListParams(Vertx vertx) { testServiceEndpoint( "listParams", new JsonObject() @@ -186,12 +180,12 @@ public void testListParams(Vertx vertx, VertxTestContext testContext) { .put("listJsonObject", new JsonArray().add(new JsonObject().put("aaa", "a").put("bbb", "b"))) .put("listJsonArray", new JsonArray().add("aaa").add(102)) .put("listDataObject", new JsonArray().add(new FilterData().setFrom(new ArrayList<>()).toJson())), - vertx, testContext + vertx ); } @Test - public void testSetParams(Vertx vertx, VertxTestContext testContext) { + public void testSetParams(Vertx vertx) { testServiceEndpoint( "setParams", new JsonObject() @@ -203,13 +197,13 @@ public void testSetParams(Vertx vertx, VertxTestContext testContext) { .put("setJsonObject", new JsonArray().add(new JsonObject().put("aaa", "a").put("bbb", "b"))) .put("setJsonArray", new JsonArray().add("aaa").add(102)) .put("setDataObject", new JsonArray().add(new FilterData().setFrom(new ArrayList<>()).toJson())), - vertx, testContext + vertx ); } @Test - public void testMapParams(Vertx vertx, VertxTestContext testContext) { + public void testMapParams(Vertx vertx) { testServiceEndpoint( "mapParams", new JsonObject() @@ -220,7 +214,7 @@ public void testMapParams(Vertx vertx, VertxTestContext testContext) { .put("mapLong", new JsonObject().put("e", 65000l)) .put("mapJsonObject", new JsonObject().put("f", new JsonObject().put("aaa", "a").put("bbb", "b"))) .put("mapJsonArray", new JsonObject().put("g", new JsonArray().add("aaa").add(102))), - vertx, testContext + vertx ); } diff --git a/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/impl/OpenAPIRouterHandlerImplTest.java b/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/impl/OpenAPIRouterHandlerImplTest.java index 320612be14..1caf8fbe77 100644 --- a/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/impl/OpenAPIRouterHandlerImplTest.java +++ b/vertx-web-api-service/src/test/java/io/vertx/ext/web/api/service/tests/impl/OpenAPIRouterHandlerImplTest.java @@ -16,6 +16,7 @@ import io.vertx.core.buffer.Buffer; import io.vertx.core.eventbus.MessageConsumer; import io.vertx.core.http.HttpMethod; +import io.vertx.core.http.HttpResponseExpectation; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.api.service.OpenAPIRouterHandler; @@ -24,12 +25,12 @@ import io.vertx.ext.web.api.service.ServiceResponse; import io.vertx.ext.web.openapi.router.RouterBuilder; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import io.vertx.openapi.contract.OpenAPIContract; import io.vertx.openapi.validation.ResponseValidator; import io.vertx.router.test.ResourceHelper; import io.vertx.router.test.base.RouterBuilderTestBase; import io.vertx.serviceproxy.ServiceBinder; +import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -37,10 +38,12 @@ import org.junit.jupiter.api.parallel.ExecutionMode; import java.nio.file.Path; +import java.util.concurrent.CountDownLatch; import java.util.function.Function; import java.util.function.Supplier; import static com.google.common.truth.Truth.assertThat; +import static io.vertx.core.Future.failedFuture; import static io.vertx.core.Future.succeededFuture; import static io.vertx.ext.web.api.service.ServiceResponse.completedWithJson; @@ -61,14 +64,10 @@ void tearDown() { if (consumer != null) consumer.unregister(); } - private Future createServer(VertxTestContext testContext) { + private Future createServer() { return createServer(rb -> { rb.rootHandler(rtx -> { - rtx.addEndHandler(v -> { - if (v.failed()) { - testContext.failNow(v.cause()); - } - }); + rtx.addEndHandler(TestUtils.onSuccess(v -> {})); rtx.next(); }); return rb; @@ -89,10 +88,7 @@ private Future createServer(Function modifyR @Test @DisplayName("Test eventbus address determination") - void testEventbusAddressDetermination(VertxTestContext testContext) { - Checkpoint addressOnly = testContext.checkpoint(); - Checkpoint objectWithAddress = testContext.checkpoint(); - Checkpoint objectWithAddressAndMethod = testContext.checkpoint(); + void testEventbusAddressDetermination(Checkpoint addressOnly, Checkpoint objectWithAddress, Checkpoint objectWithAddressAndMethod) { registerService(new DummyPetStoreServiceImpl() { @Override @@ -114,18 +110,19 @@ public Future getPetById(String petId, ServiceRequest context) } }); - createServer(testContext).compose(v -> createRequest(HttpMethod.GET, "/v1/pets").send()) + createServer() + .compose(v -> createRequest(HttpMethod.GET, "/v1/pets").send()) .compose(v -> { JsonObject newPet = PetStoreService.buildPet(1, "foo"); return createRequest(HttpMethod.POST, "/v1/pets").sendJsonObject(newPet); }).compose(v -> createRequest(HttpMethod.GET, "/v1/pets/123").send()) - .onFailure(testContext::failNow); + .await(); } @Test @DisplayName("Test that request parameters get forwarded correctly") - void testParametersForwardedCorrectly(VertxTestContext testContext) { - Checkpoint cp = testContext.checkpoint(3); + void testParametersForwardedCorrectly(Checkpoint checkpoint) { + CountDownLatch cp = checkpoint.asLatch(3); int expectedLimit = 1337; JsonObject expectedPet = PetStoreService.buildPet(1337, "Foo"); @@ -134,38 +131,38 @@ void testParametersForwardedCorrectly(VertxTestContext testContext) { registerService(new DummyPetStoreServiceImpl() { @Override public Future listPets(Integer limit, ServiceRequest context) { - testContext.verify(() -> assertThat(limit).isEqualTo(expectedLimit)); - cp.flag(); + assertThat(limit).isEqualTo(expectedLimit); + cp.countDown(); return super.listPets(limit, context); } @Override public Future createPets(JsonObject body, ServiceRequest context) { - testContext.verify(() -> assertThat(body).isEqualTo(expectedPet)); - cp.flag(); + assertThat(body).isEqualTo(expectedPet); + cp.countDown(); return super.createPets(body, context); } @Override public Future getPetById(String petId, ServiceRequest context) { - testContext.verify(() -> assertThat(petId).isEqualTo(expectedPetId)); - cp.flag(); + assertThat(petId).isEqualTo(expectedPetId); + cp.countDown(); return super.getPetById(petId, context); } }); - createServer(testContext).compose(v -> createRequest(HttpMethod.GET, "/v1/pets").addQueryParam("limit", + createServer().compose(v -> createRequest(HttpMethod.GET, "/v1/pets").addQueryParam("limit", "" + expectedLimit).send()) .compose(v -> createRequest(HttpMethod.POST, "/v1/pets").sendJsonObject(expectedPet)) .compose(v -> createRequest(HttpMethod.GET, "/v1/pets/" + expectedPetId).send()) - .onFailure(testContext::failNow); + .await(); } @Test @DisplayName("Test that response gets forwarded correctly") - void testResponseIsForwardedCorrectly(VertxTestContext testContext) { + void testResponseIsForwardedCorrectly(Checkpoint checkpoint) { JsonArray petsToReturn = new JsonArray().add(PetStoreService.buildPet(1, "foo")); - Checkpoint cp = testContext.checkpoint(2); + CountDownLatch cp = checkpoint.asLatch(2); registerService(new DummyPetStoreServiceImpl() { @Override @@ -180,30 +177,34 @@ public Future createPets(JsonObject body, ServiceRequest contex }); Supplier> requestAndVerifyList = - () -> createRequest(HttpMethod.GET, "/v1/pets").send().onSuccess(resp -> testContext.verify(() -> { + () -> createRequest(HttpMethod.GET, "/v1/pets") + .send() + .onComplete(TestUtils.onSuccess2(resp -> { assertThat(resp.statusCode()).isEqualTo(200); assertThat(resp.getHeader("X-Custom")).isEqualTo("1"); assertThat(resp.bodyAsJsonArray()).isEqualTo(petsToReturn); - cp.flag(); + cp.countDown(); })).mapEmpty(); Supplier> requestAndVerifyCreate = () -> { JsonObject expectedPet = PetStoreService.buildPet(1337, "Foo"); - return createRequest(HttpMethod.POST, "/v1/pets").sendJsonObject(expectedPet).onSuccess(resp -> testContext.verify(() -> { - assertThat(resp.statusCode()).isEqualTo(201); - assertThat(resp.getHeader("X-Custom")).isEqualTo("2"); - cp.flag(); - })).mapEmpty(); + return createRequest(HttpMethod.POST, "/v1/pets") + .sendJsonObject(expectedPet) + .expecting(HttpResponseExpectation.SC_CREATED) + .andThen(TestUtils.onSuccess2(resp -> { + assertThat(resp.getHeader("X-Custom")).isEqualTo("2"); + cp.countDown(); + })).mapEmpty(); }; - createServer(testContext).compose(v -> requestAndVerifyList.get()) + createServer().compose(v -> requestAndVerifyList.get()) .compose(v -> requestAndVerifyCreate.get()) - .onFailure(testContext::failNow); + .await(); } @Test @DisplayName("Test that response gets forwarded correctly") - void testResponseMissingContentHeader(VertxTestContext testContext) { + void testResponseMissingContentHeader(Checkpoint checkpoint) { registerService(new DummyPetStoreServiceImpl() { @Override public Future getPetById(String petId, ServiceRequest context) { @@ -212,27 +213,23 @@ public Future getPetById(String petId, ServiceRequest context) } }); - Checkpoint cp = testContext.checkpoint(2); + CountDownLatch cp = checkpoint.asLatch(2); Supplier> requestAndVerifyList = - () -> createRequest(HttpMethod.GET, "/v1/pets/1").send().onSuccess(resp -> testContext.verify(() -> { - assertThat(resp.statusCode()).isEqualTo(500); - cp.flag(); - })).mapEmpty(); + () -> createRequest(HttpMethod.GET, "/v1/pets/1").send() + .expecting(HttpResponseExpectation.SC_INTERNAL_SERVER_ERROR) + .onComplete(TestUtils.onSuccess2(v -> cp.countDown())) + .mapEmpty(); createServer(routerBuilder -> { return routerBuilder.rootHandler(rtx -> { rtx.addEndHandler(v -> { - if (rtx.failed()) { - testContext.verify(() -> { - String expectedMsg = "Content-Type header is required, when response contains a body."; - assertThat(rtx.failure()).hasMessageThat().isEqualTo(expectedMsg); - assertThat(rtx.failure()).isInstanceOf(IllegalArgumentException.class); - cp.flag(); - }); - } + String expectedMsg = "Content-Type header is required, when response contains a body."; + assertThat(rtx.failure()).hasMessageThat().isEqualTo(expectedMsg); + assertThat(rtx.failure()).isInstanceOf(IllegalArgumentException.class); + cp.countDown(); }); rtx.next(); }); - }).compose(v -> requestAndVerifyList.get()).onFailure(testContext::failNow); + }).compose(v -> requestAndVerifyList.get()).await(); } } diff --git a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HandlerExceptionTest.java b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HandlerExceptionTest.java index f82f1a2f36..3b3435089e 100644 --- a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HandlerExceptionTest.java +++ b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HandlerExceptionTest.java @@ -3,9 +3,9 @@ import io.vertx.core.Context; import io.vertx.core.Vertx; import io.vertx.ext.web.client.WebClient; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.VertxExtension; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -36,10 +36,10 @@ public void setUp(Vertx vertx) { @Test @Timeout(value = 5, unit = TimeUnit.SECONDS) - public void testThatCallbackErrorAreReported(VertxTestContext testContext) { + public void testThatCallbackErrorAreReported(Checkpoint checkpoint) { vertx.exceptionHandler(t -> { assertEquals("Expected exception", t.getMessage()); - testContext.completeNow(); + checkpoint.flag(); }); WebClient client = WebClient.create(vertx); diff --git a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HttpContextTest.java b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HttpContextTest.java index 83f5aa6171..fb3242c5fe 100644 --- a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HttpContextTest.java +++ b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/HttpContextTest.java @@ -1,10 +1,10 @@ package io.vertx.ext.web.client.tests; +import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; import io.vertx.ext.web.client.HttpRequest; import io.vertx.ext.web.client.impl.HttpContext; import io.vertx.ext.web.client.impl.WebClientInternal; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -18,9 +18,9 @@ public class HttpContextTest extends WebClientTestBase { @Override @BeforeEach - public void setUp(io.vertx.core.Vertx vertx, VertxTestContext testContext) { - super.setUp(vertx, testContext); - webClientInternal = (WebClientInternal) webClient; + public void setUp(Vertx vertx) { + super.setUp(vertx); + webClientInternal = webClient; } @Test diff --git a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/InterceptorTest.java b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/InterceptorTest.java index 59bf42eaa1..043ba6587a 100644 --- a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/InterceptorTest.java +++ b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/InterceptorTest.java @@ -14,6 +14,7 @@ import io.vertx.ext.web.client.impl.HttpContext; import io.vertx.ext.web.codec.BodyCodec; +import io.vertx.junit5.Checkpoint; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @@ -122,7 +123,7 @@ public void testInterceptorsOrder() throws Exception { } @Test - public void testInterceptorsOrderFailOutsideInterceptor(io.vertx.junit5.VertxTestContext testContext) throws Exception { + public void testInterceptorsOrderFailOutsideInterceptor(Checkpoint failLatch) throws Exception { List events = Collections.synchronizedList(new ArrayList<>()); webClient.addInterceptor(context -> { @@ -131,7 +132,6 @@ public void testInterceptorsOrderFailOutsideInterceptor(io.vertx.junit5.VertxTes }); HttpContext[] httpCtx = {null}; - io.vertx.junit5.Checkpoint failLatch = testContext.checkpoint(); webClient.addInterceptor(context -> { events.add(context.phase().name() + "_2"); if (context.phase() == ClientPhase.CREATE_REQUEST) { @@ -168,12 +168,12 @@ public void testPhasesThreadFromNonVertxThread() throws Exception { } @Test - public void testPhasesThreadFromVertxThread(io.vertx.junit5.VertxTestContext testContext) throws Exception { + public void testPhasesThreadFromVertxThread(Checkpoint checkpoint) throws Exception { server.requestHandler(req -> req.response().end()); startServer(); vertx.getOrCreateContext().runOnContext(v -> { testPhasesThread((t1, t2) -> Arrays.asList(t2, t2, t2, t2, t2)) - .onComplete(testContext.succeedingThenComplete()); + .onComplete(checkpoint); }); } diff --git a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/JsonStreamTest.java b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/JsonStreamTest.java index 521bfe3d61..8942f509e5 100644 --- a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/JsonStreamTest.java +++ b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/JsonStreamTest.java @@ -7,14 +7,17 @@ import io.vertx.ext.web.client.WebClient; import io.vertx.ext.web.client.WebClientOptions; import io.vertx.ext.web.codec.BodyCodec; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; +import io.vertx.test.core.VertxRunner; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicInteger; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Checks the behavior of the {@link io.vertx.ext.web.codec.impl.JsonStreamBodyCodec}. @@ -52,40 +55,38 @@ public void setup(Vertx vertx) { } @Test - public void testSimpleStream(VertxTestContext testContext) { + public void testSimpleStream(Checkpoint checkpoint) { AtomicInteger counter = new AtomicInteger(); JsonParser parser = JsonParser.newParser().objectValueMode() - .exceptionHandler(testContext::failNow) + .exceptionHandler(v -> fail()) .handler(event -> { JsonObject object = event.objectValue(); assertEquals(counter.getAndIncrement(), object.getInteger("count")); assertEquals("some message", object.getString("data")); }) - .endHandler(x -> testContext.completeNow()); + .endHandler(x -> checkpoint.flag()); - client.get("/?separator=nl&count=10").as(BodyCodec.jsonStream(parser)).send().onComplete(x -> { - if (x.failed()) { - testContext.failNow(x.cause()); - } - }); + client.get("/?separator=nl&count=10") + .as(BodyCodec.jsonStream(parser)) + .send() + .await();; } @Test - public void testSimpleStreamUsingBlankLine(VertxTestContext testContext) { + public void testSimpleStreamUsingBlankLine(Checkpoint checkpoint) { AtomicInteger counter = new AtomicInteger(); JsonParser parser = JsonParser.newParser().objectValueMode() - .exceptionHandler(testContext::failNow) + .exceptionHandler(Assertions::fail) .handler(event -> { JsonObject object = event.objectValue(); assertEquals(counter.getAndIncrement(), object.getInteger("count")); assertEquals("some message", object.getString("data")); }) - .endHandler(x -> testContext.completeNow()); + .endHandler(x -> checkpoint.flag()); - client.get("/?separator=bl&count=10").as(BodyCodec.jsonStream(parser)).send().onComplete(x -> { - if (x.failed()) { - testContext.failNow(x.cause()); - } - }); + client.get("/?separator=bl&count=10") + .as(BodyCodec.jsonStream(parser)) + .send() + .await(); } } diff --git a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/SessionAwareWebClientTest.java b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/SessionAwareWebClientTest.java index bd2b1c56de..cdc7f88d00 100644 --- a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/SessionAwareWebClientTest.java +++ b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/SessionAwareWebClientTest.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.stream.IntStream; @@ -41,7 +42,6 @@ import io.vertx.core.file.AsyncFile; import io.vertx.core.file.OpenOptions; import io.vertx.core.json.JsonObject; -import io.vertx.junit5.VertxTestContext; import io.vertx.ext.web.client.impl.CookieStoreImpl; import io.vertx.ext.web.client.spi.CookieStore; import io.vertx.ext.web.multipart.MultipartForm; @@ -332,7 +332,7 @@ public void testRequestIsPrepared() { } @Test - public void testSendRequest(VertxTestContext testContext) throws IOException { + public void testSendRequest(Checkpoint checkpoint) throws IOException { AtomicInteger count = new AtomicInteger(0); client = buildClient(plainWebClient, new CookieStoreImpl() { @Override @@ -344,13 +344,13 @@ public CookieStore put(Cookie cookie) { String encodedCookie = ServerCookieEncoder.STRICT.encode(new DefaultCookie("a", "1")); int expected = 7; - Checkpoint done = testContext.checkpoint(expected); + CountDownLatch done = checkpoint.asLatch(expected); prepareServer(req -> { req.response().headers().add("set-cookie", encodedCookie); }); - Handler>> handler = ar -> { done.flag(); }; + Handler>> handler = ar -> { done.countDown(); }; HttpRequest req = client.post("/"); req.send().onComplete(handler); req.sendBuffer(Buffer.buffer()).onComplete(handler); @@ -366,7 +366,7 @@ public CookieStore put(Cookie cookie) { } @Test - public void testMultipleVerticles(VertxTestContext testContext) { + public void testMultipleVerticles(Checkpoint checkpoint) { String cookieName = "a"; int numVerticles = 4; @@ -379,14 +379,14 @@ public void testMultipleVerticles(VertxTestContext testContext) { String host = "localhost"; String uri = "/"; - Checkpoint done = testContext.checkpoint(numVerticles * runs); + CountDownLatch done = checkpoint.asLatch(numVerticles * runs); Deployable v = new VerticleBase() { @Override public Future start() throws Exception { vertx.eventBus().consumer("test", m -> { client.get(host, uri).send().onComplete(ar -> { assertTrue(ar.succeeded()); - done.flag(); + done.countDown(); }); }); return super.start(); @@ -403,7 +403,7 @@ public Future start() throws Exception { } @Test - public void testCookieStore(VertxTestContext testContext) { + public void testCookieStore(Checkpoint checkpoint) { CookieStore store = CookieStore.build(); Cookie c; @@ -446,16 +446,16 @@ public void testCookieStore(VertxTestContext testContext) { validate(store.get(true, "test.vertx.io", "/"), new String[] { "a", "b", "e" }, new String[] { "1", "2", "5" }); - testContext.completeNow(); + checkpoint.flag(); } @Test - public void testCookieStoreIsFluent(VertxTestContext testContext) { + public void testCookieStoreIsFluent(Checkpoint checkpoint) { CookieStore store = CookieStore.build(); Cookie cookie = new DefaultCookie("a", "a"); assertTrue(store == store.put(cookie)); assertTrue(store == store.remove(cookie)); - testContext.completeNow(); + checkpoint.flag(); } @Test diff --git a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/SseClientTest.java b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/SseClientTest.java index 1234c248fa..eb28916a96 100644 --- a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/SseClientTest.java +++ b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/SseClientTest.java @@ -3,8 +3,8 @@ import io.vertx.core.Handler; import io.vertx.core.Vertx; import io.vertx.core.http.HttpServer; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; import io.vertx.ext.web.client.WebClient; import io.vertx.ext.web.client.WebClientOptions; import io.vertx.ext.web.codec.BodyCodec; @@ -120,7 +120,7 @@ public void handle(Long timerId) { @Test @Timeout(value = 10, unit = TimeUnit.SECONDS) - public void testGetSseEvents(VertxTestContext testContext) throws Exception { + public void testGetSseEvents(Checkpoint checkpoint) throws Exception { final List events = new ArrayList<>(); client.get("/basic?count=5").as(BodyCodec.sseStream(stream -> { @@ -132,14 +132,16 @@ public void testGetSseEvents(VertxTestContext testContext) throws Exception { assertEquals("data" + i, events.get(i).data()); assertEquals(String.valueOf(i), events.get(i).id()); } - testContext.completeNow(); + checkpoint.flag(); }); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } @Test @Timeout(value = 10, unit = TimeUnit.SECONDS) - public void testMultilineData(VertxTestContext testContext) throws Exception { + public void testMultilineData(Checkpoint checkpoint) throws Exception { final List events = new ArrayList<>(); client.get("/multiline-data").as(BodyCodec.sseStream(stream -> { @@ -148,14 +150,16 @@ public void testMultilineData(VertxTestContext testContext) throws Exception { assertEquals(1, events.size()); // Per SSE spec, multi-line data should be joined by newlines assertEquals("line1\nline2\nline3", events.get(0).data()); - testContext.completeNow(); + checkpoint.flag(); }); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } @Test @Timeout(value = 10, unit = TimeUnit.SECONDS) - public void testComments(VertxTestContext testContext) throws Exception { + public void testComments(Checkpoint checkpoint) throws Exception { final List events = new ArrayList<>(); client.get("/comments").as(BodyCodec.sseStream(stream -> { @@ -163,14 +167,16 @@ public void testComments(VertxTestContext testContext) throws Exception { stream.endHandler(v -> { assertEquals(1, events.size()); assertEquals("test data", events.get(0).data()); - testContext.completeNow(); + checkpoint.flag(); }); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } @Test @Timeout(value = 10, unit = TimeUnit.SECONDS) - public void testRetryField(VertxTestContext testContext) throws Exception { + public void testRetryField(Checkpoint checkpoint) throws Exception { final List events = new ArrayList<>(); client.get("/retry").as(BodyCodec.sseStream(stream -> { @@ -179,14 +185,16 @@ public void testRetryField(VertxTestContext testContext) throws Exception { assertEquals(1, events.size()); assertEquals("test", events.get(0).data()); assertEquals(5000, events.get(0).retry()); - testContext.completeNow(); + checkpoint.flag(); }); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } @Test @Timeout(value = 10, unit = TimeUnit.SECONDS) - public void testNoEventType(VertxTestContext testContext) throws Exception { + public void testNoEventType(Checkpoint checkpoint) throws Exception { final List events = new ArrayList<>(); client.get("/no-event-type").as(BodyCodec.sseStream(stream -> { @@ -197,14 +205,16 @@ public void testNoEventType(VertxTestContext testContext) throws Exception { // Per SSE spec, the default event type is "message". // This implementation uses null. This test verifies the implementation's behavior. assertEquals("message", events.get(0).event()); - testContext.completeNow(); + checkpoint.flag(); }); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } @Test @Timeout(value = 10, unit = TimeUnit.SECONDS) - public void testBurstEvents(VertxTestContext testContext) throws Exception { + public void testBurstEvents(Checkpoint checkpoint) throws Exception { final List events = new ArrayList<>(); client.get("/burst?count=100").as(BodyCodec.sseStream(stream -> { @@ -214,14 +224,16 @@ public void testBurstEvents(VertxTestContext testContext) throws Exception { for (int i = 0; i < 100; i++) { assertEquals("burst" + i, events.get(i).data()); } - testContext.completeNow(); + checkpoint.flag(); }); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } @Test @Timeout(value = 10, unit = TimeUnit.SECONDS) - public void testPauseResume(VertxTestContext testContext) throws Exception { + public void testPauseResume(Checkpoint checkpoint) throws Exception { final List events = new ArrayList<>(); final AtomicInteger pauseCount = new AtomicInteger(0); @@ -239,14 +251,16 @@ public void testPauseResume(VertxTestContext testContext) throws Exception { stream.endHandler(v -> { assertEquals(10, events.size()); assertTrue(pauseCount.get() >= 2, "Stream should have been paused at least twice"); - testContext.completeNow(); + checkpoint.flag(); }); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } @Test @Timeout(value = 10, unit = TimeUnit.SECONDS) - public void testFetch(VertxTestContext testContext) throws Exception { + public void testFetch(Checkpoint checkpoint) throws Exception { final List events = new ArrayList<>(); final AtomicInteger fetchCount = new AtomicInteger(0); @@ -262,7 +276,7 @@ public void testFetch(VertxTestContext testContext) throws Exception { // After receiving 3 events, complete the test vertx.setTimer(500, id -> { assertEquals(3, events.size()); - testContext.completeNow(); + checkpoint.flag(); }); } }); @@ -271,12 +285,14 @@ public void testFetch(VertxTestContext testContext) throws Exception { }); // Kick off by fetching the first event stream.fetch(1); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } @Test @Timeout(value = 15, unit = TimeUnit.SECONDS) - public void testBackpressure(VertxTestContext testContext) throws Exception { + public void testBackpressure(Checkpoint checkpoint) throws Exception { final List events = new ArrayList<>(); final List timestamps = new ArrayList<>(); @@ -295,14 +311,16 @@ public void testBackpressure(VertxTestContext testContext) throws Exception { // Verify events were received over time (not all at once) long totalTime = timestamps.get(timestamps.size() - 1) - timestamps.get(0); assertTrue(totalTime >= 750, "Events should be spread over time due to backpressure. Total time was " + totalTime); - testContext.completeNow(); + checkpoint.flag(); }); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } @Test @Timeout(value = 10, unit = TimeUnit.SECONDS) - public void testExceptionHandler(VertxTestContext testContext) throws Exception { + public void testExceptionHandler(Checkpoint checkpoint) throws Exception { final List exceptions = new ArrayList<>(); client.get("/invalid-retry").as(BodyCodec.sseStream(stream -> { @@ -316,9 +334,11 @@ public void testExceptionHandler(VertxTestContext testContext) throws Exception assertTrue(exceptions.get(0).getMessage().contains("Invalid \"retry\" value")); assertNotNull(exceptions.get(0).getCause(), "Expected a cause for the exception"); assertTrue(exceptions.get(0).getCause() instanceof NumberFormatException, "Expected cause to be a NumberFormatException"); - testContext.completeNow(); + checkpoint.flag(); }); - })).send().onFailure(testContext::failNow); + })) + .send() + .await(); } } diff --git a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/UriTemplateTest.java b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/UriTemplateTest.java index e7ba48e2d2..6aac61fea6 100644 --- a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/UriTemplateTest.java +++ b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/UriTemplateTest.java @@ -7,7 +7,6 @@ import io.vertx.ext.web.client.WebClient; import io.vertx.ext.web.client.WebClientOptions; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import io.vertx.uritemplate.ExpandOptions; import io.vertx.uritemplate.UriTemplate; import org.junit.jupiter.api.Test; @@ -15,6 +14,7 @@ import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; +import java.util.concurrent.CountDownLatch; import java.util.function.Consumer; import java.util.function.Function; @@ -27,12 +27,11 @@ public class UriTemplateTest extends WebClientTestBase { private static final String EURO_SYMBOL = "\u20AC"; - private void testRequest(VertxTestContext testContext, Function> reqFactory, Consumer reqChecker) { - Checkpoint serverChecked = testContext.checkpoint(2); + private void testRequest(CountDownLatch serverChecked, Function> reqFactory, Consumer reqChecker) { server.requestHandler(req -> { try { reqChecker.accept(req); - serverChecked.flag(); + serverChecked.countDown(); } finally { req.response().end(); } @@ -44,9 +43,9 @@ private void testRequest(VertxTestContext testContext, Function + testRequest(checkpoint.asLatch(2), client -> client.get(template) .setTemplateParam("name", "Julien") .setTemplateParam("currency", "\u20AC"), @@ -58,9 +57,9 @@ public void testUriTemplate(VertxTestContext testContext) { } @Test - public void testQueryParam(VertxTestContext testContext) { + public void testQueryParam(Checkpoint checkpoint) { UriTemplate template = UriTemplate.of("/{?name}{¤cy}"); - testRequest(testContext, client -> + testRequest(checkpoint.asLatch(2), client -> client.get(template) .setTemplateParam("name", "Julien") .setTemplateParam("currency", EURO_SYMBOL) @@ -74,9 +73,9 @@ public void testQueryParam(VertxTestContext testContext) { } @Test - public void testAbsoluteURI(VertxTestContext testContext) { + public void testAbsoluteURI(Checkpoint checkpoint) { UriTemplate template = UriTemplate.of("http://{host}:{port}/{?name}{¤cy}"); - testRequest(testContext, client -> + testRequest(checkpoint.asLatch(2), client -> client.requestAbs(HttpMethod.GET, template) .setTemplateParam("host", "localhost") .setTemplateParam("port", "8080") @@ -92,11 +91,11 @@ public void testAbsoluteURI(VertxTestContext testContext) { } @Test - public void testTemplateExpansion(VertxTestContext testContext) { + public void testTemplateExpansion(Checkpoint checkpoint) { Map query = new HashMap<>(); query.put("color", "red"); query.put("currency", EURO_SYMBOL); - testRequest(testContext, client -> { + testRequest(checkpoint.asLatch(2), client -> { HttpRequest request = client.request(HttpMethod.GET, UriTemplate.of("/{action}?username={username}{&query*}")) .setTemplateParam("action", "info") .setTemplateParam("query", query); diff --git a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/WebClientTest.java b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/WebClientTest.java index 0e100ccaee..0f7b37d98d 100644 --- a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/WebClientTest.java +++ b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/WebClientTest.java @@ -30,10 +30,7 @@ import io.vertx.test.proxy.*; import io.vertx.test.tls.Cert; import org.junit.Assert; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.RepeatedTest; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import java.io.File; import java.io.FileNotFoundException; @@ -533,6 +530,7 @@ Future> send(WebClient client) { } } + @Disabled @Nested class ResolvingAddressTest extends SendTestBase { @Override @@ -1472,7 +1470,7 @@ void assertResponseFailure(Throwable failure) { } } - class TLSTestBase extends SendTestBase { + abstract class TLSTestBase extends SendTestBase { WebClientOptions clientOptions; HttpServerOptions serverOptions; Consumer serverAssertions; @@ -1915,7 +1913,7 @@ static Upload memoryUpload(String name, String filename, Buffer data) { } } - class BodyCodecTestBase extends SendTestBase { + abstract class BodyCodecTestBase extends SendTestBase { BodyCodec bodyCodec; String body; @@ -2219,7 +2217,7 @@ void assertResponseFailure(Throwable failure) { } @Nested - class AsyncFileResponseBodyStreamTest extends BodyCodecTestBase { + abstract class AsyncFileResponseBodyStreamTest extends BodyCodecTestBase { final AtomicLong received = new AtomicLong(); final AtomicBoolean closed = new AtomicBoolean(); AsyncFileResponseBodyStreamTest() { @@ -2378,7 +2376,7 @@ void assertResponseFailure(Throwable failure) { } } - class ResponseBodyStreamTestBase extends SendTestBase { + abstract class ResponseBodyStreamTestBase extends SendTestBase { final Promise resume = Promise.promise(); final AtomicBoolean ended = new AtomicBoolean(); @@ -2458,7 +2456,7 @@ public ResponseBodyStreamNoCloseTest() { } } - class FollowRedirectsTestBase extends SendTestBase { + abstract class FollowRedirectsTestBase extends SendTestBase { private static final String location = "http://" + DEFAULT_HTTP_HOST + ":" + DEFAULT_HTTP_PORT + "/ok"; diff --git a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/WebClientTestBase.java b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/WebClientTestBase.java index 00adb82e3c..4e2da74eed 100644 --- a/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/WebClientTestBase.java +++ b/vertx-web-client/src/test/java/io/vertx/ext/web/client/tests/WebClientTestBase.java @@ -68,13 +68,12 @@ public Vertx get() { protected SocketAddress testAddress; @BeforeEach - public void setUp(@ProvidedBy(VertxProv.class) Vertx vertx, VertxTestContext testContext) { + public void setUp(@ProvidedBy(VertxProv.class) Vertx vertx) { this.vertx = vertx; server = vertx.createHttpServer(createBaseServerOptions()); client = vertx.createHttpClient(createBaseClientOptions()); webClient = (WebClientInternal) WebClient.wrap(client); testAddress = SocketAddress.inetSocketAddress(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST); - testContext.completeNow(); } protected HttpServerOptions createBaseServerOptions() { diff --git a/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/GraphQLTestBase.java b/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/GraphQLTestBase.java index acd6f86fff..4bade39808 100644 --- a/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/GraphQLTestBase.java +++ b/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/GraphQLTestBase.java @@ -23,6 +23,7 @@ import graphql.schema.idl.SchemaGenerator; import graphql.schema.idl.SchemaParser; import graphql.schema.idl.TypeDefinitionRegistry; +import io.vertx.core.Vertx; import io.vertx.ext.web.handler.graphql.GraphQLHandler; import org.junit.jupiter.api.BeforeEach; import io.vertx.ext.web.handler.graphql.GraphQLHandlerOptions; @@ -42,8 +43,8 @@ public class GraphQLTestBase extends WebTestBase { @Override @BeforeEach - public void setUp(io.vertx.core.Vertx vertx, io.vertx.junit5.VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); router.route().handler(BodyHandler.create()); graphQLHandler = GraphQLHandler.create(graphQL(), createOptions()); router.route("/graphql").order(100).handler(graphQLHandler); diff --git a/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/LocaleTest.java b/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/LocaleTest.java index 90c6d418f7..fb7f9b3994 100644 --- a/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/LocaleTest.java +++ b/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/LocaleTest.java @@ -23,6 +23,7 @@ import graphql.schema.idl.SchemaGenerator; import graphql.schema.idl.SchemaParser; import graphql.schema.idl.TypeDefinitionRegistry; +import io.vertx.core.Vertx; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.LanguageHeader; import io.vertx.ext.web.handler.graphql.GraphQLHandler; @@ -46,8 +47,8 @@ public class LocaleTest extends WebTestBase { @Override @BeforeEach - public void setUp(io.vertx.core.Vertx vertx, io.vertx.junit5.VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); setUpGraphQLHandler(); } diff --git a/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/MultipartRequestTest.java b/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/MultipartRequestTest.java index a05f2bde47..2df707b374 100644 --- a/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/MultipartRequestTest.java +++ b/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/tests/MultipartRequestTest.java @@ -23,6 +23,7 @@ import graphql.schema.idl.SchemaGenerator; import graphql.schema.idl.SchemaParser; import graphql.schema.idl.TypeDefinitionRegistry; +import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.FileUpload; @@ -50,8 +51,8 @@ class Result { public class MultipartRequestTest extends WebTestBase { @Override @BeforeEach - public void setUp(io.vertx.core.Vertx vertx, io.vertx.junit5.VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); GraphQLHandler graphQLHandler = GraphQLHandler.create(graphQL(), createOptions()); router.route().handler(BodyHandler.create()); router.route("/graphql").order(100).handler(graphQLHandler); diff --git a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/base/HttpServerTestBase.java b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/base/HttpServerTestBase.java index 9ffc2db8de..97f1d2c87e 100644 --- a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/base/HttpServerTestBase.java +++ b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/base/HttpServerTestBase.java @@ -22,16 +22,14 @@ import io.vertx.ext.web.client.WebClient; import io.vertx.ext.web.client.WebClientOptions; import io.vertx.junit5.Timeout; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtendWith; import java.util.concurrent.TimeUnit; @SuppressWarnings("NewClassNamingConvention") -@ExtendWith(VertxExtension.class) +@VertxTest public class HttpServerTestBase { protected int port; diff --git a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/PathParameterTest.java b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/PathParameterTest.java index aa4aa9fea7..ab03211db8 100644 --- a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/PathParameterTest.java +++ b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/PathParameterTest.java @@ -14,10 +14,11 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.vertx.core.Future; +import io.vertx.core.http.HttpResponseExpectation; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.openapi.router.RouterBuilder; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.Timeout; -import io.vertx.junit5.VertxTestContext; import io.vertx.openapi.validation.ValidatedRequest; import io.vertx.router.test.ResourceHelper; import io.vertx.router.test.base.RouterBuilderTestBase; @@ -37,22 +38,19 @@ class PathParameterTest extends RouterBuilderTestBase { @Timeout(value = 2, timeUnit = TimeUnit.MINUTES) @ParameterizedTest @ValueSource(strings = {"3", "-1"}) - void testPathParam(String id, VertxTestContext testContext) { + void testPathParam(String id) { Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("e2e").resolve("contract_various_scenarios.yaml"); createServer(pathDereferencedContract, rb -> { rb.getRoute("stringPathParameter").setDoSecurity(false).addHandler(rc -> { ValidatedRequest validatedRequest = rc.get(RouterBuilder.KEY_META_DATA_VALIDATED_REQUEST); - testContext.verify(() -> { - assertThat(validatedRequest.getPathParameters().get("id").getString()).isEqualTo(id); - }); + assertThat(validatedRequest.getPathParameters().get("id").getString()).isEqualTo(id); rc.response().setStatusCode(200).end(); }); return Future.succeededFuture(rb); - }).compose(v -> { - return createRequest(GET, "/v1/user/" + id).send().onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(HttpResponseStatus.OK.code()); - testContext.completeNow(); - })); - }).onFailure(testContext::failNow); + }).compose(v -> createRequest(GET, "/v1/user/" + id) + .send() + .expecting(HttpResponseExpectation.SC_OK) + ) + .await(); } } diff --git a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RootPathTest.java b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RootPathTest.java index ace3ee8b29..da939c2f41 100644 --- a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RootPathTest.java +++ b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RootPathTest.java @@ -14,13 +14,15 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.vertx.core.Future; +import io.vertx.core.http.HttpResponseExpectation; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.openapi.router.RouterBuilder; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.Timeout; -import io.vertx.junit5.VertxTestContext; import io.vertx.openapi.validation.ValidatedRequest; import io.vertx.router.test.ResourceHelper; import io.vertx.router.test.base.RouterBuilderTestBase; +import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.Test; import java.nio.file.Path; @@ -33,7 +35,7 @@ class RootPathTest extends RouterBuilderTestBase { @Test @Timeout(value = 2, timeUnit = TimeUnit.MINUTES) - void testRootPath(VertxTestContext testContext) { + void testRootPath() { Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("e2e").resolve("root.json"); createServer(pathDereferencedContract, rb -> { rb.getRoute("createPets") @@ -45,12 +47,10 @@ void testRootPath(VertxTestContext testContext) { return Future.succeededFuture(rb); }).compose(v -> { JsonObject body = new JsonObject().put("id", 1).put("name", "FooBar"); - return createRequest(POST, "/v1/").sendJsonObject(body) - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(HttpResponseStatus.CREATED.code()); - testContext.completeNow(); - })); + return createRequest(POST, "/v1/") + .sendJsonObject(body) + .expecting(HttpResponseExpectation.SC_CREATED); }) - .onFailure(testContext::failNow); + .await(); } } diff --git a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityAndAuthZTest.java b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityAndAuthZTest.java index 8e6415a68b..d35cd0cbe4 100644 --- a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityAndAuthZTest.java +++ b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityAndAuthZTest.java @@ -14,13 +14,14 @@ import io.vertx.core.Future; import io.vertx.core.Vertx; +import io.vertx.core.http.HttpResponseExpectation; import io.vertx.ext.auth.User; import io.vertx.ext.auth.authentication.AuthenticationProvider; import io.vertx.ext.auth.authorization.PermissionBasedAuthorization; import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.handler.APIKeyHandler; import io.vertx.ext.web.handler.AuthorizationHandler; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.Checkpoint; import io.vertx.router.test.ResourceHelper; import io.vertx.router.test.base.RouterBuilderTestBase; import org.junit.jupiter.api.Test; @@ -35,7 +36,7 @@ class RouterBuilderSecurityAndAuthZTest extends RouterBuilderTestBase { final Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("security").resolve("security_test.yaml"); @Test - public void mountSingle(Vertx vertx, VertxTestContext testContext) { + public void mountSingle(Vertx vertx) { AuthenticationProvider authProvider = cred -> { User user = User.fromName(cred.toString()); @@ -55,15 +56,10 @@ public void mountSingle(Vertx vertx, VertxTestContext testContext) { return Future.succeededFuture(rb); }) - .compose(v -> { - return createRequest(GET, "/v1/pets_single_security") - .putHeader("api_key", "test") - .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); - }) - .onSuccess(v -> testContext.completeNow()) - .onFailure(testContext::failNow); + .compose(v -> createRequest(GET, "/v1/pets_single_security") + .putHeader("api_key", "test") + .send() + .expecting(HttpResponseExpectation.SC_OK)) + .await(); } } diff --git a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityOptionalCallbackawareTest.java b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityOptionalCallbackawareTest.java index 04f5430931..1b45d6b7c4 100644 --- a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityOptionalCallbackawareTest.java +++ b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityOptionalCallbackawareTest.java @@ -20,7 +20,6 @@ import io.vertx.ext.auth.oauth2.providers.OpenIDConnectAuth; import io.vertx.ext.web.handler.OAuth2AuthHandler; import io.vertx.junit5.Timeout; -import io.vertx.junit5.VertxTestContext; import io.vertx.router.test.ResourceHelper; import io.vertx.router.test.base.RouterBuilderTestBase; import org.junit.jupiter.api.Test; @@ -28,15 +27,13 @@ import java.nio.file.Path; import java.util.concurrent.TimeUnit; -import static com.google.common.truth.Truth.assertThat; - class RouterBuilderSecurityOptionalCallbackawareTest extends RouterBuilderTestBase { final Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("security").resolve("security_optional_callbackaware.yaml"); @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testBuilderWithAuthn(VertxTestContext testContext) { + void testBuilderWithAuthn() { AuthenticationProvider authProvider = cred -> Future.succeededFuture(User.fromName(cred.toString())); @@ -67,7 +64,6 @@ void testBuilderWithAuthn(VertxTestContext testContext) { })) // this test may seem useless but it proves that the chain auth properly sets up a chain when the a handler // can perform redirects (callback aware) and doesn't throw an exception at setup time. - .onSuccess(v -> testContext.completeNow()) - .onFailure(testContext::failNow); + .await(); } } diff --git a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityOptionalTest.java b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityOptionalTest.java index c58a88500f..d9f684e8fc 100644 --- a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityOptionalTest.java +++ b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityOptionalTest.java @@ -13,20 +13,20 @@ package io.vertx.router.test.e2e; import io.vertx.core.Future; -import io.vertx.core.buffer.Buffer; +import io.vertx.core.http.HttpResponseExpectation; import io.vertx.ext.auth.User; import io.vertx.ext.auth.authentication.AuthenticationProvider; import io.vertx.ext.web.handler.APIKeyHandler; import io.vertx.junit5.Timeout; -import io.vertx.junit5.VertxTestContext; import io.vertx.router.test.ResourceHelper; import io.vertx.router.test.base.RouterBuilderTestBase; +import io.vertx.test.core.TestUtils; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.nio.file.Path; import java.util.concurrent.TimeUnit; -import static com.google.common.truth.Truth.assertThat; import static io.vertx.core.http.HttpMethod.GET; class RouterBuilderSecurityOptionalTest extends RouterBuilderTestBase { @@ -35,7 +35,7 @@ class RouterBuilderSecurityOptionalTest extends RouterBuilderTestBase { @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testBuilderWithAuthn(VertxTestContext testContext) { + void testBuilderWithAuthn() { AuthenticationProvider authProvider = cred -> Future.succeededFuture(User.fromName(cred.toString())); @@ -55,21 +55,12 @@ void testBuilderWithAuthn(VertxTestContext testContext) { return Future.succeededFuture(rb); }) - .compose(v -> { - return createRequest(GET, "/v1/pets").send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - assertThat(response.body()).isEqualTo(Buffer.buffer("null")); - })); - }) - .compose(v -> { - return createRequest(GET, "/v1/pets").putHeader("api_key", "123456789").send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - assertThat(response.body()).isEqualTo(Buffer.buffer("{\"username\":\"{\\\"token\\\":\\\"123456789\\\"}\"}")); - })); - }) - .onSuccess(v -> testContext.completeNow()) - .onFailure(testContext::failNow); + .compose(v -> createRequest(GET, "/v1/pets").send() + .expecting(HttpResponseExpectation.SC_OK) + .andThen(TestUtils.onSuccess2(response -> Assertions.assertEquals("null", response.bodyAsString())))) + .compose(v -> createRequest(GET, "/v1/pets").putHeader("api_key", "123456789").send() + .expecting(HttpResponseExpectation.SC_OK) + .andThen(TestUtils.onSuccess2(response -> Assertions.assertEquals("{\"username\":\"{\\\"token\\\":\\\"123456789\\\"}\"}", response.bodyAsString())))) + .await(); } } diff --git a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityScopesTest.java b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityScopesTest.java index 01ee3411fe..c6b69a421b 100644 --- a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityScopesTest.java +++ b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityScopesTest.java @@ -13,6 +13,7 @@ package io.vertx.router.test.e2e; import io.vertx.core.Future; +import io.vertx.core.http.HttpResponseExpectation; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.auth.JWTOptions; @@ -20,8 +21,8 @@ import io.vertx.ext.auth.jwt.JWTAuth; import io.vertx.ext.auth.jwt.JWTAuthOptions; import io.vertx.ext.web.handler.JWTAuthHandler; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.Timeout; -import io.vertx.junit5.VertxTestContext; import io.vertx.router.test.ResourceHelper; import io.vertx.router.test.base.RouterBuilderTestBase; import org.junit.jupiter.api.Test; @@ -39,7 +40,7 @@ class RouterBuilderSecurityScopesTest extends RouterBuilderTestBase { @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testBuilderWithAuthn(VertxTestContext testContext) { + void testBuilderWithAuthn() { JWTAuth authProvider = JWTAuth.create(vertx, new JWTAuthOptions() .setKeyStore(new KeyStoreOptions() @@ -71,28 +72,16 @@ void testBuilderWithAuthn(VertxTestContext testContext) { return createRequest(GET, "/v1/two_scopes_required") .putHeader("Authorization", "Bearer " + authProvider.generateToken(new JsonObject().put("sub", "paulo").put("scope", new JsonArray().add("read").add("write")), new JWTOptions())) .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); + .expecting(HttpResponseExpectation.SC_OK); }) - .compose(v -> { - return createRequest(GET, "/v1/one_scope_required") - .putHeader("Authorization", "Bearer " + authProvider.generateToken(new JsonObject().put("sub", "paulo").put("scope", new JsonArray().add("read")), new JWTOptions())) - .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); - }) - .compose(v -> { - return createRequest(GET, "/v1/no_scopes") - .putHeader("Authorization", "Bearer " + authProvider.generateToken(new JsonObject().put("sub", "paulo"), new JWTOptions())) - .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - assertThat(response.bodyAsJsonArray()).isNull(); - })); - }) - .onSuccess(v -> testContext.completeNow()) - .onFailure(testContext::failNow); + .compose(v -> createRequest(GET, "/v1/one_scope_required") + .putHeader("Authorization", "Bearer " + authProvider.generateToken(new JsonObject().put("sub", "paulo").put("scope", new JsonArray().add("read")), new JWTOptions())) + .send() + .expecting(HttpResponseExpectation.SC_OK)) + .compose(v -> createRequest(GET, "/v1/no_scopes") + .putHeader("Authorization", "Bearer " + authProvider.generateToken(new JsonObject().put("sub", "paulo"), new JWTOptions())) + .send() + .expecting(HttpResponseExpectation.SC_OK)) + .await(); } } diff --git a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityTest.java b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityTest.java index ded37de205..3918704a7a 100644 --- a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityTest.java +++ b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderSecurityTest.java @@ -14,6 +14,7 @@ import io.vertx.core.Future; import io.vertx.core.Vertx; +import io.vertx.core.http.HttpResponseExpectation; import io.vertx.core.http.HttpServer; import io.vertx.core.json.JsonObject; import io.vertx.ext.auth.User; @@ -23,8 +24,8 @@ import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.handler.APIKeyHandler; import io.vertx.ext.web.handler.OAuth2AuthHandler; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.Timeout; -import io.vertx.junit5.VertxTestContext; import io.vertx.router.test.ResourceHelper; import io.vertx.router.test.base.RouterBuilderTestBase; import org.junit.jupiter.api.Test; @@ -43,7 +44,7 @@ class RouterBuilderSecurityTest extends RouterBuilderTestBase { @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testBuilderWithAuthn(VertxTestContext testContext) { + void testBuilderWithAuthn() { createServer(pathDereferencedContractGlobal, rb -> { rb.security("api_key") .apiKeyHandler(APIKeyHandler.create(null)) @@ -51,13 +52,12 @@ void testBuilderWithAuthn(VertxTestContext testContext) { .apiKeyHandler(APIKeyHandler.create(null)); return Future.succeededFuture(rb); }) - .onSuccess(v -> testContext.completeNow()) - .onFailure(testContext::failNow); + .await(); } @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testBuilderWithDisabledSecurity(VertxTestContext testContext) { + void testBuilderWithDisabledSecurity() { createServer(pathDereferencedContractGlobal, rb -> { rb .getRoutes() @@ -77,16 +77,13 @@ void testBuilderWithDisabledSecurity(VertxTestContext testContext) { */ return createRequest(GET, "/v1/petsWithOverride") .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); + .expecting(HttpResponseExpectation.SC_OK); }) - .onSuccess(v -> testContext.completeNow()) - .onFailure(testContext::failNow); + .await(); } @Test - public void mountSingle(Vertx vertx, VertxTestContext testContext) { + public void mountSingle(Vertx vertx) { AuthenticationProvider authProvider = cred -> Future.succeededFuture(User.fromName(cred.toString())); @@ -193,57 +190,33 @@ public void mountSingle(Vertx vertx, VertxTestContext testContext) { return Future.succeededFuture(rb); }) - .compose(v -> { - return createRequest(GET, "/v1/pets_single_security") - .putHeader("api_key", "test") - .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); - }) - .compose(v -> { - return createRequest(GET, "/v1/pets_and_security") - .putHeader("api_key", "test") - .putHeader("second_api_key", "test") - .putHeader("third_api_key", "test") - .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); - }) - .compose(v -> { - return createRequest(GET, "/v1/pets_or_security") - .putHeader("api_key", "test") - .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); - }) - .compose(v -> { - return createRequest(GET, "/v1/pets_or_security") - .putHeader("second_api_key", "test") - .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); - }) - .compose(v -> { - return createRequest(GET, "/v1/pets_or_and_security") - .putHeader("api_key", "test") - .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); - }) - .compose(v -> { - return createRequest(GET, "/v1/pets_or_and_security") - .putHeader("second_api_key", "test") - .putHeader("sibling_second_api_key", "test") - .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); - }) + .compose(v -> createRequest(GET, "/v1/pets_single_security") + .putHeader("api_key", "test") + .send() + .expecting(HttpResponseExpectation.SC_OK)) + .compose(v -> createRequest(GET, "/v1/pets_and_security") + .putHeader("api_key", "test") + .putHeader("second_api_key", "test") + .putHeader("third_api_key", "test") + .send() + .expecting(HttpResponseExpectation.SC_OK)) + .compose(v -> createRequest(GET, "/v1/pets_or_security") + .putHeader("api_key", "test") + .send() + .expecting(HttpResponseExpectation.SC_OK)) + .compose(v -> createRequest(GET, "/v1/pets_or_security") + .putHeader("second_api_key", "test") + .send() + .expecting(HttpResponseExpectation.SC_OK)) + .compose(v -> createRequest(GET, "/v1/pets_or_and_security") + .putHeader("api_key", "test") + .send() + .expecting(HttpResponseExpectation.SC_OK)) + .compose(v -> createRequest(GET, "/v1/pets_or_and_security") + .putHeader("second_api_key", "test") + .putHeader("sibling_second_api_key", "test") + .send() + .expecting(HttpResponseExpectation.SC_OK)) .compose(v -> { // This is a complicated one: // 1. We make a bare request @@ -258,12 +231,8 @@ public void mountSingle(Vertx vertx, VertxTestContext testContext) { return createRequest(GET, "/v1/pets_oauth2") .send() - .onSuccess(response -> testContext.verify(() -> { - assertThat(response.statusCode()).isEqualTo(200); - })); - }) - .onSuccess(v -> testContext.completeNow()) - .onFailure(testContext::failNow); - }); + .expecting(HttpResponseExpectation.SC_OK); + }); + }).await(); } } diff --git a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderTest.java b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderTest.java index dcdfde1a18..1b142b77c2 100644 --- a/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderTest.java +++ b/vertx-web-openapi-router/src/test/java/io/vertx/router/test/e2e/RouterBuilderTest.java @@ -14,22 +14,25 @@ import io.vertx.core.Future; import io.vertx.core.Handler; +import io.vertx.core.buffer.Buffer; import io.vertx.core.json.Json; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; +import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.handler.BodyHandler; import io.vertx.ext.web.openapi.router.RouterBuilder; import io.vertx.junit5.Checkpoint; import io.vertx.junit5.Timeout; -import io.vertx.junit5.VertxTestContext; import io.vertx.openapi.validation.ValidatedRequest; import io.vertx.router.test.ResourceHelper; import io.vertx.router.test.base.RouterBuilderTestBase; +import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import java.nio.file.Path; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.function.Function; @@ -46,56 +49,56 @@ class RouterBuilderTest extends RouterBuilderTestBase { @ParameterizedTest(name = "{index} should load and mount all operations of an OpenAPI ({0}) contract") @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) @ValueSource(strings = {"v3.0", "v3.1"}) - void testRouter(String version, VertxTestContext testContext) { - Checkpoint cpListPets = testContext.checkpoint(2); - Checkpoint cpCreatePets = testContext.checkpoint(2); - Checkpoint cpShowPetById = testContext.checkpoint(2); + void testRouter(String version, Checkpoint cpListPets, Checkpoint cpCreatePets, Checkpoint cpShowPetById) { + CountDownLatch latchListPets = cpListPets.asLatch(2); + CountDownLatch latchCreatePets = cpCreatePets.asLatch(2); + CountDownLatch latchShowPetById = cpShowPetById.asLatch(2); - Function> buildCheckpointHandler = cp -> rc -> { + Function> buildCheckpointHandler = cp -> rc -> { ValidatedRequest validatedRequest = rc.get(RouterBuilder.KEY_META_DATA_VALIDATED_REQUEST); - cp.flag(); - rc.response().send(Json.encode(validatedRequest)).onFailure(testContext::failNow); + cp.countDown(); + rc.response().send(Json.encode(validatedRequest)); }; Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve(version).resolve("petstore.json"); - createServer(pathDereferencedContract, rb -> { + HttpResponse response = createServer(pathDereferencedContract, rb -> { rb.getRoute("listPets") .setDoSecurity(false) - .addHandler(buildCheckpointHandler.apply(cpListPets)); + .addHandler(buildCheckpointHandler.apply(latchListPets)); rb.getRoute("createPets") .setDoSecurity(false) - .addHandler(buildCheckpointHandler.apply(cpCreatePets)); + .addHandler(buildCheckpointHandler.apply(latchCreatePets)); rb.getRoute("showPetById") .setDoSecurity(false) - .addHandler(buildCheckpointHandler.apply(cpShowPetById)); + .addHandler(buildCheckpointHandler.apply(latchShowPetById)); return Future.succeededFuture(rb); - }).compose(v -> createRequest(GET, "/v1/pets").addQueryParam("limit", "42").send()) - .onSuccess(response -> testContext.verify(() -> { - JsonObject query = response.bodyAsJsonObject().getJsonObject("query"); + }).compose(v -> createRequest(GET, "/v1/pets") + .addQueryParam("limit", "42").send()) + .onComplete(TestUtils.onSuccess2(r -> { + JsonObject query = r.bodyAsJsonObject().getJsonObject("query"); assertThat(query.getJsonObject("limit").getMap()).containsEntry("long", 42); - cpListPets.flag(); + latchListPets.countDown(); })) .compose(v -> { JsonObject bodyJson = new JsonObject().put("id", 1).put("name", "FooBar"); - return createRequest(POST, "/v1/pets").sendJsonObject(bodyJson).onSuccess(response -> testContext.verify(() -> { - JsonObject body = response.bodyAsJsonObject().getJsonObject("body"); + return createRequest(POST, "/v1/pets") + .sendJsonObject(bodyJson).onComplete(TestUtils.onSuccess2(r -> { + JsonObject body = r.bodyAsJsonObject().getJsonObject("body"); JsonObject bodyValueAsJson = body.getJsonObject("jsonObject"); assertThat(bodyValueAsJson).isEqualTo(bodyJson); - cpCreatePets.flag(); + latchCreatePets.countDown(); })); }) .compose(v -> createRequest(GET, "/v1/pets/foobar").send()) - .onSuccess(response -> testContext.verify(() -> { - JsonObject path = response.bodyAsJsonObject().getJsonObject("pathParameters"); - assertThat(path.getJsonObject("petId").getMap()).containsEntry("string", "foobar"); - cpShowPetById.flag(); - })) - .onFailure(testContext::failNow); + .await(); + JsonObject path = response.bodyAsJsonObject().getJsonObject("pathParameters"); + assertThat(path.getJsonObject("petId").getMap()).containsEntry("string", "foobar"); + latchShowPetById.countDown(); } @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testRouterWithoutValidation(VertxTestContext testContext) { + void testRouterWithoutValidation(Checkpoint checkpoint) { Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("v3.1").resolve("petstore.json"); createServer(pathDereferencedContract, rb -> { rb.rootHandler(BodyHandler.create()).getRoute("createPets") @@ -106,42 +109,41 @@ void testRouterWithoutValidation(VertxTestContext testContext) { }).compose(v -> { JsonObject invalidBodyJson = new JsonObject().put("foo", "bar"); return createRequest(POST, "/v1/pets").sendJsonObject(invalidBodyJson) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { assertThat(response.bodyAsJsonObject()).isEqualTo(invalidBodyJson); - testContext.completeNow(); + checkpoint.flag(); })); }) - .onFailure(testContext::failNow); + .await(); } @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testRouterWithCustomRequestExtractor(VertxTestContext testContext) { + void testRouterWithCustomRequestExtractor(Checkpoint checkpoint, Checkpoint cp2) { Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("v3.1").resolve("petstore.json"); createServer(pathDereferencedContract, contract -> RouterBuilder.create(vertx, contract, withBodyHandler()), rb -> { rb.rootHandler(BodyHandler.create()).getRoute("createPets") .setDoSecurity(false) .addHandler(rc -> { ValidatedRequest validatedRequest = rc.get(RouterBuilder.KEY_META_DATA_VALIDATED_REQUEST); - rc.response().send(Json.encode(validatedRequest)).onFailure(testContext::failNow); + rc.response().send(Json.encode(validatedRequest)).onComplete(cp2); }); return Future.succeededFuture(rb); }).compose(v -> { JsonObject bodyJson = new JsonObject().put("id", 1).put("name", "FooBar"); return createRequest(POST, "/v1/pets").sendJsonObject(bodyJson) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { JsonObject body = response.bodyAsJsonObject().getJsonObject("body"); JsonObject bodyValueAsJson = body.getJsonObject("jsonObject"); assertThat(bodyValueAsJson).isEqualTo(bodyJson); - testContext.completeNow(); + checkpoint.flag(); })); - }) - .onFailure(testContext::failNow); + }).await(); } @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testRouterWithInvalidRequest(VertxTestContext testContext) { + void testRouterWithInvalidRequest(Checkpoint checkpoint) { Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("v3.1").resolve("petstore.json"); createServer(pathDereferencedContract, rb -> { rb.getRoute("createPets") @@ -151,63 +153,65 @@ void testRouterWithInvalidRequest(VertxTestContext testContext) { }).compose(v -> { JsonObject invalidBodyJson = new JsonObject().put("foo", "bar"); return createRequest(POST, "/v1/pets").sendJsonObject(invalidBodyJson) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { assertThat(response.statusCode()).isEqualTo(BAD_REQUEST.code()); assertThat(response.statusMessage()).isEqualTo(BAD_REQUEST.reasonPhrase()); - testContext.completeNow(); + checkpoint.flag(); })); }) - .onFailure(testContext::failNow); + .await(); } @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testRouterWithNoHandlerReturns501NotImplemented(VertxTestContext testContext) { + void testRouterWithNoHandlerReturns501NotImplemented(Checkpoint checkpoint) { Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("v3.1").resolve("petstore.json"); createServer(pathDereferencedContract, rb -> { // Intentionally do NOT add any handlers for the operations // This will trigger the default behavior of returning 501 Not Implemented return Future.succeededFuture(rb); }).compose(v -> createRequest(GET, "/v1/pets").send()) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { assertThat(response.statusCode()).isEqualTo(NOT_IMPLEMENTED.code()); - testContext.completeNow(); + checkpoint.flag(); })) - .onFailure(testContext::failNow); + .await(); } @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testRouterWithNoHandlersReturns501ForAllOperations(VertxTestContext testContext) { - Checkpoint cpAllOperations = testContext.checkpoint(3); + void testRouterWithNoHandlersReturns501ForAllOperations( + Checkpoint cpAllOperations) { + CountDownLatch latchAllOperations = cpAllOperations.asLatch(3); Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("v3.1").resolve("petstore.json"); createServer(pathDereferencedContract, rb -> Future.succeededFuture(rb)) .compose(v -> createRequest(GET, "/v1/pets").send()) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { assertThat(response.statusCode()).isEqualTo(NOT_IMPLEMENTED.code()); - cpAllOperations.flag(); + latchAllOperations.countDown(); })) .compose(v -> { JsonObject bodyJson = new JsonObject().put("id", 1).put("name", "FooBar"); return createRequest(POST, "/v1/pets").sendJsonObject(bodyJson); }) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { assertThat(response.statusCode()).isEqualTo(NOT_IMPLEMENTED.code()); - cpAllOperations.flag(); + latchAllOperations.countDown(); })) .compose(v -> createRequest(GET, "/v1/pets/123").send()) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { assertThat(response.statusCode()).isEqualTo(NOT_IMPLEMENTED.code()); - cpAllOperations.flag(); + latchAllOperations.countDown(); })) - .onFailure(testContext::failNow); + .await(); } @Test @Timeout(value = 2, timeUnit = TimeUnit.SECONDS) - void testRouterWithPartialHandlersReturns501ForUnimplemented(VertxTestContext testContext) { - Checkpoint cpAllOperations = testContext.checkpoint(3); + void testRouterWithPartialHandlersReturns501ForUnimplemented( + Checkpoint cpAllOperations) { + CountDownLatch latchAllOperations = cpAllOperations.asLatch(3); Path pathDereferencedContract = ResourceHelper.TEST_RESOURCE_PATH.resolve("v3.1").resolve("petstore.json"); createServer(pathDereferencedContract, rb -> { @@ -220,23 +224,23 @@ void testRouterWithPartialHandlersReturns501ForUnimplemented(VertxTestContext te .addHandler(rc -> rc.response().setStatusCode(OK.code()).end()); return Future.succeededFuture(rb); }).compose(v -> createRequest(GET, "/v1/pets").send()) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { assertThat(response.statusCode()).isEqualTo(OK.code()); - cpAllOperations.flag(); + latchAllOperations.countDown(); })) .compose(v -> { JsonObject bodyJson = new JsonObject().put("id", 1).put("name", "FooBar"); return createRequest(POST, "/v1/pets").sendJsonObject(bodyJson); }) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { assertThat(response.statusCode()).isEqualTo(OK.code()); - cpAllOperations.flag(); + latchAllOperations.countDown(); })) .compose(v -> createRequest(GET, "/v1/pets/123").send()) - .onSuccess(response -> testContext.verify(() -> { + .onComplete(TestUtils.onSuccess2(response -> { assertThat(response.statusCode()).isEqualTo(NOT_IMPLEMENTED.code()); - cpAllOperations.flag(); + latchAllOperations.countDown(); })) - .onFailure(testContext::failNow); + .await(); } } diff --git a/vertx-web-openapi-router/src/test/java/module-info.java b/vertx-web-openapi-router/src/test/java/module-info.java index c817f07f57..6d74764492 100644 --- a/vertx-web-openapi-router/src/test/java/module-info.java +++ b/vertx-web-openapi-router/src/test/java/module-info.java @@ -10,6 +10,7 @@ requires org.mockito; requires static io.vertx.auth.oauth2; requires static io.vertx.auth.jwt; - exports io.vertx.router.test.base; + requires io.vertx.core.tests; + exports io.vertx.router.test.base; exports io.vertx.router.test; } diff --git a/vertx-web-proxy/src/test/java/io/vertx/ext/web/proxy/tests/WebProxyTestBase.java b/vertx-web-proxy/src/test/java/io/vertx/ext/web/proxy/tests/WebProxyTestBase.java index c469fb99e0..09bea5cf8f 100644 --- a/vertx-web-proxy/src/test/java/io/vertx/ext/web/proxy/tests/WebProxyTestBase.java +++ b/vertx-web-proxy/src/test/java/io/vertx/ext/web/proxy/tests/WebProxyTestBase.java @@ -7,7 +7,6 @@ import io.vertx.core.http.HttpServerOptions; import io.vertx.ext.web.Router; import io.vertx.ext.web.tests.WebTestBase; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -22,8 +21,8 @@ public class WebProxyTestBase extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); backendRouter = Router.router(vertx); backendServer = vertx.createHttpServer(getBackendServerOptions()); proxyClient = vertx.createHttpClient(getProxyClientOptions()); @@ -40,13 +39,13 @@ protected HttpClientOptions getProxyClientOptions() { @Override @AfterEach - public void tearDown(VertxTestContext testContext) throws Exception { + public void tearDown() throws Exception { if (proxyClient != null) { proxyClient.close().await(); } if (backendServer != null) { backendServer.close().await(); } - super.tearDown(testContext); + super.tearDown(); } } diff --git a/vertx-web-session-stores/vertx-web-sstore-caffeine/src/test/java/io/vertx/ext/web/sstore/caffeine/tests/CaffeineSessionHandlerTest.java b/vertx-web-session-stores/vertx-web-sstore-caffeine/src/test/java/io/vertx/ext/web/sstore/caffeine/tests/CaffeineSessionHandlerTest.java index 29e8a710d2..fdf5e5df94 100644 --- a/vertx-web-session-stores/vertx-web-sstore-caffeine/src/test/java/io/vertx/ext/web/sstore/caffeine/tests/CaffeineSessionHandlerTest.java +++ b/vertx-web-session-stores/vertx-web-sstore-caffeine/src/test/java/io/vertx/ext/web/sstore/caffeine/tests/CaffeineSessionHandlerTest.java @@ -5,7 +5,6 @@ import io.vertx.ext.web.handler.SessionHandler; import io.vertx.ext.web.sstore.caffeine.CaffeineSessionStore; import io.vertx.ext.web.tests.handler.SessionHandlerTestBase; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -18,8 +17,8 @@ public class CaffeineSessionHandlerTest extends SessionHandlerTestBase { @BeforeEach @Override - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); store = CaffeineSessionStore.create(vertx); } diff --git a/vertx-web-session-stores/vertx-web-sstore-cookie/src/test/java/io/vertx/ext/web/sstore/cookie/tests/CookieSessionHandlerTest.java b/vertx-web-session-stores/vertx-web-sstore-cookie/src/test/java/io/vertx/ext/web/sstore/cookie/tests/CookieSessionHandlerTest.java index 5654048210..9099dd235b 100644 --- a/vertx-web-session-stores/vertx-web-sstore-cookie/src/test/java/io/vertx/ext/web/sstore/cookie/tests/CookieSessionHandlerTest.java +++ b/vertx-web-session-stores/vertx-web-sstore-cookie/src/test/java/io/vertx/ext/web/sstore/cookie/tests/CookieSessionHandlerTest.java @@ -31,7 +31,6 @@ import io.vertx.ext.web.handler.SimpleAuthenticationHandler; import io.vertx.ext.web.sstore.cookie.CookieSessionStore; import io.vertx.ext.web.tests.handler.SessionHandlerTestBase; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -47,8 +46,8 @@ public class CookieSessionHandlerTest extends SessionHandlerTestBase { @BeforeEach @Override - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); store = CookieSessionStore.create(vertx, "KeyboardCat!"); } diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/BaseValidationHandlerTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/BaseValidationHandlerTest.java index dcf4baadba..d4c9db548e 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/BaseValidationHandlerTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/BaseValidationHandlerTest.java @@ -9,13 +9,11 @@ import io.vertx.json.schema.Draft; import io.vertx.json.schema.JsonSchemaOptions; import io.vertx.json.schema.SchemaRepository; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtendWith; -@ExtendWith(VertxExtension.class) +@VertxTest public abstract class BaseValidationHandlerTest { public SchemaRepository schemaRepo; diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/ValidationHandlerPredicatesIntegrationTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/ValidationHandlerPredicatesIntegrationTest.java index a309e252a5..63af3ee0e0 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/ValidationHandlerPredicatesIntegrationTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/ValidationHandlerPredicatesIntegrationTest.java @@ -8,13 +8,12 @@ import io.vertx.ext.web.validation.ValidationHandler; import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; import java.nio.file.Path; +import java.util.concurrent.CountDownLatch; import java.util.regex.Pattern; import static io.vertx.ext.web.validation.tests.testutils.TestRequest.statusCode; @@ -25,12 +24,12 @@ * @author Francesco Guardiani @slinkydeveloper */ @SuppressWarnings("unchecked") -@ExtendWith(VertxExtension.class) +@VertxTest public class ValidationHandlerPredicatesIntegrationTest extends BaseValidationHandlerTest { @Test - public void testRequiredBodyPredicate(VertxTestContext testContext, @TempDir Path tempDir) { - Checkpoint checkpoint = testContext.checkpoint(3); + public void testRequiredBodyPredicate(@TempDir Path tempDir, Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(3); ValidationHandler validationHandler = ValidationHandlerBuilder.create(schemaRepo) .predicate(RequestPredicate.BODY_REQUIRED) @@ -48,20 +47,20 @@ public void testRequiredBodyPredicate(VertxTestContext testContext, @TempDir Pat testRequest(client, HttpMethod.POST, "/testRequiredBody") .expect(statusCode(200)) - .sendJson(new JsonObject(), testContext, checkpoint); + .sendJson(new JsonObject(), latch::countDown); testRequest(client, HttpMethod.GET, "/testRequiredBody") .expect(statusCode(400), failurePredicateResponse()) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.POST, "/testRequiredBody") .expect(statusCode(400), failurePredicateResponse()) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testFileUploadExists(VertxTestContext testContext, @TempDir Path tempDir) { - Checkpoint checkpoint = testContext.checkpoint(4); + public void testFileUploadExists(@TempDir Path tempDir, Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(4); ValidationHandler validationHandler = ValidationHandlerBuilder.create(schemaRepo) .predicate(RequestPredicate.multipartFileUploadExists( @@ -82,20 +81,20 @@ public void testFileUploadExists(VertxTestContext testContext, @TempDir Path tem testRequest(client, HttpMethod.POST, "/testFileUpload") .expect(statusCode(200)) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.POST, "/testFileUpload") .expect(statusCode(400)) - .sendMultipartForm(MultipartForm.create(), testContext, checkpoint); + .sendMultipartForm(MultipartForm.create(), latch::countDown); testRequest(client, HttpMethod.POST, "/testFileUpload") .expect(statusCode(400)) - .sendMultipartForm(MultipartForm.create().attribute("myfile", "bla"), testContext, checkpoint); + .sendMultipartForm(MultipartForm.create().attribute("myfile", "bla"), latch::countDown); testRequest(client, HttpMethod.POST, "/testFileUpload") .expect(statusCode(200)) .sendMultipartForm(MultipartForm.create().textFileUpload("myfile", "myfile.txt", "src/test/resources/myfile" + - ".txt", "text/plain"), testContext, checkpoint); + ".txt", "text/plain"), latch::countDown); } } diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/ValidationHandlerProcessorsIntegrationTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/ValidationHandlerProcessorsIntegrationTest.java index e817a2607c..97d488ccf4 100755 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/ValidationHandlerProcessorsIntegrationTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/ValidationHandlerProcessorsIntegrationTest.java @@ -22,15 +22,14 @@ import io.vertx.json.schema.common.dsl.ObjectSchemaBuilder; import io.vertx.json.schema.common.dsl.SchemaBuilder; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; import java.net.URI; import java.nio.file.Path; +import java.util.concurrent.CountDownLatch; import java.util.stream.Collectors; import static io.vertx.ext.web.validation.builder.Parameters.explodedParam; @@ -59,12 +58,12 @@ /** * @author Francesco Guardiani @slinkydeveloper */ -@ExtendWith(VertxExtension.class) +@VertxTest public class ValidationHandlerProcessorsIntegrationTest extends BaseValidationHandlerTest { @Test - public void testPathParamsSimpleTypes(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testPathParamsSimpleTypes(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(2); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -88,7 +87,7 @@ public void testPathParamsSimpleTypes(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, String.format("/testPathParams/%s/%s/%s", a, b, c)) .expect(statusCode(200), statusMessage(a + b + c)) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/testPathParams/hello/bla/10") .expect(statusCode(400)) @@ -97,12 +96,12 @@ public void testPathParamsSimpleTypes(VertxTestContext testContext) { "b", ParameterLocation.PATH )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testQueryParamsSimpleTypes(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testQueryParamsSimpleTypes(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(2); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -120,7 +119,7 @@ public void testQueryParamsSimpleTypes(VertxTestContext testContext) { }); testRequest(client, HttpMethod.GET, "/testQueryParams?param1=true¶m2=10") .expect(statusCode(200), statusMessage("true10")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/testQueryParams?param1=true¶m2=bla") .expect(statusCode(400)) @@ -129,13 +128,13 @@ public void testQueryParamsSimpleTypes(VertxTestContext testContext) { "param2", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test @Disabled("Due to an issue with circular references, which is not understood yet.") - public void testQueryJsonObjectAsyncParam(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testQueryJsonObjectAsyncParam(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(2); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -160,7 +159,7 @@ public void testQueryJsonObjectAsyncParam(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test?myTree=" + urlEncode(testSuccessObj.encode())) .expect(statusCode(200), jsonBodyResponse(testSuccessObj)) - .send(testContext, checkpoint); + .send(latch::countDown); JsonObject testFailureObj = testSuccessObj.copy(); testFailureObj.remove("value"); @@ -172,12 +171,12 @@ public void testQueryJsonObjectAsyncParam(VertxTestContext testContext) { "myTree", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testQueryParamsAsyncValidation(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(4); + public void testQueryParamsAsyncValidation(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(4); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -196,7 +195,7 @@ public void testQueryParamsAsyncValidation(VertxTestContext testContext) { }); testRequest(client, HttpMethod.GET, "/test?param1=true¶m2=5") .expect(statusCode(200), statusMessage("true5")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?param1=bla¶m2=5") .expect(statusCode(400)) @@ -205,7 +204,7 @@ public void testQueryParamsAsyncValidation(VertxTestContext testContext) { "param1", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?param1=true¶m2=bla") .expect(statusCode(400)) @@ -214,7 +213,7 @@ public void testQueryParamsAsyncValidation(VertxTestContext testContext) { "param2", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?param1=true¶m2=15") .expect(statusCode(400)) @@ -223,12 +222,12 @@ public void testQueryParamsAsyncValidation(VertxTestContext testContext) { "param2", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testQueryParamOptional(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(3); + public void testQueryParamOptional(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(3); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -247,11 +246,11 @@ public void testQueryParamOptional(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/testQueryParams?param1=true¶m2=10") .expect(statusCode(200), statusMessage("true10")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/testQueryParams?param1=true") .expect(statusCode(200), statusMessage("truenull")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/testQueryParams?param1=true¶m2=bla") .expect(statusCode(400)) @@ -260,12 +259,12 @@ public void testQueryParamOptional(VertxTestContext testContext) { "param2", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testQueryParamArrayExploded(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(3); + public void testQueryParamArrayExploded(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(3); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -285,7 +284,7 @@ public void testQueryParamArrayExploded(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test?parameter=2¶meter=4¶meter=6") .expect(statusCode(200), statusMessage("2,4,6")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?parameter=2¶meter=2¶meter=false") .expect(statusCode(400)) @@ -294,7 +293,7 @@ public void testQueryParamArrayExploded(VertxTestContext testContext) { "parameter", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?parameter=2¶meter=2¶meter=1") .expect(statusCode(400)) @@ -303,12 +302,12 @@ public void testQueryParamArrayExploded(VertxTestContext testContext) { "parameter", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testQueryParamArrayCommaSeparated(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(3); + public void testQueryParamArrayCommaSeparated(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(3); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -330,7 +329,7 @@ public void testQueryParamArrayCommaSeparated(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test?parameter=" + urlEncode("2,4,6")) .expect(statusCode(200), statusMessage("2,4,6")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?parameter=" + urlEncode("1,false,3")) .expect(statusCode(400)) @@ -339,7 +338,7 @@ public void testQueryParamArrayCommaSeparated(VertxTestContext testContext) { "parameter", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?parameter=" + urlEncode("6,2,1")) .expect(statusCode(400)) @@ -348,13 +347,13 @@ public void testQueryParamArrayCommaSeparated(VertxTestContext testContext) { "parameter", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testQueryParamDefault(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(3); + public void testQueryParamDefault(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(3); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -373,11 +372,11 @@ public void testQueryParamDefault(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test?param1=5¶m2=10") .expect(statusCode(200), statusMessage("510")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?param2=10") .expect(statusCode(200), statusMessage("1010")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?param1=5") .expect(statusCode(400)) @@ -386,13 +385,13 @@ public void testQueryParamDefault(VertxTestContext testContext) { "param2", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testQueryArrayParamsArrayAndPathParam(VertxTestContext testContext) throws Exception { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testQueryArrayParamsArrayAndPathParam(Checkpoint checkpoint) throws Exception { + CountDownLatch latch = checkpoint.asLatch(2); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -415,7 +414,7 @@ public void testQueryArrayParamsArrayAndPathParam(VertxTestContext testContext) testRequest(client, HttpMethod.GET, "/testQueryParams/true?awesomeArray=1&awesomeArray=2&awesomeArray=3" + "&anotherParam=5.2") .expect(statusCode(200), statusMessage("true" + new JsonArray().add(1).add(2).add(3).toString() + "5.2")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/testQueryParams/true?awesomeArray=1&awesomeArray=bla&awesomeArray=3" + "&anotherParam=5.2") @@ -425,12 +424,12 @@ public void testQueryArrayParamsArrayAndPathParam(VertxTestContext testContext) "awesomeArray", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testHeaderParamsSimpleTypes(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testHeaderParamsSimpleTypes(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(2); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -456,7 +455,7 @@ public void testHeaderParamsSimpleTypes(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/testHeaderParams") .with(requestHeader("x-a", a), requestHeader("x-b", b), requestHeader("x-c", c)) .expect(statusCode(200), statusMessage(a + b + c)) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/testHeaderParams") .with(requestHeader("x-a", a), requestHeader("x-b", "bla"), requestHeader("x-c", c)) @@ -465,12 +464,12 @@ public void testHeaderParamsSimpleTypes(VertxTestContext testContext) { "x-b", ParameterLocation.HEADER )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testHeaderParamsAsync(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(4); + public void testHeaderParamsAsync(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(4); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -497,7 +496,7 @@ public void testHeaderParamsAsync(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test") .with(requestHeader("x-a", a), requestHeader("x-b", b), requestHeader("x-c", c)) .expect(statusCode(200), statusMessage(a + b + c)) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test") .with(requestHeader("x-a", a), requestHeader("x-b", "bla"), requestHeader("x-c", c)) @@ -506,7 +505,7 @@ public void testHeaderParamsAsync(VertxTestContext testContext) { "x-b", ParameterLocation.HEADER )) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test") .with(requestHeader("x-a", a), requestHeader("x-b", b), requestHeader("x-c", "bla")) @@ -515,7 +514,7 @@ public void testHeaderParamsAsync(VertxTestContext testContext) { "x-c", ParameterLocation.HEADER )) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test") .with(requestHeader("x-a", a), requestHeader("x-b", b), requestHeader("x-c", "15")) @@ -524,12 +523,12 @@ public void testHeaderParamsAsync(VertxTestContext testContext) { "x-c", ParameterLocation.HEADER )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testCookieParamsSimpleTypes(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testCookieParamsSimpleTypes(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(2); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -556,7 +555,7 @@ public void testCookieParamsSimpleTypes(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/testCookieParams") .with(cookie(successParams)) .expect(statusCode(200), statusMessage("true10")) - .send(testContext, checkpoint); + .send(latch::countDown); QueryStringEncoder failureParams = new QueryStringEncoder("/"); failureParams.addParam("param1", "true"); @@ -570,12 +569,12 @@ public void testCookieParamsSimpleTypes(VertxTestContext testContext) { "param2", ParameterLocation.COOKIE )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testCookieParamsAsync(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(3); + public void testCookieParamsAsync(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(3); ValidationHandler validationHandler = ValidationHandlerBuilder .create(schemaRepo) @@ -602,7 +601,7 @@ public void testCookieParamsAsync(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test") .with(cookie(successParams)) .expect(statusCode(200), statusMessage("true10")) - .send(testContext, checkpoint); + .send(latch::countDown); QueryStringEncoder failureParams1 = new QueryStringEncoder("/"); failureParams1.addParam("param1", "true"); @@ -615,7 +614,7 @@ public void testCookieParamsAsync(VertxTestContext testContext) { "param2", ParameterLocation.COOKIE )) - .send(testContext, checkpoint); + .send(latch::countDown); QueryStringEncoder failureParams2 = new QueryStringEncoder("/"); failureParams2.addParam("param1", "true"); @@ -628,12 +627,12 @@ public void testCookieParamsAsync(VertxTestContext testContext) { "param2", ParameterLocation.COOKIE )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testFormURLEncoded(VertxTestContext testContext, @TempDir Path tempDir) throws Exception { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testFormURLEncoded(@TempDir Path tempDir, Checkpoint checkpoint) throws Exception { + CountDownLatch latch = checkpoint.asLatch(2); ValidationHandler validationHandler = ValidationHandlerBuilder.create(schemaRepo) .body(Bodies.formUrlEncoded(objectSchema().requiredProperty("parameter", intSchema()))) @@ -653,19 +652,19 @@ public void testFormURLEncoded(VertxTestContext testContext, @TempDir Path tempD testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(200), statusMessage("5")) - .sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("parameter", "5"), testContext, checkpoint); + .sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("parameter", "5"), latch::countDown); testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(400)) .expect( badBodyResponse(BodyProcessorException.BodyProcessorErrorType.PARSING_ERROR) ) - .sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("parameter", "bla"), testContext, checkpoint); + .sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("parameter", "bla"), latch::countDown); } @Test - public void testMultipartForm(VertxTestContext testContext, @TempDir Path tempDir) throws Exception { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testMultipartForm(@TempDir Path tempDir, Checkpoint checkpoint) throws Exception { + CountDownLatch latch = checkpoint.asLatch(2); ValidationHandler validationHandler = ValidationHandlerBuilder.create(schemaRepo) .body(Bodies.multipartFormData(objectSchema().requiredProperty("parameter", intSchema()))) @@ -685,19 +684,19 @@ public void testMultipartForm(VertxTestContext testContext, @TempDir Path tempDi testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(200), statusMessage("5")) - .sendMultipartForm(MultipartForm.create().attribute("parameter", "5"), testContext, checkpoint); + .sendMultipartForm(MultipartForm.create().attribute("parameter", "5"), latch::countDown); testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(400)) .expect( badBodyResponse(BodyProcessorException.BodyProcessorErrorType.PARSING_ERROR) ) - .sendMultipartForm(MultipartForm.create().attribute("parameter", "bla"), testContext, checkpoint); + .sendMultipartForm(MultipartForm.create().attribute("parameter", "bla"), latch::countDown); } @Test - public void testBothFormTypes(VertxTestContext testContext, @TempDir Path tempDir) throws Exception { - Checkpoint checkpoint = testContext.checkpoint(6); + public void testBothFormTypes(@TempDir Path tempDir, Checkpoint checkpoint) throws Exception { + CountDownLatch latch = checkpoint.asLatch(6); ObjectSchemaBuilder bodySchema = objectSchema().requiredProperty("parameter", intSchema()); @@ -727,41 +726,41 @@ public void testBothFormTypes(VertxTestContext testContext, @TempDir Path tempDi testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(200), statusMessage("5")) - .sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("parameter", "5"), testContext, checkpoint); + .sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("parameter", "5"), latch::countDown); testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(400)) .expect( badBodyResponse(BodyProcessorException.BodyProcessorErrorType.PARSING_ERROR) ) - .sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("parameter", "bla"), testContext, checkpoint); + .sendURLEncodedForm(MultiMap.caseInsensitiveMultiMap().add("parameter", "bla"), latch::countDown); testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(200), statusMessage("5")) - .sendMultipartForm(MultipartForm.create().attribute("parameter", "5"), testContext, checkpoint); + .sendMultipartForm(MultipartForm.create().attribute("parameter", "5"), latch::countDown); testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(400)) .expect( badBodyResponse(BodyProcessorException.BodyProcessorErrorType.PARSING_ERROR) ) - .sendMultipartForm(MultipartForm.create().attribute("parameter", "bla"), testContext, checkpoint); + .sendMultipartForm(MultipartForm.create().attribute("parameter", "bla"), latch::countDown); testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(200), statusMessage("No body")) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(400)) .expect( badBodyResponse(BodyProcessorException.BodyProcessorErrorType.MISSING_MATCHING_BODY_PROCESSOR) ) - .sendJson(new JsonObject(), testContext, checkpoint); + .sendJson(new JsonObject(), latch::countDown); } @Test - public void testSameResultWithDifferentBodyTypes(VertxTestContext testContext, @TempDir Path tempDir) throws Exception { - Checkpoint checkpoint = testContext.checkpoint(3); + public void testSameResultWithDifferentBodyTypes(@TempDir Path tempDir, Checkpoint checkpoint) throws Exception { + CountDownLatch latch = checkpoint.asLatch(3); JsonObject expectedResult = new JsonObject() .put("int", 10) @@ -807,7 +806,7 @@ public void testSameResultWithDifferentBodyTypes(VertxTestContext testContext, @ .add("string", "hello") .add("array", "1") .add("array", "1.1"), - testContext, checkpoint + latch::countDown ); testRequest(client, HttpMethod.POST, "/testFormParam") @@ -818,17 +817,17 @@ public void testSameResultWithDifferentBodyTypes(VertxTestContext testContext, @ .attribute("string", "hello") .attribute("array", "1") .attribute("array", "1.1"), - testContext, checkpoint + latch::countDown ); testRequest(client, HttpMethod.POST, "/testFormParam") .expect(statusCode(200)) - .sendJson(expectedResult, testContext, checkpoint); + .sendJson(expectedResult, latch::countDown); } @Test - public void testValidationHandlerChaining(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(1); + public void testValidationHandlerChaining(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(1); ValidationHandler validationHandler1 = ValidationHandlerBuilder.create(schemaRepo) .queryParameter(param("param1", intSchema())) @@ -854,12 +853,12 @@ public void testValidationHandlerChaining(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/testHandlersChaining?param1=10¶m2=true") .expect(statusCode(200), statusMessage("10true")) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testJsonBody(VertxTestContext testContext, @TempDir Path tempDir) { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testJsonBody(@TempDir Path tempDir, Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(2); ValidationHandler validationHandler = ValidationHandlerBuilder.create(schemaRepo) .body(Bodies.json(objectSchema())) @@ -880,18 +879,18 @@ public void testJsonBody(VertxTestContext testContext, @TempDir Path tempDir) { testRequest(client, HttpMethod.POST, "/test") .expect(statusCode(200), statusMessage("{}")) - .sendJson(new JsonObject(), testContext, checkpoint); + .sendJson(new JsonObject(), latch::countDown); testRequest(client, HttpMethod.POST, "/test") .expect(statusCode(400)) .expect(badBodyResponse(BodyProcessorException.BodyProcessorErrorType.VALIDATION_ERROR)) - .sendJson("aaa", testContext, checkpoint); + .sendJson("aaa", latch::countDown); } @Test @Disabled("Due to an issue with circular references, which is not understood yet.") - public void testJsonBodyAsyncCircular(VertxTestContext testContext, @TempDir Path tempDir) { - Checkpoint checkpoint = testContext.checkpoint(2); + public void testJsonBodyAsyncCircular(@TempDir Path tempDir, Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(2); SchemaBuilder childs = arraySchema().items(new GenericSchemaBuilder().withKeyword("$ref", "#")); SchemaBuilder treeSchema = objectSchema().requiredProperty("value", stringSchema()).property("childs", childs); @@ -919,17 +918,17 @@ public void testJsonBodyAsyncCircular(VertxTestContext testContext, @TempDir Pat testRequest(client, HttpMethod.POST, "/test") .expect(statusCode(200), jsonBodyResponse(testObj)) - .sendJson(testObj, testContext, checkpoint); + .sendJson(testObj, latch::countDown); testRequest(client, HttpMethod.POST, "/test") .expect(statusCode(400)) .expect(badBodyResponse(BodyProcessorException.BodyProcessorErrorType.VALIDATION_ERROR)) - .sendJson("aaa", testContext, checkpoint); + .sendJson("aaa", latch::countDown); } @Test - public void testQueryExpandedObjectAdditionalPropertiesAndDefault(VertxTestContext testContext) { - Checkpoint checkpoint = testContext.checkpoint(4); + public void testQueryExpandedObjectAdditionalPropertiesAndDefault(Checkpoint checkpoint) { + CountDownLatch latch = checkpoint.asLatch(4); ValidationHandler validationHandler = ValidationHandlerBuilder.create(schemaRepo) .queryParameter(optionalExplodedParam("explodedObject", @@ -952,15 +951,15 @@ public void testQueryExpandedObjectAdditionalPropertiesAndDefault(VertxTestConte testRequest(client, HttpMethod.GET, "/test") .expect(statusCode(200), jsonBodyResponse(new JsonObject())) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?wellKnownProperty=10") .expect(statusCode(200), jsonBodyResponse(new JsonObject().put("wellKnownProperty", 10))) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?wellKnownProperty=10&myFlag=false") .expect(statusCode(200), jsonBodyResponse(new JsonObject().put("wellKnownProperty", 10).put("myFlag", false))) - .send(testContext, checkpoint); + .send(latch::countDown); testRequest(client, HttpMethod.GET, "/test?wellKnownProperty=10&myFlag=bla") .expect(statusCode(400)) @@ -969,11 +968,11 @@ public void testQueryExpandedObjectAdditionalPropertiesAndDefault(VertxTestConte "explodedObject", ParameterLocation.QUERY )) - .send(testContext, checkpoint); + .send(latch::countDown); } @Test - public void testSimpleHeaderCaseInsensitivity(VertxTestContext testContext) { + public void testSimpleHeaderCaseInsensitivity(Checkpoint checkpoint) { ValidationHandler validationHandler = ValidationHandlerBuilder.create(schemaRepo) .headerParameter(param("AnHeader", intSchema())) .build(); @@ -991,7 +990,7 @@ public void testSimpleHeaderCaseInsensitivity(VertxTestContext testContext) { testRequest(client, HttpMethod.GET, "/test") .with(requestHeader("anheader", "10")) .expect(statusCode(200), jsonBodyResponse(10)) - .send(testContext); + .send(checkpoint); } } diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/DeepObjectValueParameterParserTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/DeepObjectValueParameterParserTest.java index 961c360d95..9c0baae819 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/DeepObjectValueParameterParserTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/DeepObjectValueParameterParserTest.java @@ -5,9 +5,8 @@ import io.vertx.ext.web.validation.impl.parameter.DeepObjectValueParameterParser; import io.vertx.ext.web.validation.impl.parser.ValueParser; import io.vertx.ext.web.validation.tests.testutils.TestParsers; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import java.util.HashMap; import java.util.List; @@ -17,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@ExtendWith(VertxExtension.class) +@VertxTest public class DeepObjectValueParameterParserTest { @Test diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedArrayValueParameterParserTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedArrayValueParameterParserTest.java index cad4d06f8c..ef1480a082 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedArrayValueParameterParserTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedArrayValueParameterParserTest.java @@ -4,9 +4,8 @@ import io.vertx.ext.web.validation.MalformedValueException; import io.vertx.ext.web.validation.impl.parameter.ExplodedArrayValueParameterParser; import io.vertx.ext.web.validation.impl.parser.ValueParser; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import java.util.Arrays; import java.util.Collections; @@ -17,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@ExtendWith(VertxExtension.class) +@VertxTest public class ExplodedArrayValueParameterParserTest { @Test diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedObjectValueParameterParserTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedObjectValueParameterParserTest.java index 4c47ce1d57..adeb0f8e31 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedObjectValueParameterParserTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedObjectValueParameterParserTest.java @@ -5,9 +5,8 @@ import io.vertx.ext.web.validation.impl.parameter.ExplodedObjectValueParameterParser; import io.vertx.ext.web.validation.impl.parser.ValueParser; import io.vertx.ext.web.validation.tests.testutils.TestParsers; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import java.util.HashMap; import java.util.List; @@ -17,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@ExtendWith(VertxExtension.class) +@VertxTest public class ExplodedObjectValueParameterParserTest { @Test diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedTupleValueParameterParserTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedTupleValueParameterParserTest.java index 24876a80e3..b9f9a8be79 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedTupleValueParameterParserTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ExplodedTupleValueParameterParserTest.java @@ -6,10 +6,9 @@ import io.vertx.ext.web.validation.impl.parameter.ExplodedTupleValueParameterParser; import io.vertx.ext.web.validation.impl.parser.ValueParser; import io.vertx.ext.web.validation.tests.testutils.TestParsers; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.assertj.core.util.Lists; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import java.util.Collections; import java.util.HashMap; @@ -19,7 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@ExtendWith(VertxExtension.class) +@VertxTest public class ExplodedTupleValueParameterParserTest { @Test diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/FormBodyProcessorImplTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/FormBodyProcessorImplTest.java index f51f00693d..f2b009b64b 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/FormBodyProcessorImplTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/FormBodyProcessorImplTest.java @@ -16,8 +16,7 @@ import io.vertx.json.schema.JsonSchemaOptions; import io.vertx.json.schema.SchemaRepository; import io.vertx.json.schema.common.dsl.ObjectSchemaBuilder; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -28,7 +27,7 @@ import static org.assertj.core.api.Assertions.fail; import static org.mockito.Mockito.when; -@ExtendWith(VertxExtension.class) +@VertxTest @ExtendWith(MockitoExtension.class) class FormBodyProcessorImplTest { private SchemaRepository repository; diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/JsonBodyProcessorImplTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/JsonBodyProcessorImplTest.java index 7c0f7ceb66..f9bf96bbe0 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/JsonBodyProcessorImplTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/JsonBodyProcessorImplTest.java @@ -16,8 +16,7 @@ import io.vertx.json.schema.JsonSchemaOptions; import io.vertx.json.schema.SchemaRepository; import io.vertx.json.schema.ValidationException; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -28,7 +27,7 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.when; -@ExtendWith(VertxExtension.class) +@VertxTest @ExtendWith(MockitoExtension.class) class JsonBodyProcessorImplTest { private SchemaRepository repository; diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ParameterProcessorIntegrationTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ParameterProcessorIntegrationTest.java index af5b3a50c7..7139159c28 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ParameterProcessorIntegrationTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ParameterProcessorIntegrationTest.java @@ -10,7 +10,7 @@ import io.vertx.json.schema.JsonSchemaOptions; import io.vertx.json.schema.SchemaRepository; import io.vertx.json.schema.ValidationException; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -24,7 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -@ExtendWith(VertxExtension.class) +@VertxTest @ExtendWith(MockitoExtension.class) public class ParameterProcessorIntegrationTest { private SchemaRepository repository; diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ParameterProcessorUnitTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ParameterProcessorUnitTest.java index 9a4ea325f7..e24b747a0e 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ParameterProcessorUnitTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ParameterProcessorUnitTest.java @@ -12,7 +12,7 @@ import io.vertx.json.schema.OutputUnit; import io.vertx.json.schema.SchemaRepository; import io.vertx.json.schema.Validator; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -24,7 +24,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -@ExtendWith(VertxExtension.class) +@VertxTest @ExtendWith(MockitoExtension.class) public class ParameterProcessorUnitTest { diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharArrayValueParserTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharArrayValueParserTest.java index 2b7fc3447e..ec5df623a2 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharArrayValueParserTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharArrayValueParserTest.java @@ -4,14 +4,13 @@ import io.vertx.ext.web.validation.MalformedValueException; import io.vertx.ext.web.validation.impl.parser.SplitterCharArrayParser; import io.vertx.ext.web.validation.impl.parser.ValueParser; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@ExtendWith(VertxExtension.class) +@VertxTest public class SplitterCharArrayValueParserTest { @Test diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharObjectValueParserTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharObjectValueParserTest.java index 833e8fc3f4..17a5a50882 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharObjectValueParserTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharObjectValueParserTest.java @@ -5,14 +5,13 @@ import io.vertx.ext.web.validation.impl.parser.SplitterCharObjectParser; import io.vertx.ext.web.validation.impl.parser.ValueParser; import io.vertx.ext.web.validation.tests.testutils.TestParsers; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@ExtendWith(VertxExtension.class) +@VertxTest public class SplitterCharObjectValueParserTest { @Test diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharTupleValueParserTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharTupleValueParserTest.java index 4de3d97dc9..c89749c429 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharTupleValueParserTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/SplitterCharTupleValueParserTest.java @@ -5,14 +5,13 @@ import io.vertx.ext.web.validation.impl.parser.SplitterCharTupleParser; import io.vertx.ext.web.validation.impl.parser.ValueParser; import io.vertx.ext.web.validation.tests.testutils.TestParsers; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -@ExtendWith(VertxExtension.class) +@VertxTest public class SplitterCharTupleValueParserTest { @Test diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/TextPlainBodyProcessorTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/TextPlainBodyProcessorTest.java index 1e38854fd5..c39e0d1967 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/TextPlainBodyProcessorTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/TextPlainBodyProcessorTest.java @@ -14,8 +14,7 @@ import io.vertx.json.schema.Draft; import io.vertx.json.schema.JsonSchemaOptions; import io.vertx.json.schema.SchemaRepository; -import io.vertx.junit5.VertxExtension; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.VertxTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -26,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatCode; import static org.mockito.Mockito.when; -@ExtendWith(VertxExtension.class) +@VertxTest @ExtendWith(MockitoExtension.class) public class TextPlainBodyProcessorTest { private SchemaRepository repository; diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ValueParserInferenceUtilsTest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ValueParserInferenceUtilsTest.java index 8f3ad6e3f6..9c92374049 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ValueParserInferenceUtilsTest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/impl/ValueParserInferenceUtilsTest.java @@ -3,11 +3,10 @@ import io.vertx.core.json.JsonObject; import io.vertx.ext.web.validation.impl.ValueParserInferenceUtils; import io.vertx.ext.web.validation.impl.parser.ValueParser; -import io.vertx.junit5.VertxExtension; +import io.vertx.junit5.VertxTest; import org.assertj.core.api.Assertions; import org.assertj.core.api.Condition; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import java.util.regex.Pattern; @@ -21,7 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; -@ExtendWith(VertxExtension.class) +@VertxTest public class ValueParserInferenceUtilsTest { @Test diff --git a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/testutils/TestRequest.java b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/testutils/TestRequest.java index 388cbae4d0..bef1903ff0 100644 --- a/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/testutils/TestRequest.java +++ b/vertx-web-validation/src/test/java/io/vertx/ext/web/validation/tests/testutils/TestRequest.java @@ -25,7 +25,6 @@ import io.vertx.ext.web.client.WebClient; import io.vertx.ext.web.multipart.MultipartForm; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; @@ -82,205 +81,134 @@ public final TestRequest expect(Consumer>... asserts) { /** * Send and flag the provided checkpoint with {@link Checkpoint#flag()} when request is completed and no assertion fails * - * @param testContext * @param checkpoint * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> send(VertxTestContext testContext, Checkpoint checkpoint) { - return internalSend(testContext, h -> req.send().onComplete(h), checkpoint::flag); + public Future> send(Checkpoint checkpoint) { + return internalSend(h -> req.send().onComplete(h), checkpoint::flag); } /** - * Send and complete test context with {@link VertxTestContext#completeNow()} when request is completed and no assertion fails + * Send and execute {@code onEnd} code block when request is completed and no assertion fails * - * @param testContext - * @return a future that will be completed when the response is ready and no response assertion fails - */ - public Future> send(VertxTestContext testContext) { - return internalSend(testContext, h -> req.send().onComplete(h), testContext::completeNow); - } - - /** - * Send and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)} - * when request is completed and no assertion fails - * - * @param testContext * @param onEnd * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> send(VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) { - return internalSend(testContext, h -> req.send().onComplete(h), onEnd); + public Future> send(Runnable onEnd) { + return internalSend(h -> req.send().onComplete(h), onEnd); } /** * Send a json and flag the provided checkpoint with {@link Checkpoint#flag()} when request is completed and no assertion fails * * @param json - * @param testContext * @param checkpoint * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> sendJson(Object json, VertxTestContext testContext, Checkpoint checkpoint) { - return internalSend(testContext, h -> req.sendJson(json).onComplete(h), checkpoint::flag); - } - - /** - * Send a json and complete test context with {@link VertxTestContext#completeNow()} when request is completed and no assertion fails - * - * @param json - * @param testContext - * @return a future that will be completed when the response is ready and no response assertion fails - */ - public Future> sendJson(Object json, VertxTestContext testContext) { - return internalSend(testContext, h -> req.sendJson(json).onComplete(h), testContext::completeNow); + public Future> sendJson(Object json, Checkpoint checkpoint) { + return internalSend(h -> req.sendJson(json).onComplete(h), checkpoint::flag); } /** - * Send a json and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)} - * when request is completed and no assertion fails + * Send a json and execute {@code onEnd} code block when request is completed and no assertion fails * * @param json - * @param testContext * @param onEnd * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> sendJson(Object json, VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) { - return internalSend(testContext, h -> req.sendJson(json).onComplete(h), onEnd); + public Future> sendJson(Object json, Runnable onEnd) { + return internalSend(h -> req.sendJson(json).onComplete(h), onEnd); } /** * Send a {@link Buffer} and flag the provided checkpoint with {@link Checkpoint#flag()} when request is completed and no assertion fails * * @param buf - * @param testContext * @param checkpoint * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> sendBuffer(Buffer buf, VertxTestContext testContext, Checkpoint checkpoint) { - return internalSend(testContext, h -> req.sendBuffer(buf).onComplete(h), checkpoint::flag); + public Future> sendBuffer(Buffer buf, Checkpoint checkpoint) { + return internalSend(h -> req.sendBuffer(buf).onComplete(h), checkpoint::flag); } /** - * Send a {@link Buffer} and complete test context with {@link VertxTestContext#completeNow()} when request is completed and no assertion fails + * Send a {@link Buffer} and execute {@code onEnd} code block when request is completed and no assertion fails * * @param buf - * @param testContext - * @return a future that will be completed when the response is ready and no response assertion fails - */ - public Future> sendBuffer(Buffer buf, VertxTestContext testContext) { - return internalSend(testContext, h -> req.sendBuffer(buf).onComplete(h), testContext::completeNow); - } - - /** - * Send a {@link Buffer} and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)} - * when request is completed and no assertion fails - * - * @param buf - * @param testContext * @param onEnd * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> sendBuffer(Buffer buf, VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) { - return internalSend(testContext, h -> req.sendBuffer(buf).onComplete(h), onEnd); + public Future> sendBuffer(Buffer buf, Runnable onEnd) { + return internalSend(h -> req.sendBuffer(buf).onComplete(h), onEnd); } /** * Send an URL Encoded form and flag the provided checkpoint with {@link Checkpoint#flag()} when request is completed and no assertion fails * * @param form - * @param testContext * @param checkpoint * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> sendURLEncodedForm(MultiMap form, VertxTestContext testContext, Checkpoint checkpoint) { - return internalSend(testContext, h -> req.sendForm(form).onComplete(h), checkpoint::flag); - } - - /** - * Send an URL Encoded form and complete test context with {@link VertxTestContext#completeNow()} when request is completed and no assertion fails - * - * @param form - * @param testContext - * @return a future that will be completed when the response is ready and no response assertion fails - */ - public Future> sendURLEncodedForm(MultiMap form, VertxTestContext testContext) { - return internalSend(testContext, h -> req.sendForm(form).onComplete(h), testContext::completeNow); + public Future> sendURLEncodedForm(MultiMap form, Checkpoint checkpoint) { + return internalSend(h -> req.sendForm(form).onComplete(h), checkpoint::flag); } /** - * Send an URL Encoded form and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)} - * when request is completed and no assertion fails + * Send an URL Encoded form and execute {@code onEnd} code block when request is completed and no assertion fails * * @param form - * @param testContext * @param onEnd * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> sendURLEncodedForm(MultiMap form, VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) { - return internalSend(testContext, h -> req.sendForm(form).onComplete(h), onEnd); + public Future> sendURLEncodedForm(MultiMap form, Runnable onEnd) { + return internalSend(h -> req.sendForm(form).onComplete(h), onEnd); } /** * Send a multipart form and flag the provided checkpoint with {@link Checkpoint#flag()} when request is completed and no assertion fails * * @param form - * @param testContext * @param checkpoint * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> sendMultipartForm(MultipartForm form, VertxTestContext testContext, Checkpoint checkpoint) { - return internalSend(testContext, h -> req.sendMultipartForm(form).onComplete(h), checkpoint::flag); + public Future> sendMultipartForm(MultipartForm form, Checkpoint checkpoint) { + return internalSend(h -> req.sendMultipartForm(form).onComplete(h), checkpoint::flag); } /** - * Send a multipart form and complete test context with {@link VertxTestContext#completeNow()} when request is completed and no assertion fails + * Send a multipart form and execute {@code onEnd} code block when request is completed and no assertion fails * * @param form - * @param testContext - * @return a future that will be completed when the response is ready and no response assertion fails - */ - public Future> sendMultipartForm(MultipartForm form, VertxTestContext testContext) { - return internalSend(testContext, h -> req.sendMultipartForm(form).onComplete(h), testContext::completeNow); - } - - /** - * Send a multipart form and execute {@code onEnd} code block wrapped in {@link VertxTestContext#verify(VertxTestContext.ExecutionBlock)} - * when request is completed and no assertion fails - * - * @param form - * @param testContext * @param onEnd * @return a future that will be completed when the response is ready and no response assertion fails */ - public Future> sendMultipartForm(MultipartForm form, VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd) { - return internalSend(testContext, h -> req.sendMultipartForm(form).onComplete(h), onEnd); + public Future> sendMultipartForm(MultipartForm form, Runnable onEnd) { + return internalSend(h -> req.sendMultipartForm(form).onComplete(h), onEnd); } - private Handler>> generateHandleResponse(VertxTestContext testContext, VertxTestContext.ExecutionBlock onEnd, Promise> fut, StackTraceElement[] stackTrace) { + private Handler>> generateHandleResponse(Runnable onEnd, Promise> fut, StackTraceElement[] stackTrace) { return ar -> { if (ar.failed()) { - testContext.failNow(ar.cause()); + fail(ar.cause()); } else { - testContext.verify(() -> { - try { - this.responseAsserts.forEach(c -> c.accept(ar.result())); - } catch (AssertionError e) { - AssertionError newE = new AssertionError("Assertion error in response: " + e.getMessage(), e); - newE.setStackTrace(stackTrace); - throw newE; - } - onEnd.apply(); - }); + try { + this.responseAsserts.forEach(c -> c.accept(ar.result())); + } catch (AssertionError e) { + AssertionError newE = new AssertionError("Assertion error in response: " + e.getMessage(), e); + newE.setStackTrace(stackTrace); + throw newE; + } + onEnd.run(); fut.complete(ar.result()); } }; } - private Future> internalSend(VertxTestContext testContext, Consumer>>> reqSendFunction, VertxTestContext.ExecutionBlock onEnd) { + private Future> internalSend(Consumer>>> reqSendFunction, Runnable onEnd) { Promise> promise = Promise.promise(); this.requestTranformations.forEach(c -> c.accept(req)); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); - reqSendFunction.accept(generateHandleResponse(testContext, onEnd, promise, Arrays.copyOfRange( + reqSendFunction.accept(generateHandleResponse(onEnd, promise, Arrays.copyOfRange( stackTrace, 3, stackTrace.length diff --git a/vertx-web/src/test/java/io/vertx/ext/web/it/RoutingContextDatabindTest.java b/vertx-web/src/test/java/io/vertx/ext/web/it/RoutingContextDatabindTest.java index bb07b6aa34..3d5347b63b 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/it/RoutingContextDatabindTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/it/RoutingContextDatabindTest.java @@ -24,7 +24,7 @@ import io.vertx.ext.web.handler.BodyHandler; import org.junit.jupiter.api.AfterAll; import static org.junit.jupiter.api.Assertions.*; -import io.vertx.junit5.VertxTestContext; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,8 +41,8 @@ public static void oneTimeTearDown() { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); router.route().handler(BodyHandler.create()); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/it/sstore/ClusteredSessionHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/it/sstore/ClusteredSessionHandlerTest.java index 13e6109c38..3b2c11f2c5 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/it/sstore/ClusteredSessionHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/it/sstore/ClusteredSessionHandlerTest.java @@ -31,7 +31,6 @@ import io.vertx.ext.web.tests.handler.SessionHandlerTestBase; import io.vertx.ext.web.sstore.impl.SharedDataSessionImpl; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import io.vertx.test.core.TestUtils; import io.vertx.test.fakecluster.FakeClusterManager; import org.junit.jupiter.api.AfterEach; @@ -40,6 +39,7 @@ import java.util.Arrays; import java.util.List; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import static org.junit.jupiter.api.Assertions.*; @@ -75,8 +75,8 @@ protected void close(List clustered) throws Exception { @BeforeEach @Override - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); setUp(); for (int i = 0;i < numNodes;i++) { ClusterManager clusterManager = getClusterManager(); @@ -94,14 +94,14 @@ public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { @AfterEach @Override - public void tearDown(VertxTestContext testContext) throws Exception { + public void tearDown() throws Exception { for (HttpServer server : servers) { if (server != null) { server.close().await(); } } close(Arrays.asList(vertices)); - super.tearDown(testContext); + super.tearDown(); } @Test @@ -247,9 +247,9 @@ public void testRetryTimeout() throws Exception { } @Test - public void testDelayedLookupWithRequestUpgrade(VertxTestContext testContext) { + public void testDelayedLookupWithRequestUpgrade(Checkpoint checkpoint) { String sessionCookieName = "session"; - Checkpoint testsComplete = testContext.checkpoint(3); + CountDownLatch testsComplete = checkpoint.asLatch(3); ProtocolUpgradeHandler upgradeHandler = ctx -> ctx.request() @@ -258,7 +258,7 @@ public void testDelayedLookupWithRequestUpgrade(VertxTestContext testContext) { .onSuccess(serverWebSocket -> { serverWebSocket.textMessageHandler(msg -> { assertEquals("foo", msg); - testsComplete.flag(); + testsComplete.countDown(); }); }); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/it/sstore/LocalSessionHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/it/sstore/LocalSessionHandlerTest.java index 48b1ebe497..50bdb79d90 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/it/sstore/LocalSessionHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/it/sstore/LocalSessionHandlerTest.java @@ -21,7 +21,6 @@ import io.vertx.ext.web.handler.SessionHandler; import io.vertx.ext.web.sstore.LocalSessionStore; import io.vertx.ext.web.tests.handler.SessionHandlerTestBase; -import io.vertx.junit5.VertxTestContext; import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,8 +34,8 @@ public class LocalSessionHandlerTest extends SessionHandlerTestBase { @BeforeEach @Override - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); store = LocalSessionStore.create(vertx); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/ForwardedTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/ForwardedTest.java index 0325a54e77..8b0c938229 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/ForwardedTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/ForwardedTest.java @@ -23,7 +23,6 @@ import io.vertx.ext.web.Route; import io.vertx.ext.web.client.HttpRequest; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import io.vertx.test.core.TestUtils; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; @@ -408,32 +407,31 @@ public void testForwardedForIpv6() { } @Test - public void testNoneMissingHostHeader(VertxTestContext testContext) { - testMissingHostHeader(testContext, router.allowForward(NONE).route("/")); + public void testNoneMissingHostHeader(Checkpoint done) { + testMissingHostHeader(done, router.allowForward(NONE).route("/")); } @Test - public void testAllMissingHostHeader(VertxTestContext testContext) { - testMissingHostHeader(testContext, router.allowForward(ALL).route("/")); + public void testAllMissingHostHeader(Checkpoint done) { + testMissingHostHeader(done, router.allowForward(ALL).route("/")); } @Test - public void testForwardMissingHostHeader(VertxTestContext testContext) { - testMissingHostHeader(testContext, router.allowForward(FORWARD).route("/")); + public void testForwardMissingHostHeader(Checkpoint done) { + testMissingHostHeader(done, router.allowForward(FORWARD).route("/")); } @Test - public void testXForwardMissingHostHeader(VertxTestContext testContext) { - testMissingHostHeader(testContext, router.allowForward(X_FORWARD).route("/")); + public void testXForwardMissingHostHeader(Checkpoint done) { + testMissingHostHeader(done, router.allowForward(X_FORWARD).route("/")); } @Test - public void testMissingHostHeader(VertxTestContext testContext) { - testMissingHostHeader(testContext, router.allowForward(ALL).route("/")); + public void testMissingHostHeader(Checkpoint done) { + testMissingHostHeader(done, router.allowForward(ALL).route("/")); } - private void testMissingHostHeader(VertxTestContext testContext, Route route) { - Checkpoint done = testContext.checkpoint(); + private void testMissingHostHeader(Checkpoint done, Route route) { route.handler(rc -> { assertNull(rc.request().authority()); @@ -483,8 +481,7 @@ private void testRequest(String... headers) { } @Test - public void testForwardedForAndWebSocket(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testForwardedForAndWebSocket(Checkpoint done) { String host = "vertx.io:1234"; String address = "1.2.3.4"; router.allowForward(ALL).route("/ws").handler(rc -> { @@ -503,8 +500,7 @@ public void testForwardedForAndWebSocket(VertxTestContext testContext) { } @Test - public void testForwardedForAndWebSocketWithUppercase(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testForwardedForAndWebSocketWithUppercase(Checkpoint done) { String host = "vertx.io:1234"; String address = "1.2.3.4"; router.allowForward(ALL).route("/ws").handler(rc -> { diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/MetricsTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/MetricsTest.java index 07c8a6376e..71179e4af3 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/MetricsTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/MetricsTest.java @@ -11,7 +11,6 @@ import io.vertx.core.spi.observability.HttpRequest; import io.vertx.core.spi.observability.HttpResponse; import io.vertx.ext.web.RoutingContext; -import io.vertx.junit5.VertxTestContext; import io.vertx.junit5.VertxProvider; import io.vertx.junit5.ProvidedBy; import io.vertx.test.fakemetrics.FakeMetricsBase; @@ -45,8 +44,8 @@ public Vertx get() { @Override @BeforeEach - public void setUp(@ProvidedBy(MetricsVertxProvider.class) Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(@ProvidedBy(MetricsVertxProvider.class) Vertx vertx) throws Exception { + super.setUp(vertx); } @Test diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/Router100ContinueTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/Router100ContinueTest.java index e2126bc11a..4d33bfa0c3 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/Router100ContinueTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/Router100ContinueTest.java @@ -4,8 +4,9 @@ import io.vertx.core.http.*; import io.vertx.ext.web.Router; import io.vertx.ext.web.handler.*; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; +import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,7 +35,7 @@ public void setup(Vertx vertx) throws Exception { } @Test - public void testContinue(VertxTestContext testContext) { + public void testContinue(Checkpoint checkpoint, Checkpoint checkpoint2, Checkpoint checkpoint3) { router.route() .handler(BodyHandler.create()) .handler(ctx -> { @@ -43,15 +44,11 @@ public void testContinue(VertxTestContext testContext) { }); client.request(HttpMethod.POST, "/") - .onFailure(testContext::failNow) - .onSuccess(req -> { + .onComplete(TestUtils.onSuccess(req -> { req .response() - .onFailure(testContext::failNow) - .onSuccess(res -> { - assertEquals(200, res.statusCode()); - testContext.completeNow(); - }); + .expecting(HttpResponseExpectation.SC_OK) + .onComplete(checkpoint); req .putHeader(HttpHeaders.EXPECT, "100-continue") @@ -59,14 +56,14 @@ public void testContinue(VertxTestContext testContext) { .continueHandler(v -> req .end("DATA") - .onFailure(testContext::failNow)) + .onComplete(checkpoint3)) .sendHead() - .onFailure(testContext::failNow); - }); + .onComplete(checkpoint2); + })); } @Test - public void testBadExpectation(VertxTestContext testContext) { + public void testBadExpectation(Checkpoint checkpoint, Checkpoint checkpoint2) { router.route() .handler(BodyHandler.create()) .handler(ctx -> { @@ -75,30 +72,22 @@ public void testBadExpectation(VertxTestContext testContext) { }); client.request(HttpMethod.POST, "/") - .onFailure(testContext::failNow) - .onSuccess(req -> { + .onComplete(TestUtils.onSuccess2(req -> { req .response() - .onFailure(testContext::failNow) - .onSuccess(res -> { - assertEquals(417, res.statusCode()); - testContext.completeNow(); - }); + .expecting(HttpResponseExpectation.SC_EXPECTATION_FAILED) + .onComplete(checkpoint); req .putHeader(HttpHeaders.EXPECT, "lets-go") .setChunked(true) - .continueHandler(v -> - req - .end("DATA") - .onFailure(testContext::failNow)) .sendHead() - .onFailure(testContext::failNow); - }); + .onComplete(checkpoint2); + })); } @Test - public void testExpectButTooLarge(VertxTestContext testContext) { + public void testExpectButTooLarge(Checkpoint checkpoint, Checkpoint checkpoint2, Checkpoint checkpoint3) { router.route() .handler(BodyHandler.create().setBodyLimit(1)) .handler(ctx -> { @@ -107,16 +96,11 @@ public void testExpectButTooLarge(VertxTestContext testContext) { }); client.request(HttpMethod.POST, "/") - .onFailure(testContext::failNow) - .onSuccess(req -> { + .onComplete(TestUtils.onSuccess2(req -> { req .response() - .onFailure(testContext::failNow) - .onSuccess(res -> { - // entity too large - assertEquals(413, res.statusCode()); - testContext.completeNow(); - }); + .expecting(HttpResponseExpectation.SC_REQUEST_ENTITY_TOO_LARGE) + .onComplete(checkpoint); req .putHeader(HttpHeaders.EXPECT, "100-continue") @@ -124,9 +108,9 @@ public void testExpectButTooLarge(VertxTestContext testContext) { .continueHandler(v -> req .end("DATA") - .onFailure(testContext::failNow)) + .onComplete(checkpoint3)) .sendHead() - .onFailure(testContext::failNow); - }); + .onComplete(checkpoint2); + })); } } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/RouterTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/RouterTest.java index 11ab9b3003..9801923ac3 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/RouterTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/RouterTest.java @@ -39,7 +39,6 @@ import io.vertx.test.core.TestUtils; import static org.junit.jupiter.api.Assertions.*; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.Test; import java.io.*; @@ -670,8 +669,7 @@ public void testFailureinHandlingFailureWithInvalidStatusMessage() throws Except } @Test - public void testSetExceptionHandler(VertxTestContext testContext) throws Exception { - Checkpoint done = testContext.checkpoint(); + public void testSetExceptionHandler(Checkpoint done) throws Exception { String path = "/blah"; router.route(path).handler(rc -> { throw new RuntimeException("ouch!"); @@ -2343,7 +2341,7 @@ public void testMultipleHandlersMixed() throws Exception { } @Test - public void testMultipleHandlersMultipleConnections(VertxTestContext testContext) throws Exception { + public void testMultipleHandlersMultipleConnections(Checkpoint checkpoint) throws Exception { router.get("/path").handler(routingContext -> { routingContext.put("response", "handler1"); routingContext.next(); @@ -2355,14 +2353,14 @@ public void testMultipleHandlersMultipleConnections(VertxTestContext testContext response.setChunked(true); response.end(routingContext.get("response") + "handler3"); }); - Checkpoint done = testContext.checkpoint(100); + CountDownLatch done = checkpoint.asLatch(100); for (int i = 0; i < 100; i++) { vertx.executeBlocking(() -> { testSyncRequest("GET", "/path", 200, "OK", "handler1handler2handler3"); return null; }).onComplete(TestUtils.onSuccess(v -> { - done.flag(); + done.countDown(); })); } } @@ -2407,7 +2405,7 @@ private void testSyncRequest(String httpMethod, String path, int statusCode, Str I've also added a timer when I call routingContext.next() */ @Test - public void testMultipleHandlersMultipleConnectionsDelayed(VertxTestContext testContext) throws Exception { + public void testMultipleHandlersMultipleConnectionsDelayed(Checkpoint checkpoint) throws Exception { router.get("/path").handler(routingContext -> { routingContext.put("response", "handler1"); routingContext.vertx().setTimer((int) (1 + Math.random() * 10), asyncResult -> routingContext.next()); @@ -2420,7 +2418,7 @@ public void testMultipleHandlersMultipleConnectionsDelayed(VertxTestContext test response.end(routingContext.get("response") + "handler3"); }); - Checkpoint done = testContext.checkpoint(100); + CountDownLatch done = checkpoint.asLatch(100); for (int i = 0; i < 100; i++) { // using executeBlocking should create multiple connections vertx.executeBlocking(() -> { @@ -2428,7 +2426,7 @@ public void testMultipleHandlersMultipleConnectionsDelayed(VertxTestContext test testSyncRequest("GET", "/path", 200, "OK", "handler1handler2handler3"); return null; }).onComplete(TestUtils.onSuccess(v -> { - done.flag(); + done.countDown(); })); } } @@ -2437,7 +2435,7 @@ public void testMultipleHandlersMultipleConnectionsDelayed(VertxTestContext test This test is similar to test above but it mixes right and failing requests */ @Test - public void testMultipleHandlersMultipleConnectionsDelayedMixed(VertxTestContext testContext) throws Exception { + public void testMultipleHandlersMultipleConnectionsDelayedMixed(Checkpoint checkpoint) throws Exception { router.get("/:param").handler(routingContext -> { if (routingContext.pathParam("param").equals("fail")) { routingContext.fail(400); @@ -2468,7 +2466,7 @@ public void testMultipleHandlersMultipleConnectionsDelayedMixed(VertxTestContext final int multipleConnections = 500; - Checkpoint done = testContext.checkpoint(multipleConnections); + CountDownLatch done = checkpoint.asLatch(multipleConnections); Callable execute200Request = () -> { Thread.sleep((int) (1 + Math.random() * 10)); @@ -2486,7 +2484,7 @@ public void testMultipleHandlersMultipleConnectionsDelayedMixed(VertxTestContext // using executeBlocking should create multiple connections vertx.executeBlocking((new Random().nextBoolean() ? execute200Request : execute400Request), false) .onComplete(TestUtils.onSuccess(v -> { - done.flag(); + done.countDown(); })); } } @@ -2600,7 +2598,7 @@ private Handler generateHandler(final int i) { } @Test - public void stressTestMultipleHandlers(VertxTestContext testContext) throws Exception { + public void stressTestMultipleHandlers(Checkpoint checkpoint) throws Exception { final int HANDLERS_NUMBER = 100; final int REQUESTS_NUMBER = 200; @@ -2619,7 +2617,7 @@ public void stressTestMultipleHandlers(VertxTestContext testContext) throws Exce .end(sum.toString()); }); - Checkpoint done = testContext.checkpoint(REQUESTS_NUMBER); + CountDownLatch done = checkpoint.asLatch(REQUESTS_NUMBER); final StringBuilder sum = new StringBuilder(); for (int i = 0; i < HANDLERS_NUMBER; i++) { sum.append(i); @@ -2631,7 +2629,7 @@ public void stressTestMultipleHandlers(VertxTestContext testContext) throws Exce testSyncRequest("GET", "/path", 200, "OK", sum.toString()); return null; }).onComplete(TestUtils.onSuccess(v -> { - done.flag(); + done.countDown(); })); } } @@ -2656,17 +2654,16 @@ public void testRoutePathNoSlashBegin() throws Exception { } @Test - public void testMissingHostHeaderHttp1_1(VertxTestContext testContext) { - testMissingHostHeader(testContext, "HTTP/1.1", 400); + public void testMissingHostHeaderHttp1_1(Checkpoint done) { + testMissingHostHeader(done, "HTTP/1.1", 400); } @Test - public void testMissingHostHeaderHttp1_0(VertxTestContext testContext) { - testMissingHostHeader(testContext, "HTTP/1.0", 200); + public void testMissingHostHeaderHttp1_0(Checkpoint done) { + testMissingHostHeader(done, "HTTP/1.0", 200); } - private void testMissingHostHeader(VertxTestContext testContext, String httpVersion, int expectedStatusCode) { - Checkpoint done = testContext.checkpoint(); + private void testMissingHostHeader(Checkpoint done, String httpVersion, int expectedStatusCode) { router.route().handler(rc -> rc.response().end()); NetClient nc = vertx.createNetClient(); NetSocket so = nc.connect(SocketAddress.inetSocketAddress(8080, "localhost")).await(); @@ -2687,7 +2684,7 @@ private void testMissingHostHeader(VertxTestContext testContext, String httpVers } @Test - public void testMultipleHandlersWithFailuresDeadlock(VertxTestContext testContext) throws Exception { + public void testMultipleHandlersWithFailuresDeadlock(Checkpoint checkpoint) throws Exception { AtomicBoolean first = new AtomicBoolean(true); CountDownLatch firstHandlerLatch = new CountDownLatch(1); CountDownLatch secondHandlerLatch = new CountDownLatch(1); @@ -2724,7 +2721,7 @@ public void testMultipleHandlersWithFailuresDeadlock(VertxTestContext testContex event.fail(new NullPointerException()); }); - Checkpoint done = testContext.checkpoint(2); + CountDownLatch done = checkpoint.asLatch(2); for (int i = 0; i < 2; i++) { vertx.executeBlocking(() -> { HttpServerRequest request = mock(HttpServerRequestInternal.class); @@ -2740,7 +2737,7 @@ public void testMultipleHandlersWithFailuresDeadlock(VertxTestContext testContex router.handle(request); return null; }, false).onComplete(TestUtils.onSuccess(v -> { - done.flag(); + done.countDown(); })); } } @@ -3525,7 +3522,7 @@ public void testPauseResumeOnPipeline() { } @Test - public void testPausedConnection(VertxTestContext testContext) { + public void testPausedConnection(Checkpoint checkpoint) { router.route() .handler((PlatformHandler) ctx -> { @@ -3544,7 +3541,7 @@ public void testPausedConnection(VertxTestContext testContext) { int numRequests = 20; - Checkpoint checkpoint = testContext.checkpoint(numRequests); + CountDownLatch latch = checkpoint.asLatch(numRequests); HttpClient client = vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1)); for (int i = 0; i < numRequests; i++) { @@ -3556,7 +3553,7 @@ public void testPausedConnection(VertxTestContext testContext) { .expecting(HttpResponseExpectation.SC_OK) .compose(HttpClientResponse::end) ).onComplete(TestUtils.onSuccess(resp -> { - checkpoint.flag(); + latch.countDown(); })); } @@ -3565,7 +3562,7 @@ public void testPausedConnection(VertxTestContext testContext) { } @Test - public void testPausedConnection2(VertxTestContext testContext) { + public void testPausedConnection2(Checkpoint checkpoint) { router.route() .handler((PlatformHandler) ctx -> { @@ -3583,7 +3580,7 @@ public void testPausedConnection2(VertxTestContext testContext) { int numRequests = 20; - Checkpoint checkpoint = testContext.checkpoint(numRequests); + CountDownLatch latch = checkpoint.asLatch(numRequests); HttpClient client = vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1)); for (int i = 0; i < numRequests; i++) { @@ -3595,7 +3592,7 @@ public void testPausedConnection2(VertxTestContext testContext) { .expecting(HttpResponseExpectation.SC_NOT_FOUND) .compose(HttpClientResponse::end)) .onComplete(TestUtils.onSuccess(v -> { - checkpoint.flag(); + latch.countDown(); })); } @@ -3604,7 +3601,7 @@ public void testPausedConnection2(VertxTestContext testContext) { } @Test - public void testPausedConnection3(VertxTestContext testContext) { + public void testPausedConnection3(Checkpoint checkpoint) { router.route() .handler((PlatformHandler) ctx -> { @@ -3624,7 +3621,7 @@ public void testPausedConnection3(VertxTestContext testContext) { int numRequests = 20; - Checkpoint checkpoint = testContext.checkpoint(numRequests); + CountDownLatch latch = checkpoint.asLatch(numRequests); HttpClient client = vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1)); for (int i = 0; i < numRequests; i++) { @@ -3636,7 +3633,7 @@ public void testPausedConnection3(VertxTestContext testContext) { .expecting(HttpResponseExpectation.SC_OK) .compose(HttpClientResponse::end)) .onComplete(TestUtils.onSuccess(v -> { - checkpoint.flag(); + latch.countDown(); })); } @@ -3645,7 +3642,7 @@ public void testPausedConnection3(VertxTestContext testContext) { } @Test - public void testPausedConnection4(VertxTestContext testContext) { + public void testPausedConnection4(Checkpoint checkpoint) { router.route() .handler((PlatformHandler) ctx -> { @@ -3655,7 +3652,7 @@ public void testPausedConnection4(VertxTestContext testContext) { int numRequests = 20; - Checkpoint checkpoint = testContext.checkpoint(numRequests); + CountDownLatch latch = checkpoint.asLatch(numRequests); HttpClient client = vertx.createHttpClient(new PoolOptions().setHttp1MaxSize(1)); for (int i = 0; i < numRequests; i++) { @@ -3667,7 +3664,7 @@ public void testPausedConnection4(VertxTestContext testContext) { .expecting(HttpResponseExpectation.SC_NOT_FOUND) .compose(HttpClientResponse::end)) .onComplete(TestUtils.onSuccess(v -> { - checkpoint.flag(); + latch.countDown(); })); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/UpgradeTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/UpgradeTest.java index 9fdb62401d..b86ddc9f4a 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/UpgradeTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/UpgradeTest.java @@ -7,7 +7,6 @@ import io.vertx.ext.web.handler.*; import io.vertx.junit5.Checkpoint; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,8 +44,7 @@ public void setup() throws Exception { } @Test - public void testUpgradeWithAsyncInBetween(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testUpgradeWithAsyncInBetween(Checkpoint done) { router.route() .handler((PlatformHandler) ctx -> { ctx.request().pause(); @@ -76,16 +74,14 @@ public void testUpgradeWithAsyncInBetween(VertxTestContext testContext) { }); wsClient.connect("/") - .onFailure(testContext::failNow) - .onSuccess(webSocket -> { + .onComplete(TestUtils.onSuccess2(webSocket -> { webSocket.frameHandler(System.out::println); webSocket.closeHandler(ok -> done.flag()); - }); + })); } @Test - public void testUpgradeWithLongAwait(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testUpgradeWithLongAwait(Checkpoint done) { router.route() .handler((PlatformHandler) ctx -> { ctx.request().pause(); @@ -113,10 +109,9 @@ public void testUpgradeWithLongAwait(VertxTestContext testContext) { .addHeader("cookie", "session=" + TestUtils.randomAlphaString(32)); wsClient.connect(options) - .onFailure(testContext::failNow) - .onSuccess(webSocket -> { + .onComplete(TestUtils.onSuccess2(webSocket -> { webSocket.frameHandler(System.out::println); webSocket.closeHandler(ok -> done.flag()); - }); + })); } } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/WebTestBase.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/WebTestBase.java index 54e0412a93..f9002b6f19 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/WebTestBase.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/WebTestBase.java @@ -27,7 +27,7 @@ import io.vertx.ext.web.client.WebClient; import io.vertx.ext.web.handler.BodyHandler; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; + import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -57,7 +57,7 @@ public abstract class WebTestBase { protected Router router; @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { + public void setUp(Vertx vertx) throws Exception { this.vertx = vertx; router = Router.router(vertx); server = vertx.createHttpServer(getHttpServerOptions().setMaxFormFields(2048)); @@ -67,7 +67,7 @@ public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { server .requestHandler(router) .listen() - .onComplete(testContext.succeedingThenComplete()); + .await(); } protected HttpServerOptions getHttpServerOptions() { @@ -83,19 +83,12 @@ protected WebSocketClientOptions getWebSocketClientOptions() { } @AfterEach - public void tearDown(VertxTestContext testContext) throws Exception { + public void tearDown() throws Exception { if (client != null) { - client.close().onComplete(ar -> { - if (server != null) { - server.close().onComplete(testContext.succeedingThenComplete()); - } else { - testContext.completeNow(); - } - }); - } else if (server != null) { - server.close().onComplete(testContext.succeedingThenComplete()); - } else { - testContext.completeNow(); + client.close().await(); + } + if (server != null) { + server.close().await(); } } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BasicAuthImpersonationTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BasicAuthImpersonationTest.java index ca298e262b..ef4c2a213d 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BasicAuthImpersonationTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BasicAuthImpersonationTest.java @@ -17,7 +17,6 @@ import io.vertx.ext.web.sstore.SessionStore; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -32,8 +31,8 @@ public class BasicAuthImpersonationTest extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); authn = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); authz = PropertyFileAuthorization.create(vertx, "login/loginusers.properties"); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BlockingHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BlockingHandlerTest.java index c830968264..81e02cd4d6 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BlockingHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BlockingHandlerTest.java @@ -23,7 +23,6 @@ import io.vertx.ext.web.tests.WebTestBase; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,8 +36,8 @@ public class BlockingHandlerTest extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); } @Test diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BodyHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BodyHandlerTest.java index 22624adad0..070ab4e6b6 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BodyHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/BodyHandlerTest.java @@ -31,7 +31,7 @@ import io.vertx.ext.web.handler.BodyHandler; import io.vertx.ext.web.handler.PlatformHandler; import io.vertx.ext.web.tests.WebTestBase; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.Checkpoint; import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; @@ -60,8 +60,8 @@ public class BodyHandlerTest extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); router.route().handler(BodyHandler.create()); } @@ -315,7 +315,7 @@ public void testFileDeleteOnLargeUpload() { } @Test - public void testFileUploadFileRemovalOnClientClosesConnection(VertxTestContext testContext) { + public void testFileUploadFileRemovalOnClientClosesConnection(Checkpoint checkpoint) { String uploadsDirectory = new File(tempUploads, "clientClose").getPath(); new File(uploadsDirectory).mkdirs(); @@ -349,7 +349,7 @@ public void testFileUploadFileRemovalOnClientClosesConnection(VertxTestContext t //wait for upload being deleted repeatWhile(100, i -> i < 100 && vertx.fileSystem().readDirBlocking(uploadsDirectory).size() != 0, () -> { assertEquals(0, vertx.fileSystem().readDirBlocking(uploadsDirectory).size()); - testContext.completeNow(); + checkpoint.flag(); }); }); })); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CSRFHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CSRFHandlerTest.java index fe7068180a..78e18d6108 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CSRFHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CSRFHandlerTest.java @@ -33,7 +33,7 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterAll; import static org.junit.jupiter.api.Assertions.*; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.Checkpoint; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -67,12 +67,12 @@ public void testGetCookie() throws Exception { } @Test - public void testPostWithoutHeader(VertxTestContext testContext) { + public void testPostWithoutHeader(Checkpoint checkpoint) { router.route() .handler(BodyHandler.create()) .handler(CSRFHandler.create(vertx, "Abracadabra")); router.route().handler(rc -> rc.response().end()); - router.errorHandler(403, rc -> testContext.completeNow()); + router.errorHandler(403, rc -> checkpoint.flag()); testRequest(HttpMethod.POST, "/", 403, "Forbidden", null); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ChainAuthHandlerAndTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ChainAuthHandlerAndTest.java index df8bf0688c..59deb3c986 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ChainAuthHandlerAndTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ChainAuthHandlerAndTest.java @@ -10,7 +10,6 @@ import io.vertx.ext.web.sstore.LocalSessionStore; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -21,8 +20,8 @@ public class ChainAuthHandlerAndTest extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); AuthenticationHandler redirectAuthHandler = RedirectAuthHandler.create(authProvider); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ChainAuthHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ChainAuthHandlerTest.java index a0ff05b133..597786fce4 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ChainAuthHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ChainAuthHandlerTest.java @@ -13,7 +13,6 @@ import io.vertx.ext.web.sstore.LocalSessionStore; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -26,8 +25,8 @@ public class ChainAuthHandlerTest extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); AuthenticationHandler redirectAuthHandler = RedirectAuthHandler.create(authProvider); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CookieHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CookieHandlerTest.java index 4eded1225a..dd45d0dbe8 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CookieHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CookieHandlerTest.java @@ -24,7 +24,6 @@ import io.vertx.ext.web.tests.WebTestBase; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,8 +36,8 @@ public class CookieHandlerTest extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); } @Test diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CookielessSessionHandlerTestBase.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CookielessSessionHandlerTestBase.java index e26c2c069e..56f4a94712 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CookielessSessionHandlerTestBase.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/CookielessSessionHandlerTestBase.java @@ -16,6 +16,7 @@ package io.vertx.ext.web.tests.handler; +import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpMethod; import io.vertx.ext.web.Session; @@ -44,8 +45,8 @@ public class CookielessSessionHandlerTestBase extends WebTestBase { @Override @BeforeEach - public void setUp(io.vertx.core.Vertx vertx, io.vertx.junit5.VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); store = LocalSessionStore.create(vertx); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ErrorHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ErrorHandlerTest.java index c7558b5302..458ef069a0 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ErrorHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ErrorHandlerTest.java @@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,8 +36,8 @@ public class ErrorHandlerTest extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); router.route().failureHandler(ErrorHandler.create(vertx)); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/EventbusBridgeTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/EventbusBridgeTest.java index ee011301a6..6d74f33804 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/EventbusBridgeTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/EventbusBridgeTest.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelPromise; import io.vertx.core.Future; import io.vertx.core.Handler; +import io.vertx.core.Vertx; import io.vertx.core.eventbus.DeliveryOptions; import io.vertx.core.eventbus.Message; import io.vertx.core.eventbus.MessageConsumer; @@ -45,7 +46,7 @@ import io.vertx.ext.web.sstore.SessionStore; import io.vertx.test.core.TestUtils; import static org.junit.jupiter.api.Assertions.*; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.Checkpoint; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -76,13 +77,13 @@ public EventbusBridgeTest(Transport transport) { @Override @BeforeEach - public void setUp(io.vertx.core.Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); sockJS = SockJSHandler.create(vertx); } @Test - public void testHookCreateSocket(VertxTestContext testContext) throws Exception { + public void testHookCreateSocket(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { @@ -90,7 +91,7 @@ public void testHookCreateSocket(VertxTestContext testContext) throws Exception assertNotNull(be.socket()); assertNull(be.getRawMessage()); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -99,18 +100,18 @@ public void testHookCreateSocket(VertxTestContext testContext) throws Exception } @Test - public void testHookCreateSocketRejected(VertxTestContext testContext) throws Exception { + public void testHookCreateSocketRejected(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> be.complete(be.type() != BridgeEventType.SOCKET_CREATED))); BridgeClient client = new BridgeClient(super.wsClient, transport); client - .closeHandler(v -> testContext.completeNow()) + .closeHandler(v -> checkpoint.flag()) .connect(websocketURI); } @Test - public void testHookSocketClosed(VertxTestContext testContext) throws Exception { + public void testHookSocketClosed(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { @@ -118,7 +119,7 @@ public void testHookSocketClosed(VertxTestContext testContext) throws Exception assertNotNull(be.socket()); assertNull(be.getRawMessage()); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -130,7 +131,7 @@ public void testHookSocketClosed(VertxTestContext testContext) throws Exception } @Test - public void testHookSocketClosedAbruptly(VertxTestContext testContext) throws Exception { + public void testHookSocketClosedAbruptly(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { @@ -138,7 +139,7 @@ public void testHookSocketClosedAbruptly(VertxTestContext testContext) throws Ex assertNotNull(be.socket()); assertNull(be.getRawMessage()); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -150,7 +151,7 @@ public void testHookSocketClosedAbruptly(VertxTestContext testContext) throws Ex } @Test - public void testHookSend(VertxTestContext testContext) throws Exception { + public void testHookSend(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.SEND) { @@ -159,7 +160,7 @@ public void testHookSend(VertxTestContext testContext) throws Exception { assertEquals(addr, raw.getString("address")); assertEquals("foobar", raw.getString("body")); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -168,7 +169,7 @@ public void testHookSend(VertxTestContext testContext) throws Exception { } @Test - public void testHookSendHeaders(VertxTestContext testContext) throws Exception { + public void testHookSendHeaders(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.SEND) { @@ -179,7 +180,7 @@ public void testHookSendHeaders(VertxTestContext testContext) throws Exception { raw.put("headers", new JsonObject().put("hdr1", "val1").put("hdr2", "val2")); be.setRawMessage(raw); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -188,12 +189,12 @@ public void testHookSendHeaders(VertxTestContext testContext) throws Exception { } @Test - public void testHookSendRejected(VertxTestContext testContext) throws Exception { + public void testHookSendRejected(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.SEND) { be.complete(false); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -203,12 +204,12 @@ public void testHookSendRejected(VertxTestContext testContext) throws Exception } @Test - public void testHookSendMissingAddress(VertxTestContext testContext) throws Exception { + public void testHookSendMissingAddress(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.SEND) { be.getRawMessage().remove("address"); - testContext.completeNow(); + checkpoint.flag(); } be.complete(true); })); @@ -217,7 +218,7 @@ public void testHookSendMissingAddress(VertxTestContext testContext) throws Exce } @Test - public void testHookPublish(VertxTestContext testContext) throws Exception { + public void testHookPublish(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.PUBLISH) { @@ -226,7 +227,7 @@ public void testHookPublish(VertxTestContext testContext) throws Exception { assertEquals(addr, raw.getString("address")); assertEquals("foobar", raw.getString("body")); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -235,7 +236,7 @@ public void testHookPublish(VertxTestContext testContext) throws Exception { } @Test - public void testHookPublishHeaders(VertxTestContext testContext) throws Exception { + public void testHookPublishHeaders(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.PUBLISH) { @@ -246,7 +247,7 @@ public void testHookPublishHeaders(VertxTestContext testContext) throws Exceptio raw.put("headers", new JsonObject().put("hdr1", "val1").put("hdr2", "val2")); be.setRawMessage(raw); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -255,12 +256,12 @@ public void testHookPublishHeaders(VertxTestContext testContext) throws Exceptio } @Test - public void testHookPubRejected(VertxTestContext testContext) throws Exception { + public void testHookPubRejected(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.PUBLISH) { be.complete(false); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -270,12 +271,12 @@ public void testHookPubRejected(VertxTestContext testContext) throws Exception { } @Test - public void testHookPublishMissingAddress(VertxTestContext testContext) throws Exception { + public void testHookPublishMissingAddress(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.PUBLISH) { be.getRawMessage().remove("address"); - testContext.completeNow(); + checkpoint.flag(); } be.complete(true); })); @@ -284,7 +285,7 @@ public void testHookPublishMissingAddress(VertxTestContext testContext) throws E } @Test - public void testHookRegister(VertxTestContext testContext) throws Exception { + public void testHookRegister(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.REGISTER) { @@ -292,7 +293,7 @@ public void testHookRegister(VertxTestContext testContext) throws Exception { JsonObject raw = be.getRawMessage(); assertEquals(addr, raw.getString("address")); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -301,12 +302,12 @@ public void testHookRegister(VertxTestContext testContext) throws Exception { } @Test - public void testHookRegisterRejected(VertxTestContext testContext) throws Exception { + public void testHookRegisterRejected(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.REGISTER) { be.complete(false); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -316,12 +317,12 @@ public void testHookRegisterRejected(VertxTestContext testContext) throws Except } @Test - public void testHookRegisterMissingAddress(VertxTestContext testContext) throws Exception { + public void testHookRegisterMissingAddress(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.REGISTER) { be.getRawMessage().remove("address"); - testContext.completeNow(); + checkpoint.flag(); } be.complete(true); })); @@ -381,7 +382,7 @@ public void testHookRegistered() throws Exception { } @Test - public void testHookReceive(VertxTestContext testContext) throws Exception { + public void testHookReceive(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { @@ -391,7 +392,7 @@ public void testHookReceive(VertxTestContext testContext) throws Exception { assertEquals(addr, raw.getString("address")); assertEquals("foobar", raw.getString("body")); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -400,12 +401,12 @@ public void testHookReceive(VertxTestContext testContext) throws Exception { } @Test - public void testHookReceiveRejected(VertxTestContext testContext) throws Exception { + public void testHookReceiveRejected(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.RECEIVE) { be.complete(false); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -414,7 +415,7 @@ public void testHookReceiveRejected(VertxTestContext testContext) throws Excepti } @Test - public void testHookUnregister(VertxTestContext testContext) throws Exception { + public void testHookUnregister(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.UNREGISTER) { @@ -422,7 +423,7 @@ public void testHookUnregister(VertxTestContext testContext) throws Exception { JsonObject raw = be.getRawMessage(); assertEquals(addr, raw.getString("address")); be.complete(true); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -431,12 +432,12 @@ public void testHookUnregister(VertxTestContext testContext) throws Exception { } @Test - public void testHookUnregisterRejected(VertxTestContext testContext) throws Exception { + public void testHookUnregisterRejected(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.UNREGISTER) { be.complete(false); - testContext.completeNow(); + checkpoint.flag(); } else { be.complete(true); } @@ -446,12 +447,12 @@ public void testHookUnregisterRejected(VertxTestContext testContext) throws Exce } @Test - public void testHookUnregisterMissingAddress(VertxTestContext testContext) throws Exception { + public void testHookUnregisterMissingAddress(Checkpoint checkpoint) throws Exception { router.route("/eventbus/*").subRouter( sockJS.bridge(allAccessOptions, be -> { if (be.type() == BridgeEventType.UNREGISTER) { be.getRawMessage().remove("address"); - testContext.completeNow(); + checkpoint.flag(); } be.complete(true); })); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/LoggerHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/LoggerHandlerTest.java index 6e03b3405c..86c843aa7b 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/LoggerHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/LoggerHandlerTest.java @@ -21,7 +21,6 @@ import io.vertx.ext.web.handler.LoggerHandler; import io.vertx.ext.web.tests.WebTestBase; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.Test; /** @@ -57,8 +56,7 @@ public void testLogger3() throws Exception { } @Test - public void testLogger4(VertxTestContext testContext) throws Exception { - Checkpoint done = testContext.checkpoint(); + public void testLogger4(Checkpoint done) throws Exception { LoggerHandler logger = LoggerHandler.create(true, LoggerFormat.CUSTOM).customFormatter((req, ms) -> { done.flag(); return "custom log message"; @@ -67,8 +65,7 @@ public void testLogger4(VertxTestContext testContext) throws Exception { } @Test - public void testLogger5(VertxTestContext testContext) throws Exception { - Checkpoint done = testContext.checkpoint(); + public void testLogger5(Checkpoint done) throws Exception { LoggerHandler logger = LoggerHandler.create(true, LoggerFormat.CUSTOM).customFormatter((ctx, ms) -> { done.flag(); return "custom log message"; diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OAuth2AuthHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OAuth2AuthHandlerTest.java index d0ae068eb0..6a96c81470 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OAuth2AuthHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OAuth2AuthHandlerTest.java @@ -33,7 +33,7 @@ import io.vertx.ext.web.tests.WebTestBase; import io.vertx.ext.web.sstore.SessionStore; import static org.junit.jupiter.api.Assertions.*; -import io.vertx.junit5.VertxTestContext; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -61,8 +61,8 @@ public class OAuth2AuthHandlerTest extends WebTestBase { @Override @AfterEach - public void tearDown(VertxTestContext testContext) throws Exception { - super.tearDown(testContext); + public void tearDown() throws Exception { + super.tearDown(); } private String redirectURL = null; diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OAuth2ImpersonationTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OAuth2ImpersonationTest.java index 1832c03887..dd275c806d 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OAuth2ImpersonationTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OAuth2ImpersonationTest.java @@ -35,7 +35,6 @@ import io.vertx.ext.web.sstore.SessionStore; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -77,16 +76,16 @@ public class OAuth2ImpersonationTest extends WebTestBase { @Override @AfterEach - public void tearDown(VertxTestContext testContext) throws Exception { + public void tearDown() throws Exception { server.close(); - super.tearDown(testContext); + super.tearDown(); } @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); oauth2 = OAuth2Auth.create(vertx, new OAuth2Options() .setClientId("client-id") diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OtpHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OtpHandlerTest.java index 34b1796be6..f442a24f87 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OtpHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/OtpHandlerTest.java @@ -17,7 +17,6 @@ import io.vertx.ext.web.sstore.LocalSessionStore; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -56,8 +55,8 @@ public void dump() { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); router.post() .handler(BodyHandler.create()); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/RedirectAuthHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/RedirectAuthHandlerTest.java index c7c059c0d4..b90818e227 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/RedirectAuthHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/RedirectAuthHandlerTest.java @@ -32,7 +32,6 @@ import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -51,8 +50,8 @@ public class RedirectAuthHandlerTest extends AuthHandlerTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties"); usernameParam = FormLoginHandler.DEFAULT_USERNAME_PARAM; passwordParam = FormLoginHandler.DEFAULT_PASSWORD_PARAM; @@ -171,8 +170,7 @@ public void testFormLoginFailures() throws Exception { } @Test - public void testFormLoginWithoutBodyHandlerFailure(VertxTestContext testContext) throws Exception { - Checkpoint done = testContext.checkpoint(); + public void testFormLoginWithoutBodyHandlerFailure(Checkpoint done) throws Exception { SessionStore store = LocalSessionStore.create(vertx); router.route().handler(SessionHandler.create(store)); FormLoginHandler loginHandler = FormLoginHandler.create(authProvider); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ResponseContentTypeHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ResponseContentTypeHandlerTest.java index 90660f445c..59da917407 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ResponseContentTypeHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/ResponseContentTypeHandlerTest.java @@ -27,7 +27,6 @@ import io.vertx.ext.web.tests.WebTestBase; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,8 +44,8 @@ public class ResponseContentTypeHandlerTest extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); router.route().handler(ResponseContentTypeHandler.create()); // Added to make sure ResponseContentTypeHandler works well with others router.route().handler(ResponseTimeHandler.create()); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SecurityAuditLoggerHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SecurityAuditLoggerHandlerTest.java index c09f09ff8f..492b56fd74 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SecurityAuditLoggerHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SecurityAuditLoggerHandlerTest.java @@ -34,7 +34,6 @@ import io.vertx.ext.web.tests.WebTestBase; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -59,8 +58,8 @@ public void setup() throws Exception { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); } @Test diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SessionHandlerTestBase.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SessionHandlerTestBase.java index bb32b3a117..bbee73f458 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SessionHandlerTestBase.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SessionHandlerTestBase.java @@ -24,7 +24,7 @@ import io.vertx.ext.web.handler.SessionHandler; import io.vertx.ext.web.sstore.AbstractSession; import io.vertx.ext.web.tests.WebTestBase; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.Checkpoint; import io.vertx.test.core.AsyncTestBase; import io.vertx.ext.web.sstore.LocalSessionStore; import io.vertx.ext.web.sstore.SessionStore; @@ -470,7 +470,7 @@ public void testSessionIdLength() throws Exception { } @Test - public void testVersion(VertxTestContext testContext) throws Exception { + public void testVersion(Checkpoint checkpoint) throws Exception { AbstractSession session = (AbstractSession) store.createSession(10000); assertEquals(0, session.version()); @@ -525,7 +525,7 @@ public void testVersion(VertxTestContext testContext) throws Exception { assertEquals(2, session3.version()); // confirm the content is present assertEquals("w", session3.get("k")); - testContext.completeNow(); + checkpoint.flag(); }); }); }); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SlowClusterEventbusBridgeTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SlowClusterEventbusBridgeTest.java index 65a2bc6a33..f93b3d6697 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SlowClusterEventbusBridgeTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/SlowClusterEventbusBridgeTest.java @@ -27,7 +27,6 @@ import io.vertx.ext.web.tests.handler.EventbusBridgeTest.Transport; import io.vertx.junit5.Checkpoint; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; import io.vertx.test.core.TestUtils; import io.vertx.test.fakecluster.FakeClusterManager; import io.vertx.tests.eventbus.WrappedClusterManager; @@ -93,7 +92,7 @@ public void tearDown() { } @Test - public void testRegistration(VertxTestContext testContext) throws Exception { + public void testRegistration(Checkpoint checkpoint) throws Exception { String payload = "hello slinkydeveloper!"; String addr = "someaddress"; String websocketURI = "/eventbus/websocket"; @@ -129,8 +128,6 @@ public void testRegistration(VertxTestContext testContext) throws Exception { BridgeClient bridgeClient = new BridgeClient(wsClient, transport); - Checkpoint checkpoint = testContext.checkpoint(); - bridgeClient.handler((address, received) -> { assertTrue(step.compareAndSet(2, 3)); assertEquals(addr, address); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticDirectoryListHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticDirectoryListHandlerTest.java index 67d3e40f5a..62e1a4564f 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticDirectoryListHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticDirectoryListHandlerTest.java @@ -22,7 +22,6 @@ import io.vertx.ext.web.tests.WebTestBase; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,8 +34,8 @@ public class StaticDirectoryListHandlerTest extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); stat = StaticHandler.create("webroot").setDirectoryListing(true).setDirectoryTemplate("custom_dir_template.html"); router.route().handler(stat); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler2Test.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler2Test.java index 9a4f691deb..3b851f2959 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler2Test.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler2Test.java @@ -23,7 +23,6 @@ import io.vertx.ext.web.tests.WebTestBase; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,8 +35,8 @@ public class StaticHandler2Test extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); stat = StaticHandler.create(); router.route("/static/*").handler(stat); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler3Test.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler3Test.java index 6730cf1853..2e0151c2b5 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler3Test.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler3Test.java @@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,8 +36,8 @@ public class StaticHandler3Test extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); stat = StaticHandler.create(); router.route("/*").handler(stat); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler4Test.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler4Test.java index de9d6d3697..a00216446c 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler4Test.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandler4Test.java @@ -24,7 +24,6 @@ import io.vertx.ext.web.tests.WebTestBase; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,8 +36,8 @@ public class StaticHandler4Test extends WebTestBase { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); stat = StaticHandler.create(FileSystemAccess.RELATIVE, "nasty"); router.route("/*").handler(stat); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandlerTest.java index bcf03cf821..093b1b8800 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/StaticHandlerTest.java @@ -39,7 +39,6 @@ import org.junit.jupiter.api.Assumptions; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -53,6 +52,7 @@ import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiFunction; @@ -84,8 +84,8 @@ public class StaticHandlerTest extends WebTestBase { @Override @BeforeEach - public void setUp(io.vertx.core.Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); webRootTarget = Files.createTempDirectory(webRootSrc.getParent(), "webroot"); copyWebRootFiles(); stat = StaticHandler.create(webRootTarget.getFileName().toString()); @@ -114,8 +114,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO @Override @AfterEach - public void tearDown(VertxTestContext testContext) throws Exception { - super.tearDown(testContext); + public void tearDown() throws Exception { + super.tearDown(); deleteWebRootFiles(); } @@ -315,8 +315,8 @@ public void testNoHttp2Push() throws Exception { } @Test - public void testHttp2Push(VertxTestContext testContext) throws Exception { - Checkpoint pushReceived = testContext.checkpoint(2); + public void testHttp2Push(Checkpoint checkpoint) throws Exception { + CountDownLatch pushReceived = checkpoint.asLatch(2); List mappings = new ArrayList<>(); mappings.add(new Http2PushMapping("style.css", "style", false)); @@ -353,7 +353,7 @@ public void testHttp2Push(VertxTestContext testContext) throws Exception { .compose(HttpClientResponse::body) .onComplete(TestUtils.onSuccess(body -> { assertTrue(body.length() > 0); - pushReceived.flag(); + pushReceived.countDown(); })); }).send() .expecting(HttpResponseExpectation.SC_OK) @@ -937,8 +937,7 @@ public void testHandlerAfter() throws Exception { } @Test - public void testWriteResponseWhenAlreadyClosed(VertxTestContext testContext) throws Exception { - Checkpoint done = testContext.checkpoint(); + public void testWriteResponseWhenAlreadyClosed(Checkpoint done) throws Exception { router.clear(); router .route() diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/VirtualThreadTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/VirtualThreadTest.java index cf680a4464..fdd69ad4d4 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/VirtualThreadTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/VirtualThreadTest.java @@ -24,8 +24,8 @@ import io.vertx.core.http.HttpServer; import io.vertx.core.internal.VertxInternal; import io.vertx.ext.web.Router; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -36,7 +36,7 @@ public class VirtualThreadTest { @Test - public void testBlockingHandler(Vertx vertx, VertxTestContext testContext) { + public void testBlockingHandler(Vertx vertx, Checkpoint checkpoint) { assumeTrue(Runtime.version().feature() >= 21); HttpServer server = vertx.createHttpServer(); HttpClient client = vertx.createHttpClient(); @@ -56,7 +56,7 @@ public void testBlockingHandler(Vertx vertx, VertxTestContext testContext) { .await(); assertEquals("Hello", body.toString()); assertTrue(System.currentTimeMillis() - now >= 200); - testContext.completeNow(); + checkpoint.flag(); }); } } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSAsyncHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSAsyncHandlerTest.java index 6043474383..bac7a55767 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSAsyncHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSAsyncHandlerTest.java @@ -21,7 +21,7 @@ import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.handler.BodyHandler; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -46,8 +46,7 @@ public void setUp(Vertx vertx) throws Exception { } @Test - public void testHandleMessageFromXhrTransportWithAsyncHandler(VertxTestContext testContext) throws Exception { - Checkpoint cp = testContext.checkpoint(); + public void testHandleMessageFromXhrTransportWithAsyncHandler(Checkpoint cp) throws Exception { socketHandler = () -> socket -> { socket.handler(buf -> { assertEquals("Hello World", buf.toString()); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSErrorTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSErrorTest.java index 8134bc8618..f77593c372 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSErrorTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSErrorTest.java @@ -14,8 +14,8 @@ import io.vertx.ext.web.handler.sockjs.BridgeEvent; import io.vertx.ext.web.handler.sockjs.SockJSBridgeOptions; import io.vertx.ext.web.handler.sockjs.SockJSHandler; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -66,7 +66,7 @@ public void setUp(Vertx vertx) throws Exception { } @Test - public void testEventBusBridgeLeakingConsumers(VertxTestContext testContext) throws InterruptedException { + public void testEventBusBridgeLeakingConsumers(Checkpoint checkpoint) throws InterruptedException { Promise firstClientDone = Promise.promise(); // initial connection - double registration and unregistration WebSocketClient client = vertx.createWebSocketClient(); @@ -107,7 +107,7 @@ public void testEventBusBridgeLeakingConsumers(VertxTestContext testContext) thr assertEquals(counter[0], number, "Message was lost, next id not matching."); if (number % 20 == 0) { - testContext.completeNow(); + checkpoint.flag(); } }); @@ -115,7 +115,7 @@ public void testEventBusBridgeLeakingConsumers(VertxTestContext testContext) thr } @Test - public void testEventBusBridgeLeakingConsumersClean(VertxTestContext testContext) throws InterruptedException { + public void testEventBusBridgeLeakingConsumersClean(Checkpoint checkpoint) throws InterruptedException { Promise firstClientDone = Promise.promise(); // initial connection - single registration and unregistration WebSocketClient client = vertx.createWebSocketClient(); @@ -153,7 +153,7 @@ public void testEventBusBridgeLeakingConsumersClean(VertxTestContext testContext assertEquals(counter[0], number, "Message was lost, next id not matching."); if (number % 20 == 0) { - testContext.completeNow(); + checkpoint.flag(); } }); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSEventBusTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSEventBusTest.java index 47abb18d18..973b6d7dd4 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSEventBusTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSEventBusTest.java @@ -16,7 +16,7 @@ package io.vertx.ext.web.tests.handler.sockjs; import io.vertx.core.buffer.Buffer; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.Checkpoint; import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; @@ -30,16 +30,16 @@ public class SockJSEventBusTest extends SockJSTestBase { @Test - public void testWriteText(VertxTestContext testContext) throws Exception { - testWrite(true, testContext); + public void testWriteText(Checkpoint checkpoint) throws Exception { + testWrite(true, checkpoint::flag); } @RepeatedTest(1000) - public void testWriteBinary(VertxTestContext testContext) throws Exception { - testWrite(false, testContext); + public void testWriteBinary(Checkpoint checkpoint) throws Exception { + testWrite(false, checkpoint::flag); } - private void testWrite(boolean text, VertxTestContext testContext) throws Exception { + private void testWrite(boolean text, Runnable done) throws Exception { String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { if (text) { @@ -48,7 +48,7 @@ private void testWrite(boolean text, VertxTestContext testContext) throws Except vertx.eventBus().send(socket.writeHandlerID(), Buffer.buffer(expected)); } socket.endHandler(v -> { - testContext.completeNow(); + done.run(); }); }; startServers(); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSHandlerTest.java index 7db484d175..106f936855 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSHandlerTest.java @@ -18,6 +18,7 @@ import io.vertx.core.MultiMap; import io.vertx.core.Promise; +import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.*; import io.vertx.core.internal.buffer.BufferInternal; @@ -39,7 +40,6 @@ import io.vertx.test.core.TestUtils; import static org.junit.jupiter.api.Assertions.*; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -47,6 +47,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -64,8 +65,8 @@ public class SockJSHandlerTest extends WebTestBase { @Override @BeforeEach - public void setUp(io.vertx.core.Vertx vertx, io.vertx.junit5.VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); // Make sure a catch-all BodyHandler will not prevent websocket connection router.route().handler(BodyHandler.create()); SockJSProtocolTest.installTestApplications(router, vertx); @@ -99,8 +100,7 @@ public void testNotFound() { // https://github.com/vert-x3/vertx-web/issues/77 @Test - public void testSendWebsocketContinuationFrames(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testSendWebsocketContinuationFrames(Checkpoint done) { // Use raw websocket transport wsClient.connect("/echo/websocket").onComplete(TestUtils.onSuccess(ws -> { @@ -129,8 +129,7 @@ public void testSendWebsocketContinuationFrames(VertxTestContext testContext) { * after the frames are re-combined */ @Test - public void testCombineBinaryContinuationFramesRawWebSocket(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testCombineBinaryContinuationFramesRawWebSocket(Checkpoint done) { String serverPath = "/combine"; AtomicReference serverReceivedMessage = new AtomicReference<>(); @@ -155,8 +154,7 @@ public void testCombineBinaryContinuationFramesRawWebSocket(VertxTestContext tes } @Test - public void testSplitLargeReplyRawWebSocket(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testSplitLargeReplyRawWebSocket(Checkpoint done) { String serverPath = "/split"; String largeReply = TestUtils.randomAlphaString(65536 * 5); @@ -184,8 +182,7 @@ public void testSplitLargeReplyRawWebSocket(VertxTestContext testContext) { } @Test - public void testTextFrameRawWebSocket(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testTextFrameRawWebSocket(Checkpoint done) { String serverPath = "/textecho"; setupSockJsServer(serverPath, this::echoRequest); @@ -202,8 +199,7 @@ public void testTextFrameRawWebSocket(VertxTestContext testContext) { } @Test - public void testTextFrameSockJs(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testTextFrameSockJs(Checkpoint done) { String serverPath = "/text-sockjs"; setupSockJsServer(serverPath, this::echoRequest); @@ -220,8 +216,7 @@ public void testTextFrameSockJs(VertxTestContext testContext) { } @Test - public void testCombineTextFrameSockJs(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testCombineTextFrameSockJs(Checkpoint done) { String serverPath = "/text-combine-sockjs"; setupSockJsServer(serverPath, this::echoRequest); @@ -249,8 +244,7 @@ public void testCombineTextFrameSockJs(VertxTestContext testContext) { } @Test - public void testSplitLargeReplySockJs(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testSplitLargeReplySockJs(Checkpoint done) { String serverPath = "/large-reply-sockjs"; String largeMessage = TestUtils.randomAlphaString(65536 * 2); @@ -350,8 +344,8 @@ private void testNotFound(String uri) { } @Test - public void testWebContext(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(2); + public void testWebContext(Checkpoint checkpoint) { + CountDownLatch done = checkpoint.asLatch(2); SessionStore store = SessionStore.create(vertx); SessionHandler handler = SessionHandler.create(store).setCookieless(true); CompletableFuture sessionID = new CompletableFuture<>(); @@ -392,7 +386,7 @@ public void testWebContext(VertxTestContext testContext) { } catch (InterruptedException | ExecutionException e) { fail(e.getMessage()); } - done.flag(); + done.countDown(); })); wsClient.connect(new WebSocketConnectOptions() @@ -401,19 +395,19 @@ public void testWebContext(VertxTestContext testContext) { .compose(ws -> wsClient.connect(new WebSocketConnectOptions() .setPort(8080) .setURI("/webcontextuser/websocket"))) - .onComplete(TestUtils.onSuccess(wsuser -> done.flag())); + .onComplete(TestUtils.onSuccess(wsuser -> done.countDown())); } @Test - public void testCookiesRemoved(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(2); + public void testCookiesRemoved(Checkpoint checkpoint) { + CountDownLatch done = checkpoint.asLatch(2); router.route("/cookiesremoved*").subRouter(SockJSHandler.create(vertx) .socketHandler(sock -> { MultiMap headers = sock.headers(); String cookieHeader = headers.get("cookie"); assertNotNull(cookieHeader); assertEquals("JSESSIONID=wibble", cookieHeader); - done.flag(); + done.countDown(); })); MultiMap headers = HttpHeaders.headers(); headers.add("cookie", "JSESSIONID=wibble"); @@ -423,13 +417,12 @@ public void testCookiesRemoved(VertxTestContext testContext) { .setPort(8080) .setURI("/cookiesremoved/websocket") .setHeaders(headers)).onComplete(TestUtils.onSuccess(ws -> { - done.flag(); + done.countDown(); })); } @Test - public void testTimeoutCloseCode(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testTimeoutCloseCode(Checkpoint done) { router.route("/ws-timeout*").subRouter(SockJSHandler .create(vertx) .bridge(new SockJSBridgeOptions().setPingTimeout(1)) @@ -445,8 +438,7 @@ public void testTimeoutCloseCode(VertxTestContext testContext) { } @Test - public void testInvalidMessageCode(VertxTestContext testContext) { - Checkpoint done = testContext.checkpoint(); + public void testInvalidMessageCode(Checkpoint done) { router.route("/ws-timeout*").subRouter(SockJSHandler .create(vertx) .bridge(new SockJSBridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("SockJSHandlerTest.testInvalidMessageCode"))) diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSRawTransportTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSRawTransportTest.java index 32c7c97121..e6d2936167 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSRawTransportTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSRawTransportTest.java @@ -18,7 +18,7 @@ import io.vertx.core.buffer.Buffer; import io.vertx.core.http.WebSocketConnectOptions; import io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.Checkpoint; import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.Test; @@ -32,22 +32,22 @@ public class SockJSRawTransportTest extends SockJSTestBase { @Test - public void testWriteText(VertxTestContext testContext) throws Exception { - testWrite(true, testContext); + public void testWriteText(Checkpoint checkpoint) throws Exception { + testWrite(true, checkpoint); } @Test - public void testWriteBinary(VertxTestContext testContext) throws Exception { - testWrite(false, testContext); + public void testWriteBinary(Checkpoint checkpoint) throws Exception { + testWrite(false, checkpoint); } @Test - public void disableHost(VertxTestContext testContext) throws Exception { + public void disableHost(Checkpoint checkpoint) throws Exception { String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.write(expected); socket.endHandler(v -> { - testContext.completeNow(); + checkpoint.flag(); }); }; startServers(new SockJSHandlerOptions()); @@ -70,7 +70,7 @@ public void disableHost(VertxTestContext testContext) throws Exception { } @Test - public void disableHostFailWhenOriginIsRequired(VertxTestContext testContext) throws Exception { + public void disableHostFailWhenOriginIsRequired(Checkpoint checkpoint) throws Exception { socketHandler = () -> socket -> { socket.write(TestUtils.randomAlphaString(64)); }; @@ -83,17 +83,17 @@ public void disableHostFailWhenOriginIsRequired(VertxTestContext testContext) th .setAllowOriginHeader(false)).onComplete(TestUtils.onFailure(err -> { assertNotNull(err); assertEquals("WebSocket upgrade failure: 403", err.getMessage()); - testContext.completeNow(); + checkpoint.flag(); })); } @Test - public void goodOrigin(VertxTestContext testContext) throws Exception { + public void goodOrigin(Checkpoint checkpoint) throws Exception { String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.write(expected); socket.endHandler(v -> { - testContext.completeNow(); + checkpoint.flag(); }); }; startServers(new SockJSHandlerOptions().setOrigin("http://localhost:8080")); @@ -111,7 +111,7 @@ public void goodOrigin(VertxTestContext testContext) throws Exception { } @Test - public void badOrigin(VertxTestContext testContext) throws Exception { + public void badOrigin(Checkpoint checkpoint) throws Exception { socketHandler = () -> socket -> { socket.write(TestUtils.randomAlphaString(64)); }; @@ -119,11 +119,11 @@ public void badOrigin(VertxTestContext testContext) throws Exception { wsClient.connect("/test/websocket").onComplete(TestUtils.onFailure(err -> { assertNotNull(err); assertEquals("WebSocket upgrade failure: 403", err.getMessage()); - testContext.completeNow(); + checkpoint.flag(); })); } - private void testWrite(boolean text, VertxTestContext testContext) throws Exception { + private void testWrite(boolean text, Checkpoint checkpoint) throws Exception { String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { if (text) { @@ -132,7 +132,7 @@ private void testWrite(boolean text, VertxTestContext testContext) throws Except socket.write(Buffer.buffer(expected)); } socket.endHandler(v -> { - testContext.completeNow(); + checkpoint.flag(); }); }; startServers(new SockJSHandlerOptions()); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSSessionTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSSessionTest.java index a30eb2d863..91f3298dfb 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSSessionTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSSessionTest.java @@ -22,7 +22,7 @@ import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpMethod; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; + import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; @@ -43,13 +43,13 @@ public class SockJSSessionTest extends SockJSTestBase { @Test - public void testNoDeadlockWhenWritingFromAnotherThreadWithSseTransport(VertxTestContext testContext) throws Exception { + public void testNoDeadlockWhenWritingFromAnotherThreadWithSseTransport(Checkpoint checkpoint) throws Exception { socketHandler = () -> { return socket -> { AtomicBoolean closed = new AtomicBoolean(); socket.endHandler(v -> { closed.set(true); - testContext.completeNow(); + checkpoint.flag(); }); new Thread(() -> { while (!closed.get()) { @@ -73,11 +73,10 @@ public void testNoDeadlockWhenWritingFromAnotherThreadWithSseTransport(VertxTest } @Test - public void testNoDeadlockWhenWritingFromAnotherThreadWithWebsocketTransport(VertxTestContext testContext) throws Exception { + public void testNoDeadlockWhenWritingFromAnotherThreadWithWebsocketTransport(Checkpoint cp) throws Exception { Assumptions.assumeFalse(PlatformDependent.isWindows()); final Buffer random = Buffer.buffer(TestUtils.randomAlphaString(256)); int numMsg = 1000; - Checkpoint cp = testContext.checkpoint(1); AtomicInteger clientReceived = new AtomicInteger(); AtomicInteger serverReceived = new AtomicInteger(); BooleanSupplier shallStop = () -> clientReceived.get() > numMsg * 256 && serverReceived.get() > numMsg * 256; @@ -120,11 +119,11 @@ public void testNoDeadlockWhenWritingFromAnotherThreadWithWebsocketTransport(Ver } @Test - public void testCombineMultipleFramesIntoASingleMessage(VertxTestContext testContext) throws Exception { + public void testCombineMultipleFramesIntoASingleMessage(Checkpoint checkpoint) throws Exception { socketHandler = () -> { return socket -> socket.handler(buf -> { assertEquals("Hello World", buf.toString()); - testContext.completeNow(); + checkpoint.flag(); }); }; startServers(); @@ -136,7 +135,7 @@ public void testCombineMultipleFramesIntoASingleMessage(VertxTestContext testCon } @Test - public void doesNotSendEmptyAnswerForWriteSentInEarlierBatch(VertxTestContext testContext) throws Exception { + public void doesNotSendEmptyAnswerForWriteSentInEarlierBatch(Checkpoint checkpoint) throws Exception { AtomicInteger answerCount = new AtomicInteger(); socketHandler = () -> { return socket -> socket.handler(buf -> { @@ -167,7 +166,7 @@ public void doesNotSendEmptyAnswerForWriteSentInEarlierBatch(VertxTestContext te break; case CLOSE: assertEquals(1, answerCount.get()); - testContext.completeNow(); + checkpoint.flag(); break; } }); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSWriteTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSWriteTest.java index abf4f3bce2..cc2351f75e 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSWriteTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/handler/sockjs/SockJSWriteTest.java @@ -20,10 +20,11 @@ import io.vertx.core.http.HttpMethod; import io.vertx.core.http.WebSocketBase; import io.vertx.junit5.Checkpoint; -import io.vertx.junit5.VertxTestContext; import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.Test; +import java.util.concurrent.CountDownLatch; + import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -32,12 +33,12 @@ public class SockJSWriteTest extends SockJSTestBase { @Test - public void testRaw(VertxTestContext testContext) throws Exception { - Checkpoint cp = testContext.checkpoint(2); + public void testRaw(Checkpoint checkpoint) throws Exception { + CountDownLatch cp = checkpoint.asLatch(2); String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onSuccess(v -> { - cp.flag(); + cp.countDown(); })); }; startServers(); @@ -45,7 +46,7 @@ public void testRaw(VertxTestContext testContext) throws Exception { wsClient.connect("/test/websocket").onComplete(TestUtils.onSuccess(ws -> { ws.handler(buffer -> { if (buffer.toString().equals(expected)) { - cp.flag(); + cp.countDown(); } }); })); @@ -53,12 +54,12 @@ public void testRaw(VertxTestContext testContext) throws Exception { } @Test - public void testRawFailure(VertxTestContext testContext) throws Exception { + public void testRawFailure(Checkpoint checkpoint) throws Exception { String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.endHandler(v -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onFailure(err -> { - testContext.completeNow(); + checkpoint.flag(); })); }); }; @@ -69,12 +70,12 @@ public void testRawFailure(VertxTestContext testContext) throws Exception { } @Test - public void testWebSocket(VertxTestContext testContext) throws Exception { - Checkpoint cp = testContext.checkpoint(2); + public void testWebSocket(Checkpoint checkpoint) throws Exception { + CountDownLatch cp = checkpoint.asLatch(2); String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onSuccess(v -> { - cp.flag(); + cp.countDown(); })); }; startServers(); @@ -82,7 +83,7 @@ public void testWebSocket(VertxTestContext testContext) throws Exception { wsClient.connect("/test/400/8ne8e94a/websocket").onComplete(TestUtils.onSuccess(ws -> { ws.handler(buffer -> { if (buffer.toString().equals("a[\"" + expected + "\"]")) { - cp.flag(); + cp.countDown(); } }); })); @@ -90,12 +91,12 @@ public void testWebSocket(VertxTestContext testContext) throws Exception { } @Test - public void testWebSocketFailure(VertxTestContext testContext) throws Exception { + public void testWebSocketFailure(Checkpoint checkpoint) throws Exception { String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.endHandler(v -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onFailure(err -> { - testContext.completeNow(); + checkpoint.flag(); })); }); }; @@ -106,12 +107,12 @@ public void testWebSocketFailure(VertxTestContext testContext) throws Exception } @Test - public void testEventSource(VertxTestContext testContext) throws Exception { - Checkpoint cp = testContext.checkpoint(2); + public void testEventSource(Checkpoint checkpoint) throws Exception { + CountDownLatch cp = checkpoint.asLatch(2); String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onSuccess(v -> { - cp.flag(); + cp.countDown(); })); }; startServers(); @@ -120,19 +121,19 @@ public void testEventSource(VertxTestContext testContext) throws Exception { .onComplete(TestUtils.onSuccess(resp -> { resp.handler(buffer -> { if (buffer.toString().equals("data: a[\"" + expected + "\"]\r\n\r\n")) { - cp.flag(); + cp.countDown(); } }); })); } @Test - public void testEventSourceFailure(VertxTestContext testContext) throws Exception { + public void testEventSourceFailure(Checkpoint checkpoint) throws Exception { String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.endHandler(v -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onFailure(err -> { - testContext.completeNow(); + checkpoint.flag(); })); }); }; @@ -145,12 +146,12 @@ public void testEventSourceFailure(VertxTestContext testContext) throws Exceptio } @Test - public void testXHRStreaming(VertxTestContext testContext) throws Exception { - Checkpoint cp = testContext.checkpoint(2); + public void testXHRStreaming(Checkpoint checkpoint) throws Exception { + CountDownLatch cp = checkpoint.asLatch(2); String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onSuccess(v -> { - cp.flag(); + cp.countDown(); })); }; startServers(); @@ -160,19 +161,19 @@ public void testXHRStreaming(VertxTestContext testContext) throws Exception { assertEquals(200, resp.statusCode()); resp.handler(buffer -> { if (buffer.toString().equals("a[\"" + expected + "\"]\n")) { - cp.flag(); + cp.countDown(); } }); })); } @Test - public void testXHRStreamingFailure(VertxTestContext testContext) throws Exception { + public void testXHRStreamingFailure(Checkpoint checkpoint) throws Exception { String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.endHandler(v -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onFailure(err -> { - testContext.completeNow(); + checkpoint.flag(); })); }); }; @@ -185,12 +186,12 @@ public void testXHRStreamingFailure(VertxTestContext testContext) throws Excepti } @Test - public void testXHRPolling(VertxTestContext testContext) throws Exception { - Checkpoint cp = testContext.checkpoint(2); + public void testXHRPolling(Checkpoint checkpoint) throws Exception { + CountDownLatch cp = checkpoint.asLatch(2); String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onSuccess(v -> { - cp.flag(); + cp.countDown(); })); }; startServers(); @@ -202,7 +203,7 @@ public void testXHRPolling(VertxTestContext testContext) throws Exception { assertEquals(200, resp.statusCode()); resp.handler(buffer -> { if (buffer.toString().equals("a[\"" + expected + "\"]\n")) { - cp.flag(); + cp.countDown(); } else { task[0].run(); } @@ -212,17 +213,17 @@ public void testXHRPolling(VertxTestContext testContext) throws Exception { } @Test - public void testXHRPollingClose(VertxTestContext testContext) throws Exception { + public void testXHRPollingClose(Checkpoint checkpoint) throws Exception { // Take 5 seconds which is the hearbeat timeout - Checkpoint cp = testContext.checkpoint(2); + CountDownLatch cp = checkpoint.asLatch(2); String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onFailure(err -> { - cp.flag(); + cp.countDown(); })); socket.endHandler(v -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onFailure(err -> { - cp.flag(); + cp.countDown(); })); }); socket.close(); @@ -235,17 +236,17 @@ public void testXHRPollingClose(VertxTestContext testContext) throws Exception { } @Test - public void testXHRPollingShutdown(VertxTestContext testContext) throws Exception { + public void testXHRPollingShutdown(Checkpoint checkpoint) throws Exception { // Take 5 seconds which is the hearbeat timeout - Checkpoint cp = testContext.checkpoint(2); + CountDownLatch cp = checkpoint.asLatch(2); String expected = TestUtils.randomAlphaString(64); socketHandler = () -> socket -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onFailure(err -> { - cp.flag(); + cp.countDown(); })); socket.endHandler(v -> { socket.write(Buffer.buffer(expected)).onComplete(TestUtils.onFailure(err -> { - cp.flag(); + cp.countDown(); })); }); }; diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/impl/RoutingContextImplTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/impl/RoutingContextImplTest.java index 970c70a988..624cb09c1a 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/impl/RoutingContextImplTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/impl/RoutingContextImplTest.java @@ -12,7 +12,6 @@ import org.junit.jupiter.api.AfterAll; import static org.junit.jupiter.api.Assertions.*; import io.vertx.core.Vertx; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,8 +28,8 @@ public static void oneTimeTearDown() throws IOException { @Override @BeforeEach - public void setUp(Vertx vertx, VertxTestContext testContext) throws Exception { - super.setUp(vertx, testContext); + public void setUp(Vertx vertx) throws Exception { + super.setUp(vertx); router.route().handler(BodyHandler.create()); } diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/sse/SseBodyCodecTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/sse/SseBodyCodecTest.java index e2a380594d..461c4b7a1d 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/sse/SseBodyCodecTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/sse/SseBodyCodecTest.java @@ -5,8 +5,8 @@ import io.vertx.ext.web.codec.BodyCodec; import io.vertx.ext.web.codec.SseEvent; import io.vertx.ext.web.codec.spi.BodyStream; +import io.vertx.junit5.Checkpoint; import io.vertx.junit5.VertxTest; -import io.vertx.junit5.VertxTestContext; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -76,7 +76,7 @@ public void testRetryField() throws Exception { } @Test - public void testInvalidRetryField(VertxTestContext testContext) throws Exception { + public void testInvalidRetryField(Checkpoint checkpoint) throws Exception { AtomicReference caught = new AtomicReference<>(); BodyCodec codec = BodyCodec.sseStream(stream -> { stream.handler(evt -> fail("Should not receive event")); @@ -84,7 +84,7 @@ public void testInvalidRetryField(VertxTestContext testContext) throws Exception caught.set(err); assertNotNull(caught.get()); assertTrue(caught.get().getMessage().contains("Invalid \"retry\" value")); - testContext.completeNow(); + checkpoint.flag(); }); }); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/tests/templ/TemplateTest.java b/vertx-web/src/test/java/io/vertx/ext/web/tests/templ/TemplateTest.java index 3569c0483f..4a28100115 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/tests/templ/TemplateTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/tests/templ/TemplateTest.java @@ -26,7 +26,7 @@ import io.vertx.ext.web.common.template.TemplateEngine; import io.vertx.ext.web.handler.TemplateHandler; import io.vertx.ext.web.tests.WebTestBase; -import io.vertx.junit5.VertxTestContext; +import io.vertx.junit5.Checkpoint; import io.vertx.test.core.TestUtils; import org.junit.jupiter.api.Test; @@ -80,13 +80,13 @@ private void testRelativeToRoutePath(String pathPrefix) { } @Test - public void testTemplateEngineFail(VertxTestContext testContext) { + public void testTemplateEngineFail(Checkpoint checkpoint) { TemplateEngine engine = new TestEngine(true); router.route().handler(TemplateHandler.create(engine, "somedir", "text/html")); router.errorHandler(500, ctx -> { Throwable t = ctx.failure(); assertEquals("eek", t.getMessage()); - testContext.completeNow(); + checkpoint.flag(); }); testRequest(HttpMethod.GET, "/foo.html", 500, "Internal Server Error"); }