Add freemarker-webmvc smoke test
Closes gh-46
This commit is contained in:
@@ -30,6 +30,7 @@ smoke_tests:
|
||||
- event-listener
|
||||
- flyway
|
||||
- freemarker-webflux
|
||||
- freemarker-webmvc
|
||||
- hateoas
|
||||
- jdbc
|
||||
- liquibase
|
||||
|
||||
1
freemarker-webmvc/README.adoc
Normal file
1
freemarker-webmvc/README.adoc
Normal file
@@ -0,0 +1 @@
|
||||
Tests if Freemarker view rendering works with WebMVC
|
||||
21
freemarker-webmvc/build.gradle
Normal file
21
freemarker-webmvc/build.gradle
Normal 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-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
|
||||
}
|
||||
@@ -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("<li>Brian Goetz</li>").contains("<li>Joshua Bloch</li>"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
}
|
||||
|
||||
}
|
||||
18
freemarker-webmvc/src/main/resources/templates/authors.ftlh
Normal file
18
freemarker-webmvc/src/main/resources/templates/authors.ftlh
Normal file
@@ -0,0 +1,18 @@
|
||||
<#-- @ftlvariable name="authors" type="com.example.freemarker.webmvc.TestController.Author[]" -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>freemarker-webflux test page</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<ul>
|
||||
<#list authors as author>
|
||||
<li>${author.name()}</li>
|
||||
</#list>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
16
freemarker-webmvc/src/main/resources/templates/greeting.ftlh
Normal file
16
freemarker-webmvc/src/main/resources/templates/greeting.ftlh
Normal file
@@ -0,0 +1,16 @@
|
||||
<#-- @ftlvariable name="model" type="com.example.freemarker.webmvc.TestController.IndexModel" -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>freemarker-webflux test page</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>
|
||||
${model.greeting()} ${model.name()}
|
||||
</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user