diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index 456d4e63e7..376d8099ed 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -33,6 +33,7 @@ spring-cloud-contract spring-cloud-kubernetes spring-cloud-archaius + spring-cloud-functions spring-cloud-vault diff --git a/spring-cloud/spring-cloud-functions/pom.xml b/spring-cloud/spring-cloud-functions/pom.xml new file mode 100644 index 0000000000..e3c17329d0 --- /dev/null +++ b/spring-cloud/spring-cloud-functions/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + spring-cloud-functions + pom + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + spring-cloud-function-aws + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/pom.xml b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/pom.xml new file mode 100644 index 0000000000..8b2b0ad385 --- /dev/null +++ b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + + com.baeldung.spring + cloudfunction-aws + 0.0.1-SNAPSHOT + jar + + cloudfunction-aws + Demo project for Spring Cloud Function + + + org.springframework.boot + spring-boot-starter-parent + 2.0.4.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + 1.0.1.RELEASE + 2.0.2 + + + + + org.springframework.cloud + spring-cloud-function-adapter-aws + ${spring-cloud-function.version} + + + + + org.springframework.cloud + spring-cloud-starter-function-web + 1.0.1.RELEASE + + + com.amazonaws + aws-lambda-java-events + ${aws-lambda-events.version} + provided + + + com.amazonaws + aws-lambda-java-core + 1.1.0 + provided + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.springframework.boot.experimental + spring-boot-thin-layout + 1.0.10.RELEASE + + + + + org.apache.maven.plugins + maven-shade-plugin + + false + true + aws + + + + + + diff --git a/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/java/com/baeldung/spring/cloudfunction/CloudFunctionAwsApplication.java b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/java/com/baeldung/spring/cloudfunction/CloudFunctionAwsApplication.java new file mode 100644 index 0000000000..cc8f11beca --- /dev/null +++ b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/java/com/baeldung/spring/cloudfunction/CloudFunctionAwsApplication.java @@ -0,0 +1,23 @@ +package com.baeldung.spring.cloudfunction; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +@SpringBootApplication +public class CloudFunctionAwsApplication { + + public static void main(String[] args) { + SpringApplication.run(CloudFunctionAwsApplication.class, args); + } + + @Bean + public Function reverseString() { + return value -> new StringBuilder(value).reverse().toString(); + } + +} diff --git a/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/java/com/baeldung/spring/cloudfunction/StringReverseHandler.java b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/java/com/baeldung/spring/cloudfunction/StringReverseHandler.java new file mode 100644 index 0000000000..d103bc98d9 --- /dev/null +++ b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/java/com/baeldung/spring/cloudfunction/StringReverseHandler.java @@ -0,0 +1,7 @@ +package com.baeldung.spring.cloudfunction; + +import org.springframework.cloud.function.adapter.aws.SpringBootRequestHandler; + +public class StringReverseHandler extends SpringBootRequestHandler { + +} diff --git a/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/java/com/baeldung/spring/cloudfunction/functions/Greeter.java b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/java/com/baeldung/spring/cloudfunction/functions/Greeter.java new file mode 100644 index 0000000000..124aefe56e --- /dev/null +++ b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/java/com/baeldung/spring/cloudfunction/functions/Greeter.java @@ -0,0 +1,11 @@ +package com.baeldung.spring.cloudfunction.functions; + +import java.util.function.Function; + +public class Greeter implements Function { + + @Override + public String apply(String s) { + return "Hello " + s + ", and welcome to Spring Cloud Function!!!"; + } +} diff --git a/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/resources/application.properties b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/resources/application.properties new file mode 100644 index 0000000000..14426a848c --- /dev/null +++ b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.cloud.function.scan.packages: com.baeldung.spring.cloudfunction.functions \ No newline at end of file diff --git a/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/test/java/com/baeldung/spring/cloudfunction/CloudFunctionApplicationTests.java b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/test/java/com/baeldung/spring/cloudfunction/CloudFunctionApplicationTests.java new file mode 100644 index 0000000000..01199475fb --- /dev/null +++ b/spring-cloud/spring-cloud-functions/spring-cloud-function-aws/src/test/java/com/baeldung/spring/cloudfunction/CloudFunctionApplicationTests.java @@ -0,0 +1,33 @@ +package com.baeldung.spring.cloudfunction; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class CloudFunctionApplicationTests { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate testRestTemplate; + + @Test + public void givenAString_whenReverseStringCloudFunctionInvoked_thenStringIsReversed() { + assertThat(this.testRestTemplate.getForObject("http://localhost:" + port + "/reverseString/HelloWorld", String.class)).isEqualTo("dlroWolleH"); + } + + @Test + public void givenAString_whenGreeterCloudFunctionInvoked_thenPrintsGreeting() { + assertThat(this.testRestTemplate.getForObject("http://localhost:" + port + "/greeter/BaeldungUser", String.class)).isEqualTo("Hello BaeldungUser, and welcome to Spring Cloud Function!!!"); + } + +}