From 5a17f1d447ac2ad47c4153c3ef4daae7f32ec8ce Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Thu, 2 May 2024 12:20:08 +0200 Subject: [PATCH] Qute: add integration test for test templates - i.e. add a test with templates in both (1) src/main/resources/templates and (2) src/test/resources/templates --- integration-tests/qute/pom.xml | 4 +-- .../java/io/quarkus/it/qute/HiResource.java | 25 +++++++++++++++++++ .../java/io/quarkus/it/qute/QuteTestCase.java | 10 ++++++++ .../qute/src/test/resources/templates/hi.txt | 1 + 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 integration-tests/qute/src/test/java/io/quarkus/it/qute/HiResource.java create mode 100644 integration-tests/qute/src/test/resources/templates/hi.txt diff --git a/integration-tests/qute/pom.xml b/integration-tests/qute/pom.xml index 1e6870c1a471f..4f9f70242985f 100644 --- a/integration-tests/qute/pom.xml +++ b/integration-tests/qute/pom.xml @@ -16,7 +16,7 @@ io.quarkus - quarkus-resteasy-qute + quarkus-rest-qute io.quarkus @@ -51,7 +51,7 @@ io.quarkus - quarkus-resteasy-qute-deployment + quarkus-rest-qute-deployment ${project.version} pom test diff --git a/integration-tests/qute/src/test/java/io/quarkus/it/qute/HiResource.java b/integration-tests/qute/src/test/java/io/quarkus/it/qute/HiResource.java new file mode 100644 index 0000000000000..e07090553c995 --- /dev/null +++ b/integration-tests/qute/src/test/java/io/quarkus/it/qute/HiResource.java @@ -0,0 +1,25 @@ +package io.quarkus.it.qute; + +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.MediaType; + +import io.quarkus.qute.Template; +import io.quarkus.qute.TemplateInstance; + +@Path("/hi") +public class HiResource { + + @Inject + Template hi; + + @GET + @Produces(MediaType.TEXT_PLAIN) + public TemplateInstance get(@QueryParam("name") String name) { + return hi.data("name", name); + } + +} diff --git a/integration-tests/qute/src/test/java/io/quarkus/it/qute/QuteTestCase.java b/integration-tests/qute/src/test/java/io/quarkus/it/qute/QuteTestCase.java index 7044d12b806c8..4f43b07e835c1 100644 --- a/integration-tests/qute/src/test/java/io/quarkus/it/qute/QuteTestCase.java +++ b/integration-tests/qute/src/test/java/io/quarkus/it/qute/QuteTestCase.java @@ -2,10 +2,12 @@ import static jakarta.ws.rs.core.Response.Status.NOT_FOUND; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import org.junit.jupiter.api.Test; +import io.quarkus.test.junit.DisabledOnIntegrationTest; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -33,4 +35,12 @@ public void testNotFoundPageStatusCode() { .body(containsString("Not Found!")) .statusCode(NOT_FOUND.getStatusCode()); } + + // Keep in mind that src/test/java is not part of the native image + @DisabledOnIntegrationTest + @Test + public void testTemplateLocatedInTestSource() { + RestAssured.when().get("/hi?name=Ciri").then().body(equalTo("Hi Ciri!")); + } + } diff --git a/integration-tests/qute/src/test/resources/templates/hi.txt b/integration-tests/qute/src/test/resources/templates/hi.txt new file mode 100644 index 0000000000000..3f988823f5f04 --- /dev/null +++ b/integration-tests/qute/src/test/resources/templates/hi.txt @@ -0,0 +1 @@ +Hi {name}! \ No newline at end of file