Search in sources :

Example 1 with Checkpoint

use of io.vertx.junit5.Checkpoint in project vertx-examples by vert-x3.

the class SampleVerticleTest method countThreeTicksWithCheckpoints.

@Test
@DisplayName("⏱ Count 3 timer ticks, with a checkpoint")
void countThreeTicksWithCheckpoints(Vertx vertx, VertxTestContext testContext) {
    Checkpoint checkpoint = testContext.checkpoint(3);
    vertx.setPeriodic(100, id -> checkpoint.flag());
}
Also used : Checkpoint(io.vertx.junit5.Checkpoint)

Example 2 with Checkpoint

use of io.vertx.junit5.Checkpoint in project vertx-examples by vert-x3.

the class SampleVerticleTest method useSampleVerticle.

@Test
@DisplayName("🚀 Deploy a HTTP service verticle and make 10 requests")
void useSampleVerticle(Vertx vertx, VertxTestContext testContext) {
    WebClient webClient = WebClient.create(vertx);
    Checkpoint deploymentCheckpoint = testContext.checkpoint();
    Checkpoint requestCheckpoint = testContext.checkpoint(10);
    vertx.deployVerticle(new SampleVerticle(), testContext.succeeding(id -> {
        deploymentCheckpoint.flag();
        for (int i = 0; i < 10; i++) {
            webClient.get(11981, "localhost", "/").as(BodyCodec.string()).send(testContext.succeeding(resp -> {
                testContext.verify(() -> {
                    assertThat(resp.statusCode()).isEqualTo(200);
                    assertThat(resp.body()).contains("Yo!");
                    requestCheckpoint.flag();
                });
            }));
        }
    }));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) WebClient(io.vertx.ext.web.client.WebClient) org.junit.jupiter.api(org.junit.jupiter.api) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) BodyCodec(io.vertx.ext.web.codec.BodyCodec) VertxOptions(io.vertx.core.VertxOptions) Assertions(org.assertj.core.api.Assertions) Checkpoint(io.vertx.junit5.Checkpoint) VertxExtension(io.vertx.junit5.VertxExtension) Checkpoint(io.vertx.junit5.Checkpoint) WebClient(io.vertx.ext.web.client.WebClient)

Aggregations

Checkpoint (io.vertx.junit5.Checkpoint)2 Vertx (io.vertx.core.Vertx)1 VertxOptions (io.vertx.core.VertxOptions)1 WebClient (io.vertx.ext.web.client.WebClient)1 BodyCodec (io.vertx.ext.web.codec.BodyCodec)1 VertxExtension (io.vertx.junit5.VertxExtension)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 org.junit.jupiter.api (org.junit.jupiter.api)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1