From c673fdd3d8344f55eb2b24fa5a0e34e45cd048bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Fri, 30 Sep 2022 12:27:41 +0200 Subject: [PATCH] Add kotlin-functional sample Related to https://github.com/spring-projects/spring-framework/issues/29211 --- kotlin-functional/build.gradle | 21 ++++++++++++++++ .../FunctionalApplicationAotTests.java | 23 ++++++++++++++++++ .../functional/FunctionalApplication.kt | 24 +++++++++++++++++++ settings.gradle | 1 + .../example/webflux/WebfluxApplication.java | 3 --- 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 kotlin-functional/build.gradle create mode 100644 kotlin-functional/src/aotSmokeTest/java/com/example/functional/FunctionalApplicationAotTests.java create mode 100644 kotlin-functional/src/main/kotlin/com/example/functional/FunctionalApplication.kt diff --git a/kotlin-functional/build.gradle b/kotlin-functional/build.gradle new file mode 100644 index 00000000..9f305d72 --- /dev/null +++ b/kotlin-functional/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' + id 'org.springframework.boot' + id 'org.springframework.aot.smoke-test' + id 'org.graalvm.buildtools.native' + id 'org.jetbrains.kotlin.jvm' + id 'org.jetbrains.kotlin.plugin.spring' version "1.7.10" +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + aotSmokeTestImplementation(project(":aot-smoke-test-support")) + aotSmokeTestImplementation("org.awaitility:awaitility:4.2.0") +} + diff --git a/kotlin-functional/src/aotSmokeTest/java/com/example/functional/FunctionalApplicationAotTests.java b/kotlin-functional/src/aotSmokeTest/java/com/example/functional/FunctionalApplicationAotTests.java new file mode 100644 index 00000000..c595acd9 --- /dev/null +++ b/kotlin-functional/src/aotSmokeTest/java/com/example/functional/FunctionalApplicationAotTests.java @@ -0,0 +1,23 @@ +package com.example.functional; + +import java.time.Duration; + +import org.awaitility.Awaitility; +import org.junit.jupiter.api.Test; + +import org.springframework.aot.smoketest.support.assertj.AssertableOutput; +import org.springframework.aot.smoketest.support.junit.AotSmokeTest; + +import static org.assertj.core.api.Assertions.assertThat; + +@AotSmokeTest +public class FunctionalApplicationAotTests { + + @Test + void expectedLoggingIsProduced(AssertableOutput output) { + Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> { + assertThat(output).hasSingleLineContaining("Hello World"); + }); + } + +} diff --git a/kotlin-functional/src/main/kotlin/com/example/functional/FunctionalApplication.kt b/kotlin-functional/src/main/kotlin/com/example/functional/FunctionalApplication.kt new file mode 100644 index 00000000..98b31e99 --- /dev/null +++ b/kotlin-functional/src/main/kotlin/com/example/functional/FunctionalApplication.kt @@ -0,0 +1,24 @@ +package com.example.functional + +import org.springframework.boot.CommandLineRunner +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication +import org.springframework.context.support.beans + +@SpringBootApplication +class FunctionalApplication + +fun main(args: Array) { + runApplication(*args) { + addInitializers(beans { + bean() + }) + } +} + +class Foo : CommandLineRunner { + override fun run(vararg args: String?) { + println("Hello world!") + } +} + diff --git a/settings.gradle b/settings.gradle index 140820ec..d7684990 100644 --- a/settings.gradle +++ b/settings.gradle @@ -69,6 +69,7 @@ include "freemarker-webflux" include "freemarker-webmvc" include "hateoas" include "integration" +include "kotlin-functional" include "jdbc-h2" include "jdbc-mariadb" include "jdbc-mysql" diff --git a/webflux-netty/src/main/java/com/example/webflux/WebfluxApplication.java b/webflux-netty/src/main/java/com/example/webflux/WebfluxApplication.java index 514aab7e..52955be9 100644 --- a/webflux-netty/src/main/java/com/example/webflux/WebfluxApplication.java +++ b/webflux-netty/src/main/java/com/example/webflux/WebfluxApplication.java @@ -1,14 +1,11 @@ package com.example.webflux; -import org.springframework.aot.smoketest.thirdpartyhints.JaxbRuntimeHints; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication -@ImportRuntimeHints(JaxbRuntimeHints.class) public class WebfluxApplication { public static void main(String[] args) {