diff --git a/fn-ci-cd-deployment-pipeline/hello-java/func.yaml b/fn-ci-cd-deployment-pipeline/hello-java/func.yaml new file mode 100644 index 0000000..a61250d --- /dev/null +++ b/fn-ci-cd-deployment-pipeline/hello-java/func.yaml @@ -0,0 +1,7 @@ +schema_version: 20180708 +name: hello-java +version: 0.0.1 +runtime: java +build_image: fnproject/fn-java-fdk-build:jdk17-1.0.192 +run_image: fnproject/fn-java-fdk:jre17-1.0.192 +cmd: com.example.fn.HelloFunction::handleRequest diff --git a/fn-ci-cd-deployment-pipeline/hello-java/pom.xml b/fn-ci-cd-deployment-pipeline/hello-java/pom.xml new file mode 100644 index 0000000..4652938 --- /dev/null +++ b/fn-ci-cd-deployment-pipeline/hello-java/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + UTF-8 + 1.0.192 + + com.example.fn + hello + 1.0.0 + + + + com.fnproject.fn + api + ${fdk.version} + + + com.fnproject.fn + testing-core + ${fdk.version} + test + + + com.fnproject.fn + testing-junit4 + ${fdk.version} + test + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 17 + 17 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + + false + + + + + diff --git a/fn-ci-cd-deployment-pipeline/hello-java/src/main/java/com/example/fn/HelloFunction.java b/fn-ci-cd-deployment-pipeline/hello-java/src/main/java/com/example/fn/HelloFunction.java new file mode 100644 index 0000000..7b2e6a8 --- /dev/null +++ b/fn-ci-cd-deployment-pipeline/hello-java/src/main/java/com/example/fn/HelloFunction.java @@ -0,0 +1,12 @@ +package com.example.fn; + +public class HelloFunction { + + public String handleRequest(String input) { + String name = (input == null || input.isEmpty()) ? "world" : input; + + System.out.println("Inside Java Hello World function"); + return "Hello, " + name + "!"; + } + +} \ No newline at end of file diff --git a/fn-ci-cd-deployment-pipeline/hello-java/src/test/java/com/example/fn/HelloFunctionTest.java b/fn-ci-cd-deployment-pipeline/hello-java/src/test/java/com/example/fn/HelloFunctionTest.java new file mode 100644 index 0000000..e6b7a5e --- /dev/null +++ b/fn-ci-cd-deployment-pipeline/hello-java/src/test/java/com/example/fn/HelloFunctionTest.java @@ -0,0 +1,22 @@ +package com.example.fn; + +import com.fnproject.fn.testing.*; +import org.junit.*; + +import static org.junit.Assert.*; + +public class HelloFunctionTest { + + @Rule + public final FnTestingRule testing = FnTestingRule.createDefault(); + + @Test + public void shouldReturnGreeting() { + testing.givenEvent().enqueue(); + testing.thenRun(HelloFunction.class, "handleRequest"); + + FnResult result = testing.getOnlyResult(); + assertEquals("Hello, world!", result.getBodyAsString()); + } + +} \ No newline at end of file