diff --git a/framework/webflux-undertow/README.adoc b/framework/webflux-undertow/README.adoc new file mode 100644 index 0000000..df74cf7 --- /dev/null +++ b/framework/webflux-undertow/README.adoc @@ -0,0 +1 @@ +Tests if WebFlux with Undertow is working. diff --git a/framework/webflux-undertow/build.gradle b/framework/webflux-undertow/build.gradle new file mode 100644 index 0000000..1f7b0e1 --- /dev/null +++ b/framework/webflux-undertow/build.gradle @@ -0,0 +1,26 @@ +plugins { + id "java" + id "org.springframework.boot" + id "org.springframework.cr.smoke-test" +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("org.springframework.boot:spring-boot-starter-undertow") + modules { + module("org.springframework.boot:spring-boot-starter-reactor-netty") { + replacedBy("org.springframework.boot:spring-boot-starter-undertow", "Use Undertow instead of Netty") + } + } + implementation("org.crac:crac:$cracVersion") + implementation(project(":cr-listener")) + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + appTestImplementation(project(":cr-smoke-test-support")) +} + +crSmokeTest { + webApplication = true +} diff --git a/framework/webflux-undertow/src/appTest/java/com/example/webflux/WebfluxApplicationTests.java b/framework/webflux-undertow/src/appTest/java/com/example/webflux/WebfluxApplicationTests.java new file mode 100644 index 0000000..c36bdc7 --- /dev/null +++ b/framework/webflux-undertow/src/appTest/java/com/example/webflux/WebfluxApplicationTests.java @@ -0,0 +1,35 @@ +package com.example.webflux; + +import org.junit.jupiter.api.Test; + +import org.springframework.cr.smoketest.support.junit.ApplicationTest; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@ApplicationTest +class WebfluxApplicationTests { + + @Test + void stringResponseBody(WebTestClient client) { + client.get() + .exchange() + .expectStatus() + .isOk() + .expectBody() + .consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())) + .isEqualTo("Hello from Spring WebFlux and Undertow")); + } + + @Test + void resourceInStatic(WebTestClient client) { + client.get() + .uri("foo.html") + .exchange() + .expectStatus() + .isOk() + .expectBody() + .consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("Foo")); + } + +} diff --git a/framework/webflux-undertow/src/main/java/com/example/webflux/WebfluxApplication.java b/framework/webflux-undertow/src/main/java/com/example/webflux/WebfluxApplication.java new file mode 100644 index 0000000..7d00c48 --- /dev/null +++ b/framework/webflux-undertow/src/main/java/com/example/webflux/WebfluxApplication.java @@ -0,0 +1,13 @@ +package com.example.webflux; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WebfluxApplication { + + public static void main(String[] args) { + SpringApplication.run(WebfluxApplication.class, args); + } + +} diff --git a/framework/webflux-undertow/src/main/java/com/example/webflux/WebfluxController.java b/framework/webflux-undertow/src/main/java/com/example/webflux/WebfluxController.java new file mode 100644 index 0000000..1897b98 --- /dev/null +++ b/framework/webflux-undertow/src/main/java/com/example/webflux/WebfluxController.java @@ -0,0 +1,14 @@ +package com.example.webflux; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class WebfluxController { + + @GetMapping("/") + public String hello() { + return "Hello from Spring WebFlux and Undertow"; + } + +} diff --git a/framework/webflux-undertow/src/main/resources/static/foo.html b/framework/webflux-undertow/src/main/resources/static/foo.html new file mode 100644 index 0000000..9f26b63 --- /dev/null +++ b/framework/webflux-undertow/src/main/resources/static/foo.html @@ -0,0 +1 @@ +Foo \ No newline at end of file diff --git a/framework/webflux-undertow/src/test/java/com/example/webflux/test/RandomPortTests.java b/framework/webflux-undertow/src/test/java/com/example/webflux/test/RandomPortTests.java new file mode 100644 index 0000000..7a25ef5 --- /dev/null +++ b/framework/webflux-undertow/src/test/java/com/example/webflux/test/RandomPortTests.java @@ -0,0 +1,35 @@ +package com.example.webflux.test; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@SpringBootTest(webEnvironment = RANDOM_PORT) +public class RandomPortTests { + + @LocalServerPort + int port; + + @Test + void check() { + assertThat(this.port).isNotZero(); + } + + @Test + void webClientWorks(@Autowired WebTestClient webClient) { + webClient.get() + .uri("/") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("Hello from Spring WebFlux and Undertow"); + } + +}