diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index bc12bab7..99fd55fb 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -30,6 +30,7 @@ smoke_tests: - event-listener - flyway - freemarker-webflux + - freemarker-webmvc - hateoas - jdbc - liquibase diff --git a/freemarker-webmvc/README.adoc b/freemarker-webmvc/README.adoc new file mode 100644 index 00000000..f4f5eb2b --- /dev/null +++ b/freemarker-webmvc/README.adoc @@ -0,0 +1 @@ +Tests if Freemarker view rendering works with WebMVC diff --git a/freemarker-webmvc/build.gradle b/freemarker-webmvc/build.gradle new file mode 100644 index 00000000..efa55e38 --- /dev/null +++ b/freemarker-webmvc/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' + id 'org.springframework.boot' + id 'org.springframework.aot.smoke-test' + id 'org.graalvm.buildtools.native' +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-freemarker") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + aotTestImplementation(project(":aot-smoke-test-support")) + aotTestImplementation("org.awaitility:awaitility:4.2.0") +} + +aotSmokeTest { + webApplication = true +} diff --git a/freemarker-webmvc/src/aotTest/java/com/example/freemarker/webmvc/FreemarkerWebMvcApplicationAotTests.java b/freemarker-webmvc/src/aotTest/java/com/example/freemarker/webmvc/FreemarkerWebMvcApplicationAotTests.java new file mode 100644 index 00000000..10c384b1 --- /dev/null +++ b/freemarker-webmvc/src/aotTest/java/com/example/freemarker/webmvc/FreemarkerWebMvcApplicationAotTests.java @@ -0,0 +1,26 @@ +package com.example.freemarker.webmvc; + +import org.junit.jupiter.api.Test; + +import org.springframework.aot.smoketest.support.junit.AotSmokeTest; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@AotSmokeTest +class FreemarkerWebMvcApplicationAotTests { + + @Test + void greetingIsRendered(WebTestClient client) { + client.get().uri("/greeting").exchange().expectStatus().isOk().expectBody().consumeWith( + (result) -> assertThat(new String(result.getResponseBodyContent())).contains("Hello world")); + } + + @Test + void authorListIsRendered(WebTestClient client) { + client.get().uri("/authors").exchange().expectStatus().isOk().expectBody() + .consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())) + .contains("
  • Brian Goetz
  • ").contains("
  • Joshua Bloch
  • ")); + } + +} diff --git a/freemarker-webmvc/src/main/java/com/example/freemarker/webmvc/FreemarkerWebMvcApplication.java b/freemarker-webmvc/src/main/java/com/example/freemarker/webmvc/FreemarkerWebMvcApplication.java new file mode 100644 index 00000000..e25aeddc --- /dev/null +++ b/freemarker-webmvc/src/main/java/com/example/freemarker/webmvc/FreemarkerWebMvcApplication.java @@ -0,0 +1,14 @@ +package com.example.freemarker.webmvc; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FreemarkerWebMvcApplication { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(FreemarkerWebMvcApplication.class, args); + Thread.currentThread().join(); // To be able to measure memory consumption + } + +} diff --git a/freemarker-webmvc/src/main/java/com/example/freemarker/webmvc/TestController.java b/freemarker-webmvc/src/main/java/com/example/freemarker/webmvc/TestController.java new file mode 100644 index 00000000..decc9663 --- /dev/null +++ b/freemarker-webmvc/src/main/java/com/example/freemarker/webmvc/TestController.java @@ -0,0 +1,34 @@ +package com.example.freemarker.webmvc; + +import java.util.List; + +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +@RequestMapping(produces = MediaType.TEXT_HTML_VALUE) +public class TestController { + + @GetMapping("/greeting") + public String greeting(@RequestParam(defaultValue = "world") String name, Model model) { + model.addAttribute("model", new IndexModel("Hello", name)); + return "greeting"; + } + + @GetMapping("/authors") + public String authors(Model model) { + model.addAttribute("authors", List.of(new Author("Brian Goetz"), new Author("Joshua Bloch"))); + return "authors"; + } + + public record IndexModel(String greeting, String name) { + } + + public record Author(String name) { + } + +} diff --git a/freemarker-webmvc/src/main/resources/templates/authors.ftlh b/freemarker-webmvc/src/main/resources/templates/authors.ftlh new file mode 100644 index 00000000..144cdf9f --- /dev/null +++ b/freemarker-webmvc/src/main/resources/templates/authors.ftlh @@ -0,0 +1,18 @@ +<#-- @ftlvariable name="authors" type="com.example.freemarker.webmvc.TestController.Author[]" --> + + + + freemarker-webflux test page + + + + + + + + + diff --git a/freemarker-webmvc/src/main/resources/templates/greeting.ftlh b/freemarker-webmvc/src/main/resources/templates/greeting.ftlh new file mode 100644 index 00000000..128e26f4 --- /dev/null +++ b/freemarker-webmvc/src/main/resources/templates/greeting.ftlh @@ -0,0 +1,16 @@ +<#-- @ftlvariable name="model" type="com.example.freemarker.webmvc.TestController.IndexModel" --> + + + + freemarker-webflux test page + + + + +

    + ${model.greeting()} ${model.name()} +

    + + + + diff --git a/freemarker-webmvc/src/test/java/com/example/freemarker/webmvc/FreemarkerWebMvcApplicationTests.java b/freemarker-webmvc/src/test/java/com/example/freemarker/webmvc/FreemarkerWebMvcApplicationTests.java new file mode 100644 index 00000000..7979eb81 --- /dev/null +++ b/freemarker-webmvc/src/test/java/com/example/freemarker/webmvc/FreemarkerWebMvcApplicationTests.java @@ -0,0 +1,14 @@ +package com.example.freemarker.webmvc; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class FreemarkerWebMvcApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/settings.gradle b/settings.gradle index 3a49f68e..e3e30fa6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -58,6 +58,7 @@ include "data-rest-mongodb" include "event-listener" include "flyway" include "freemarker-webflux" +include "freemarker-webmvc" include "hateoas" include "jdbc" include "liquibase"