Add thymeleaf-webmvc smoke test

Closes gh-57
This commit is contained in:
Moritz Halbritter
2022-08-05 16:07:15 +02:00
parent c0ea180938
commit 8aaf5281a6
10 changed files with 145 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ smoke_tests:
- spring-kafka
- spring-kafka-avro
- spring-kafka-streams
- thymeleaf-webmvc
- tracing-brave-zipkin
- transactional
- transactional-event-listener

View File

@@ -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"

View File

@@ -0,0 +1 @@
Tests if Thymeleaf view rendering works with WebMVC

View File

@@ -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
}

View File

@@ -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("<span>Hello</span>").contains("<span>world</span>"));
}
@Test
void authorListIsRendered(WebTestClient client) {
client.get().uri("/authors").exchange().expectStatus().isOk().expectBody()
.consumeWith((result) -> assertThat(new String(result.getResponseBodyContent()))
.contains("<li>Brian Goetz</li>").contains("<li>Joshua Bloch</li>"));
}
}

View File

@@ -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) {
}
}

View File

@@ -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
}
}

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<title>thymeleaf-webmvc test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<ul th:each="author, iter : ${authors}">
<li th:text="${author.name()}">Some name</li>
</ul>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<title>thymeleaf-webmvc test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p>
<span th:text="${model.greeting()}">Greeting</span>
<span th:text="${model.name()}">Who</span>
</p>
</body>
</html>

View File

@@ -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() {
}
}