Skip to content

Commit

Permalink
Dev mode: add QuteWatchedResourceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Oct 17, 2023
1 parent cc211a6 commit 76b5eaf
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,14 @@ void collectTemplates(ApplicationArchivesBuildItem applicationArchives,
List<ResolvedDependency> 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<String>() {
@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit 76b5eaf

Please sign in to comment.