Skip to content

Commit

Permalink
Qute: dev mode - no-restart-templates
Browse files Browse the repository at this point in the history
- fix javadoc in QuteDevModeConfig
- improve NoRestartTemplatesDevModeTest
  • Loading branch information
mkouba committed Nov 21, 2023
1 parent 6c11d36 commit 2ff9715
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import io.quarkus.qute.Location;
import io.quarkus.qute.Template;
import io.quarkus.vertx.web.Route;
import io.vertx.ext.web.RoutingContext;
Expand All @@ -15,12 +16,20 @@ public class NoRestartRoute {

private String id;

@Inject
@Location("foo/norestart")
Template norestart;

@Inject
Template bar;

@Route(path = "norestart")
public void test(RoutingContext ctx) {
ctx.end(norestart.data("foo", id).render());
ctx.end(norestart.data("id", id).render());
}

@Route(path = "bar")
public void testBar(RoutingContext ctx) {
ctx.end(bar.data("id", id).render());
}

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,39 @@ public class NoRestartTemplatesDevModeTest {
.withApplicationRoot(root -> root
.addClass(NoRestartRoute.class)
.addAsResource(new StringAsset(
"Hello {foo}!"),
"templates/norestart.html")
"Hello {id}!"),
"templates/foo/norestart.html")
.addAsResource(new StringAsset(
"quarkus.qute.dev-mode.no-restart-templates=templates/norestart.html"),
"Hi {id}!"),
"templates/bar.html")
.addAsResource(new StringAsset(
"quarkus.qute.dev-mode.no-restart-templates=templates/.+"),
"application.properties"));

@Test
public void testNoRestartTemplates() {
Response resp = given().get("norestart");
resp.then()
.statusCode(200);
String val = resp.getBody().asString();
assertTrue(val.startsWith("Hello "));
String val1 = resp.getBody().asString();
assertTrue(val1.startsWith("Hello "));

resp = given().get("bar");
resp.then()
.statusCode(200);
String val2 = resp.getBody().asString();
assertTrue(val2.startsWith("Hi "));

config.modifyResourceFile("templates/norestart.html", t -> t.concat("!!"));
config.modifyResourceFile("templates/foo/norestart.html", t -> t.concat("!!"));
config.modifyResourceFile("templates/bar.html", t -> t.concat("!!"));

resp = given().get("norestart");
resp.then().statusCode(200);
assertEquals(val + "!!", resp.getBody().asString());
assertEquals(val1 + "!!", resp.getBody().asString());

resp = given().get("bar");
resp.then().statusCode(200);
assertEquals(val2 + "!!", resp.getBody().asString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class QuteDevModeConfig {
* This regular expression can be used to specify the templates for which the application is not restarted.
* I.e. the templates are reloaded and only runtime validations are performed.
* <p>
* The matched input is the template path relative from the {@code templates} directory and the
* {@code /} is used as a path separator. For example, {@code templates/foo.html}.
* The matched input is the template path that starts with a template root, and the {@code /} is used as a path separator.
* For example, {@code templates/foo.html}.
*/
@ConfigItem
public Optional<Pattern> noRestartTemplates;
Expand Down

0 comments on commit 2ff9715

Please sign in to comment.