From ba05872a01e55c89c2a73c6b89772fe2228fdbf4 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 12 Aug 2019 10:19:06 +0200 Subject: [PATCH] Added sample app with SCF on classpath --- .../src/it/bootapp-with-scf/pom.xml | 71 +++++++++++++++++++ .../example/SimpleFunctionAppApplication.java | 57 +++++++++++++++ .../function/example/UpperCaseFunction.java | 13 ++++ .../deployer/FunctionDeployerTests.java | 21 ++++++ 4 files changed, 162 insertions(+) create mode 100644 spring-cloud-function-deployer-new/src/it/bootapp-with-scf/pom.xml create mode 100644 spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/SimpleFunctionAppApplication.java create mode 100644 spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/UpperCaseFunction.java diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/pom.xml b/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/pom.xml new file mode 100644 index 000000000..ce10bf055 --- /dev/null +++ b/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + function.example + bootapp-with-scf + 0.0.1.BUILD-SNAPSHOT + jar + + + org.springframework.boot + spring-boot-starter-parent + 2.2.0.BUILD-SNAPSHOT + + + + + 1.8 + 3.0.0.BUILD-SNAPSHOT + 1.0.17.RELEASE + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.cloud + spring-cloud-function-context + ${spring-cloud-function.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + exec + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + package + + unpack + + + + + ${project.groupId} + ${project.artifactId} + ${project.version} + exec + + + + + + + + + diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/SimpleFunctionAppApplication.java b/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/SimpleFunctionAppApplication.java new file mode 100644 index 000000000..ed8f694ef --- /dev/null +++ b/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/SimpleFunctionAppApplication.java @@ -0,0 +1,57 @@ +package function.example; + +import java.util.function.Function; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class SimpleFunctionAppApplication { + + public static void main(String[] args) { + SpringApplication.run(SimpleFunctionAppApplication.class, args); + } + + @Bean + public Function uppercase() { + System.out.println("==> CREATING 'uppercase' FUNCTION bean"); + return new UpperCaseFunction(); + } + + @Bean + public Function uppercasePerson() { + System.out.println("==> CREATING 'uppercasePerson' FUNCTION bean"); + return person -> { + Person p = new Person(); + p.setId(person.getId()); + p.setName(person.getName().toUpperCase()); + return p; + }; + } + + + + public static class Person { + private String name; + + private int id; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + } +} diff --git a/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/UpperCaseFunction.java b/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/UpperCaseFunction.java new file mode 100644 index 000000000..859a54a58 --- /dev/null +++ b/spring-cloud-function-deployer-new/src/it/bootapp-with-scf/src/main/java/function/example/UpperCaseFunction.java @@ -0,0 +1,13 @@ +package function.example; + +import java.util.function.Function; + +public class UpperCaseFunction implements Function { + + @Override + public String apply(String value) { + System.out.println("Uppercasing " + value); + return value.toUpperCase(); + } + +} diff --git a/spring-cloud-function-deployer-new/src/test/java/org/springframework/cloud/function/deployer/FunctionDeployerTests.java b/spring-cloud-function-deployer-new/src/test/java/org/springframework/cloud/function/deployer/FunctionDeployerTests.java index 94f532ace..53f79d3ec 100644 --- a/spring-cloud-function-deployer-new/src/test/java/org/springframework/cloud/function/deployer/FunctionDeployerTests.java +++ b/spring-cloud-function-deployer-new/src/test/java/org/springframework/cloud/function/deployer/FunctionDeployerTests.java @@ -108,6 +108,27 @@ public class FunctionDeployerTests { assertThat(new String(result.getPayload(), StandardCharsets.UTF_8)).isEqualTo("\"BOB\""); } + /* + * Target function: + * + * @Bean public Function uppercase() + * + * this contains SCF on classpath + */ + @Test + public void testWithMainAndStartClassAndSpringConfigurationAndSCFOnClasspath() throws Exception { + String[] args = new String[] { + "--spring.cloud.function.location=target/it/bootapp-with-scf/target/bootapp-with-scf-0.0.1.BUILD-SNAPSHOT-exec.jar", + "--spring.cloud.function.function-name=uppercase" }; + ApplicationContext context = SpringApplication.run(FunctionDeployerConfiguration.class, args); + FunctionCatalog catalog = context.getBean(FunctionCatalog.class); + Function, Message> function = catalog.lookup("uppercase", "application/json"); + + Message result = function + .apply(MessageBuilder.withPayload("\"bob\"".getBytes(StandardCharsets.UTF_8)).build()); + assertThat(new String(result.getPayload(), StandardCharsets.UTF_8)).isEqualTo("\"BOB\""); + } + /* * Target function: *