From e864e800f13b989a7244e6928eebd4b9782aac9e Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 7 Nov 2021 13:04:24 +0100 Subject: [PATCH] Test some jaxrs features --- volvox/pom.xml | 8 ++---- .../it/cavallium/ExampleDelayedResource.java | 27 +++++++++++++++++++ .../cavallium/ExampleDelayResourceTest.java | 22 +++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 volvox/src/main/java/it/cavallium/ExampleDelayedResource.java create mode 100644 volvox/src/test/java/it/cavallium/ExampleDelayResourceTest.java diff --git a/volvox/pom.xml b/volvox/pom.xml index 138dbe9..6d4f365 100644 --- a/volvox/pom.xml +++ b/volvox/pom.xml @@ -9,8 +9,8 @@ 3.8.1 true - 11 - 11 + 17 + 17 UTF-8 UTF-8 quarkus-bom @@ -62,10 +62,6 @@ io.quarkus quarkus-resteasy-reactive-jsonb - - io.quarkus - quarkus-resteasy-mutiny - io.quarkus quarkus-smallrye-reactive-messaging diff --git a/volvox/src/main/java/it/cavallium/ExampleDelayedResource.java b/volvox/src/main/java/it/cavallium/ExampleDelayedResource.java new file mode 100644 index 0000000..a97d76c --- /dev/null +++ b/volvox/src/main/java/it/cavallium/ExampleDelayedResource.java @@ -0,0 +1,27 @@ +package it.cavallium; + +import io.smallrye.mutiny.Uni; +import java.time.Duration; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +@Path("/delay") +public class ExampleDelayedResource { + + @Path("{seconds:\\d+}") + @GET + @Produces(MediaType.TEXT_PLAIN) + public Uni delay(int seconds) { + return Uni + + // Create the response item + .createFrom().item("Hello from the future! %d seconds have passed".formatted(seconds)) + + // Delay the response by n seconds + .onItem().delayIt().by(Duration.ofSeconds(seconds)); + } +} \ No newline at end of file diff --git a/volvox/src/test/java/it/cavallium/ExampleDelayResourceTest.java b/volvox/src/test/java/it/cavallium/ExampleDelayResourceTest.java new file mode 100644 index 0000000..c27eedb --- /dev/null +++ b/volvox/src/test/java/it/cavallium/ExampleDelayResourceTest.java @@ -0,0 +1,22 @@ +package it.cavallium; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +@QuarkusTest +public class ExampleDelayResourceTest { + + @Test + public void testHelloEndpoint() { + given() + .when() + .get("/delay?duration=1") + .then() + .statusCode(200) + .body(is("Hello from the future! %d seconds have passed".formatted(1))); + } + +} \ No newline at end of file