Add WebFlux with Undertow tests

This commit is contained in:
Sébastien Deleuze
2023-07-06 11:17:09 +02:00
parent 619d959a31
commit 4c6fe33697
7 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1 @@
Tests if WebFlux with Undertow is working.

View File

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

View File

@@ -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"));
}
}

View File

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

View File

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

View File

@@ -0,0 +1 @@
Foo

View File

@@ -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");
}
}