From 8aaf5281a6c9b72577a8ef397cfb93a8877fcf33 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Fri, 5 Aug 2022 16:07:15 +0200 Subject: [PATCH] Add thymeleaf-webmvc smoke test Closes gh-57 --- ci/smoke-tests.yml | 1 + settings.gradle | 1 + thymeleaf-webmvc/README.adoc | 1 + thymeleaf-webmvc/build.gradle | 21 ++++++++++++ .../ThymeleafWebMvcApplicationAotTests.java | 27 +++++++++++++++ .../thymeleaf/webmvc/TestController.java | 34 +++++++++++++++++++ .../webmvc/ThymeleafWebMvcApplication.java | 14 ++++++++ .../src/main/resources/templates/authors.html | 15 ++++++++ .../src/main/resources/templates/index.html | 17 ++++++++++ .../ThymeleafWebMvcApplicationTests.java | 14 ++++++++ 10 files changed, 145 insertions(+) create mode 100644 thymeleaf-webmvc/README.adoc create mode 100644 thymeleaf-webmvc/build.gradle create mode 100644 thymeleaf-webmvc/src/aotTest/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplicationAotTests.java create mode 100644 thymeleaf-webmvc/src/main/java/com/example/thymeleaf/webmvc/TestController.java create mode 100644 thymeleaf-webmvc/src/main/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplication.java create mode 100644 thymeleaf-webmvc/src/main/resources/templates/authors.html create mode 100644 thymeleaf-webmvc/src/main/resources/templates/index.html create mode 100644 thymeleaf-webmvc/src/test/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplicationTests.java diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index adcd3a35..46e103a3 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -37,6 +37,7 @@ smoke_tests: - spring-kafka - spring-kafka-avro - spring-kafka-streams + - thymeleaf-webmvc - tracing-brave-zipkin - transactional - transactional-event-listener diff --git a/settings.gradle b/settings.gradle index 3c411e48..18f19db4 100644 --- a/settings.gradle +++ b/settings.gradle @@ -65,6 +65,7 @@ include "spring-amqp-rabbit" include "spring-kafka" include "spring-kafka-avro" include "spring-kafka-streams" +include "thymeleaf-webmvc" include "tracing-brave-zipkin" include "transactional" include "transactional-event-listener" diff --git a/thymeleaf-webmvc/README.adoc b/thymeleaf-webmvc/README.adoc new file mode 100644 index 00000000..ad337dbf --- /dev/null +++ b/thymeleaf-webmvc/README.adoc @@ -0,0 +1 @@ +Tests if Thymeleaf view rendering works with WebMVC diff --git a/thymeleaf-webmvc/build.gradle b/thymeleaf-webmvc/build.gradle new file mode 100644 index 00000000..caa56698 --- /dev/null +++ b/thymeleaf-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-thymeleaf") + + 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/thymeleaf-webmvc/src/aotTest/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplicationAotTests.java b/thymeleaf-webmvc/src/aotTest/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplicationAotTests.java new file mode 100644 index 00000000..462e3009 --- /dev/null +++ b/thymeleaf-webmvc/src/aotTest/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplicationAotTests.java @@ -0,0 +1,27 @@ +package com.example.thymeleaf.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 ThymeleafWebMvcApplicationAotTests { + + @Test + void greetingIsRendered(WebTestClient client) { + client.get().uri("/greeting").exchange().expectStatus().isOk().expectBody() + .consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())) + .contains("Hello").contains("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/thymeleaf-webmvc/src/main/java/com/example/thymeleaf/webmvc/TestController.java b/thymeleaf-webmvc/src/main/java/com/example/thymeleaf/webmvc/TestController.java new file mode 100644 index 00000000..ba9bc6f0 --- /dev/null +++ b/thymeleaf-webmvc/src/main/java/com/example/thymeleaf/webmvc/TestController.java @@ -0,0 +1,34 @@ +package com.example.thymeleaf.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 index(@RequestParam(defaultValue = "world") String name, Model model) { + model.addAttribute("model", new IndexModel("Hello", name)); + return "index"; + } + + @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/thymeleaf-webmvc/src/main/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplication.java b/thymeleaf-webmvc/src/main/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplication.java new file mode 100644 index 00000000..d562102c --- /dev/null +++ b/thymeleaf-webmvc/src/main/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplication.java @@ -0,0 +1,14 @@ +package com.example.thymeleaf.webmvc; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ThymeleafWebMvcApplication { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(ThymeleafWebMvcApplication.class, args); + Thread.currentThread().join(); // To be able to measure memory consumption + } + +} diff --git a/thymeleaf-webmvc/src/main/resources/templates/authors.html b/thymeleaf-webmvc/src/main/resources/templates/authors.html new file mode 100644 index 00000000..7ba04ee8 --- /dev/null +++ b/thymeleaf-webmvc/src/main/resources/templates/authors.html @@ -0,0 +1,15 @@ + + + + thymeleaf-webmvc test page + + + + + + + + + diff --git a/thymeleaf-webmvc/src/main/resources/templates/index.html b/thymeleaf-webmvc/src/main/resources/templates/index.html new file mode 100644 index 00000000..bead520d --- /dev/null +++ b/thymeleaf-webmvc/src/main/resources/templates/index.html @@ -0,0 +1,17 @@ + + + + thymeleaf-webmvc test page + + + + +

    + Greeting + Who +

    + + + + + diff --git a/thymeleaf-webmvc/src/test/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplicationTests.java b/thymeleaf-webmvc/src/test/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplicationTests.java new file mode 100644 index 00000000..dd59c3f8 --- /dev/null +++ b/thymeleaf-webmvc/src/test/java/com/example/thymeleaf/webmvc/ThymeleafWebMvcApplicationTests.java @@ -0,0 +1,14 @@ +package com.example.thymeleaf.webmvc; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ThymeleafWebMvcApplicationTests { + + @Test + void contextLoads() { + } + +}