From 3dfb69841fc1d3ced7b83f39047c9297bbc1ec77 Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Tue, 30 Jul 2019 15:04:33 +0200 Subject: [PATCH] Add WebFlux Coroutines smoke test See gh-17701 --- .../spring-boot-smoke-tests/pom.xml | 1 + .../pom.xml | 83 +++++++++++++++++++ .../coroutines/CoroutinesApplication.kt | 10 +++ .../coroutines/CoroutinesController.kt | 24 ++++++ .../coroutines/CoroutinesApplicationTests.kt | 25 ++++++ 5 files changed, 143 insertions(+) create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/pom.xml create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/main/kotlin/smoketest/coroutines/CoroutinesApplication.kt create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/main/kotlin/smoketest/coroutines/CoroutinesController.kt create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/test/kotlin/smoketest/coroutines/CoroutinesApplicationTests.kt diff --git a/spring-boot-tests/spring-boot-smoke-tests/pom.xml b/spring-boot-tests/spring-boot-smoke-tests/pom.xml index 7d08c31aa7..d6cf48412c 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/pom.xml +++ b/spring-boot-tests/spring-boot-smoke-tests/pom.xml @@ -98,6 +98,7 @@ spring-boot-smoke-test-web-static spring-boot-smoke-test-web-ui spring-boot-smoke-test-webflux + spring-boot-smoke-test-webflux-coroutines spring-boot-smoke-test-websocket-jetty spring-boot-smoke-test-websocket-tomcat spring-boot-smoke-test-websocket-undertow diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/pom.xml b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/pom.xml new file mode 100644 index 0000000000..b7a7ababd6 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-smoke-tests + ${revision} + + spring-boot-smoke-test-webflux-coroutines + Spring Boot WebFlux Coroutines Smoke Test + Spring Boot WebFlux Coroutines Smoke Test + + ${basedir}/../../.. + / + + + + + org.springframework.boot + spring-boot-starter-webflux + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + org.jetbrains.kotlin + kotlin-reflect + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + + + org.jetbrains.kotlinx + kotlinx-coroutines-reactor + + + + org.springframework.boot + spring-boot-starter-test + test + + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + org.springframework.boot + spring-boot-maven-plugin + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + -Xjsr305=strict + + + spring + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + org.apache.maven.plugins + maven-surefire-plugin + + false + + + + + diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/main/kotlin/smoketest/coroutines/CoroutinesApplication.kt b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/main/kotlin/smoketest/coroutines/CoroutinesApplication.kt new file mode 100644 index 0000000000..f545fa81e0 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/main/kotlin/smoketest/coroutines/CoroutinesApplication.kt @@ -0,0 +1,10 @@ +package smoketest.coroutines + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication + +@SpringBootApplication +class CoroutinesApplication +fun main(args: Array) { + runApplication(*args) +} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/main/kotlin/smoketest/coroutines/CoroutinesController.kt b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/main/kotlin/smoketest/coroutines/CoroutinesController.kt new file mode 100644 index 0000000000..9e902cf2e3 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/main/kotlin/smoketest/coroutines/CoroutinesController.kt @@ -0,0 +1,24 @@ +package smoketest.coroutines + +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.flow +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +class CoroutinesController { + + @GetMapping("/suspending") + suspend fun suspendingFunction(): String { + delay(10) + return "Hello World" + } + + @GetMapping("/flow") + fun flow() = flow { + delay(10) + emit("Hello ") + delay(10) + emit("World") + } +} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/test/kotlin/smoketest/coroutines/CoroutinesApplicationTests.kt b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/test/kotlin/smoketest/coroutines/CoroutinesApplicationTests.kt new file mode 100644 index 0000000000..1af3624504 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-coroutines/src/test/kotlin/smoketest/coroutines/CoroutinesApplicationTests.kt @@ -0,0 +1,25 @@ +package smoketest.coroutines + +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.context.SpringBootTest.* +import org.springframework.http.MediaType +import org.springframework.test.web.reactive.server.WebTestClient +import org.springframework.test.web.reactive.server.expectBody + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class CoroutinesApplicationTests(@Autowired private val webClient: WebTestClient) { + + @Test + fun testSuspendingFunction() { + webClient.get().uri("/suspending").accept(MediaType.TEXT_PLAIN).exchange() + .expectBody().isEqualTo("Hello World") + } + + @Test + fun testFlow() { + webClient.get().uri("/flow").accept(MediaType.TEXT_PLAIN).exchange() + .expectBody().isEqualTo("Hello World") + } +}