Test some jaxrs features

This commit is contained in:
Andrea Cavalli 2021-11-07 13:04:24 +01:00
parent 92581efb3d
commit e864e800f1
3 changed files with 51 additions and 6 deletions

View File

@ -9,8 +9,8 @@
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
@ -62,10 +62,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging</artifactId>

View File

@ -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<String> 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));
}
}

View File

@ -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)));
}
}