diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index 1804ccae..f6fc9fba 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -4,6 +4,7 @@ smoke_tests: - aspect - async - batch + - cloud-function-web - command-line-runner - conditional - configuration-properties diff --git a/cloud-function-web/README.adoc b/cloud-function-web/README.adoc new file mode 100644 index 00000000..a321747c --- /dev/null +++ b/cloud-function-web/README.adoc @@ -0,0 +1 @@ +Tests if Spring Cloud Function Web works diff --git a/cloud-function-web/build.gradle b/cloud-function-web/build.gradle new file mode 100644 index 00000000..6add7496 --- /dev/null +++ b/cloud-function-web/build.gradle @@ -0,0 +1,27 @@ +plugins { + id 'java' + id 'org.springframework.boot' + id 'org.springframework.boot.aot' + id 'org.springframework.aot.smoke-test' + id 'org.graalvm.buildtools.native' +} + +ext { + set('springCloudVersion', "2022.0.0-SNAPSHOT") +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation(platform("org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}")) + implementation("org.springframework.boot:spring-boot-starter") + implementation("org.springframework.cloud:spring-cloud-starter-function-web") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + aotTestImplementation(project(":aot-smoke-test-support")) + aotTestImplementation("org.awaitility:awaitility:4.2.0") +} + +aotSmokeTest { + webApplication = true +} diff --git a/cloud-function-web/src/aotTest/java/com/example/cloud/function/web/CloudFunctionWebApplicationAotTests.java b/cloud-function-web/src/aotTest/java/com/example/cloud/function/web/CloudFunctionWebApplicationAotTests.java new file mode 100644 index 00000000..96d2b4f3 --- /dev/null +++ b/cloud-function-web/src/aotTest/java/com/example/cloud/function/web/CloudFunctionWebApplicationAotTests.java @@ -0,0 +1,28 @@ +package com.example.cloud.function.web; + +import org.junit.jupiter.api.Test; + +import org.springframework.aot.smoketest.support.junit.AotSmokeTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@AotSmokeTest +class CloudFunctionWebApplicationAotTests { + + @Test + void uppercaseShouldBeInvokable(WebTestClient webTestClient) { + webTestClient.post().uri("/uppercase").header("Content-Type", MediaType.TEXT_PLAIN_VALUE).bodyValue("hello") + .exchange().expectStatus().isOk().expectBody() + .consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("HELLO")); + } + + @Test + void lowercaseShouldBeInvokable(WebTestClient webTestClient) { + webTestClient.post().uri("/lowercase").header("Content-Type", MediaType.TEXT_PLAIN_VALUE).bodyValue("HELLO") + .exchange().expectStatus().isOk().expectBody() + .consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("hello")); + } + +} diff --git a/cloud-function-web/src/main/java/com/example/cloud/function/web/CloudFunctionWebApplication.java b/cloud-function-web/src/main/java/com/example/cloud/function/web/CloudFunctionWebApplication.java new file mode 100644 index 00000000..a0fe1c63 --- /dev/null +++ b/cloud-function-web/src/main/java/com/example/cloud/function/web/CloudFunctionWebApplication.java @@ -0,0 +1,13 @@ +package com.example.cloud.function.web; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CloudFunctionWebApplication { + + public static void main(String[] args) { + SpringApplication.run(CloudFunctionWebApplication.class, args); + } + +} diff --git a/cloud-function-web/src/main/java/com/example/cloud/function/web/Lowercase.java b/cloud-function-web/src/main/java/com/example/cloud/function/web/Lowercase.java new file mode 100644 index 00000000..f086804e --- /dev/null +++ b/cloud-function-web/src/main/java/com/example/cloud/function/web/Lowercase.java @@ -0,0 +1,16 @@ +package com.example.cloud.function.web; + +import java.util.Locale; +import java.util.function.Function; + +import org.springframework.stereotype.Component; + +@Component +class Lowercase implements Function { + + @Override + public String apply(String input) { + return input.toLowerCase(Locale.ENGLISH); + } + +} diff --git a/cloud-function-web/src/main/java/com/example/cloud/function/web/Uppercase.java b/cloud-function-web/src/main/java/com/example/cloud/function/web/Uppercase.java new file mode 100644 index 00000000..10eff8c2 --- /dev/null +++ b/cloud-function-web/src/main/java/com/example/cloud/function/web/Uppercase.java @@ -0,0 +1,16 @@ +package com.example.cloud.function.web; + +import java.util.Locale; +import java.util.function.Function; + +import org.springframework.stereotype.Component; + +@Component +class Uppercase implements Function { + + @Override + public String apply(String input) { + return input.toUpperCase(Locale.ENGLISH); + } + +} diff --git a/cloud-function-web/src/test/java/com/example/cloud/function/web/CloudFunctionWebApplicationTests.java b/cloud-function-web/src/test/java/com/example/cloud/function/web/CloudFunctionWebApplicationTests.java new file mode 100644 index 00000000..f4f5816e --- /dev/null +++ b/cloud-function-web/src/test/java/com/example/cloud/function/web/CloudFunctionWebApplicationTests.java @@ -0,0 +1,14 @@ +package com.example.cloud.function.web; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class CloudFunctionWebApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/settings.gradle b/settings.gradle index ebfbd8c0..2e2f5cac 100644 --- a/settings.gradle +++ b/settings.gradle @@ -36,6 +36,7 @@ include "actuator-webmvc" include "aspect" include "async" include "batch" +include "cloud-function-web" include "command-line-runner" include "conditional" include "configuration-properties"