From 76b5eaf7ff4ef260169b2c2dbe278b258c63bbd2 Mon Sep 17 00:00:00 2001 From: Martin Kouba Date: Tue, 17 Oct 2023 10:47:39 +0200 Subject: [PATCH] Dev mode: add QuteWatchedResourceTest --- .../qute/deployment/QuteProcessor.java | 8 +++ .../io/quarkus/test/qute/HelloResource.java | 32 ++++++++++++ .../test/qute/QuteWatchedResourceTest.java | 51 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 integration-tests/devmode/src/test/java/io/quarkus/test/qute/HelloResource.java create mode 100644 integration-tests/devmode/src/test/java/io/quarkus/test/qute/QuteWatchedResourceTest.java diff --git a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java index 54a1022511e6b..c0cf32ede02cd 100644 --- a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java +++ b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java @@ -2091,6 +2091,14 @@ void collectTemplates(ApplicationArchivesBuildItem applicationArchives, List extensionArtifacts = curateOutcome.getApplicationModel().getDependencies().stream() .filter(Dependency::isRuntimeExtensionArtifact).collect(Collectors.toList()); + // Make sure the new templates are watched as well + watchedPaths.produce(HotDeploymentWatchedFileBuildItem.builder().setLocationPredicate(new Predicate() { + @Override + public boolean test(String path) { + return path.startsWith(BASE_PATH); + } + }).build()); + for (ResolvedDependency artifact : extensionArtifacts) { if (isApplicationArchive(artifact, allApplicationArchives)) { // Skip extension archives that are also application archives diff --git a/integration-tests/devmode/src/test/java/io/quarkus/test/qute/HelloResource.java b/integration-tests/devmode/src/test/java/io/quarkus/test/qute/HelloResource.java new file mode 100644 index 0000000000000..d0165af028e83 --- /dev/null +++ b/integration-tests/devmode/src/test/java/io/quarkus/test/qute/HelloResource.java @@ -0,0 +1,32 @@ +package io.quarkus.test.qute; + +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +import org.jboss.resteasy.reactive.RestQuery; + +import io.quarkus.qute.Engine; +import io.quarkus.qute.Template; + +@Path("hello") +public class HelloResource { + + @Inject + Template hello; + + @Inject + Engine engine; + + @GET + public String get(@RestQuery String name) { + return hello.data("name", name).render(); + } + + @GET + @Path("ping") + public String ping() { + return engine.getTemplate("ping").render(); + } + +} diff --git a/integration-tests/devmode/src/test/java/io/quarkus/test/qute/QuteWatchedResourceTest.java b/integration-tests/devmode/src/test/java/io/quarkus/test/qute/QuteWatchedResourceTest.java new file mode 100644 index 0000000000000..f61c8969fb8dc --- /dev/null +++ b/integration-tests/devmode/src/test/java/io/quarkus/test/qute/QuteWatchedResourceTest.java @@ -0,0 +1,51 @@ +package io.quarkus.test.qute; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.CoreMatchers.containsString; + +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusDevModeTest; + +public class QuteWatchedResourceTest { + + @RegisterExtension + static final QuarkusDevModeTest config = new QuarkusDevModeTest() + .withApplicationRoot( + root -> root.addClass(HelloResource.class) + .addAsResource(new StringAsset("Hello {name}!"), "templates/hello.txt")); + + @Test + public void testWatchedFiles() { + when().get("/hello?name=Martin").then() + .body(containsString("Hello Martin!")) + .statusCode(200); + + config.modifyResourceFile("templates/hello.txt", file -> "Hi {name}!"); + + when().get("/hello?name=Martin").then() + .body(containsString("Hi Martin!")) + .statusCode(200); + + config.modifyResourceFile("templates/hello.txt", file -> "Hello {name}!"); + + when().get("/hello?name=Martin").then() + .body(containsString("Hello Martin!")) + .statusCode(200); + + config.addResourceFile("templates/ping.txt", "pong"); + + when().get("/hello/ping").then() + .body(containsString("pong")) + .statusCode(200); + + config.modifyResourceFile("templates/ping.txt", file -> "pong!"); + + when().get("/hello/ping").then() + .body(containsString("pong!")) + .statusCode(200); + } + +}