From d834cea31ef38d5feddfecd5b561dce6870a73e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 19 Oct 2021 16:12:08 +0200 Subject: [PATCH 1/3] Add a codestart test for the Google Cloud Function codestart --- .../GoogleCloudFunctionsCodestartTest.java | 29 +++++++++++++++++++ ...unctions_HelloWorldBackgroundFunction.java | 19 ++++++++++++ ...cloudfunctions_HelloWorldHttpFunction.java | 19 ++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/GoogleCloudFunctionsCodestartTest.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_HelloWorldBackgroundFunction.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_HelloWorldHttpFunction.java diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/GoogleCloudFunctionsCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/GoogleCloudFunctionsCodestartTest.java new file mode 100644 index 0000000000000..ebd96556538d6 --- /dev/null +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/GoogleCloudFunctionsCodestartTest.java @@ -0,0 +1,29 @@ +package io.quarkus.devtools.codestarts.quarkus; + +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; + +public class GoogleCloudFunctionsCodestartTest { + @RegisterExtension + public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .codestarts("google-cloud-functions") + .languages(JAVA) + .build(); + + @Test + void testContent() throws Throwable { + codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.HelloWorldBackgroundFunction"); + codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.HelloWorldHttpFunction"); + } + + @Test + @EnabledIfSystemProperty(named = "build-projects", matches = "true") + void buildAllProjectsForLocalUse() throws Throwable { + codestartTest.buildAllProjects(); + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_HelloWorldBackgroundFunction.java b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_HelloWorldBackgroundFunction.java new file mode 100644 index 0000000000000..85f58424c8f2f --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_HelloWorldBackgroundFunction.java @@ -0,0 +1,19 @@ +package ilove.quark.us.googlecloudfunctions; + +import javax.enterprise.context.ApplicationScoped; + +import com.google.cloud.functions.BackgroundFunction; +import com.google.cloud.functions.Context; + +@ApplicationScoped +public class HelloWorldBackgroundFunction implements BackgroundFunction { + + @Override + public void accept(StorageEvent event, Context context) throws Exception { + System.out.println("Receive event on file: " + event.name); + } + + public static class StorageEvent { + public String name; + } +} \ No newline at end of file diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_HelloWorldHttpFunction.java b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_HelloWorldHttpFunction.java new file mode 100644 index 0000000000000..c03a2b50b7603 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_HelloWorldHttpFunction.java @@ -0,0 +1,19 @@ +package ilove.quark.us.googlecloudfunctions; + +import java.io.Writer; + +import javax.enterprise.context.ApplicationScoped; + +import com.google.cloud.functions.HttpFunction; +import com.google.cloud.functions.HttpRequest; +import com.google.cloud.functions.HttpResponse; + +@ApplicationScoped +public class HelloWorldHttpFunction implements HttpFunction { + + @Override + public void service(HttpRequest httpRequest, HttpResponse httpResponse) throws Exception { + Writer writer = httpResponse.getWriter(); + writer.write("Hello World"); + } +} \ No newline at end of file From bc7256d7946de98bf972982da9902879f7678b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 19 Oct 2021 16:21:26 +0200 Subject: [PATCH 2/3] Add a codestart test for Google Cloud Functions HTTP codestart --- ...GoogleCloudFunctionsHttpCodestartTest.java | 31 ++++++++++++ ...us_googlecloudfunctions_GreetingFunqy.java | 17 +++++++ ...googlecloudfunctions_GreetingResource.java | 49 +++++++++++++++++++ ...s_googlecloudfunctions_GreetingRoutes.java | 20 ++++++++ ..._googlecloudfunctions_GreetingServlet.java | 27 ++++++++++ 5 files changed, 144 insertions(+) create mode 100644 integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/GoogleCloudFunctionsHttpCodestartTest.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingFunqy.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingResource.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingRoutes.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingServlet.java diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/GoogleCloudFunctionsHttpCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/GoogleCloudFunctionsHttpCodestartTest.java new file mode 100644 index 0000000000000..7d9f5deb40b4e --- /dev/null +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/GoogleCloudFunctionsHttpCodestartTest.java @@ -0,0 +1,31 @@ +package io.quarkus.devtools.codestarts.quarkus; + +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; + +public class GoogleCloudFunctionsHttpCodestartTest { + @RegisterExtension + public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .codestarts("google-cloud-functions-http") + .languages(JAVA) + .build(); + + @Test + void testContent() throws Throwable { + codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.GreetingFunqy"); + codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.GreetingResource"); + codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.GreetingRoutes"); + codestartTest.checkGeneratedSource("org.acme.googlecloudfunctions.GreetingServlet"); + } + + @Test + @EnabledIfSystemProperty(named = "build-projects", matches = "true") + void buildAllProjectsForLocalUse() throws Throwable { + codestartTest.buildAllProjects(); + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingFunqy.java b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingFunqy.java new file mode 100644 index 0000000000000..7be609bbc3649 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingFunqy.java @@ -0,0 +1,17 @@ +package ilove.quark.us.googlecloudfunctionshttp; + +import io.quarkus.funqy.Funq; +import io.smallrye.mutiny.Uni; + +public class GreetingFunqy { + + @Funq + public String funqy() { + return "Make it funqy"; + } + + @Funq + public Uni funqyAsync() { + return Uni.createFrom().item(() -> "Make it funqy asynchronously"); + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingResource.java b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingResource.java new file mode 100644 index 0000000000000..8c8ceaa674cba --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingResource.java @@ -0,0 +1,49 @@ +package ilove.quark.us.googlecloudfunctionshttp; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/hello") +public class GreetingResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } + + @POST + @Produces(MediaType.TEXT_PLAIN) + @Consumes(MediaType.TEXT_PLAIN) + public String hello(String name) { + return "hello " + name; + } + + @POST + @Produces(MediaType.APPLICATION_OCTET_STREAM) + @Consumes(MediaType.APPLICATION_OCTET_STREAM) + public byte[] hello(byte[] bytes) { + if (bytes[0] != 0 || bytes[1] != 1 || bytes[2] != 2 || bytes[3] != 3) { + throw new RuntimeException("bad input"); + } + byte[] rtn = { 4, 5, 6 }; + return rtn; + } + + @POST + @Path("empty") + public void empty() { + + } + + @GET + @Path("error") + public void error() { + throw new RuntimeException("Oups!"); + } + +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingRoutes.java b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingRoutes.java new file mode 100644 index 0000000000000..ecb260a6f96f4 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingRoutes.java @@ -0,0 +1,20 @@ +package ilove.quark.us.googlecloudfunctionshttp; + +import static io.quarkus.vertx.web.Route.HttpMethod.GET; + +import io.quarkus.vertx.web.Route; +import io.vertx.ext.web.RoutingContext; + +public class GreetingRoutes { + @Route(path = "/vertx/hello", methods = GET) + void hello(RoutingContext context) { + context.response().headers().set("Content-Type", "text/plain"); + context.response().setStatusCode(200).end("hello"); + } + + @Route(path = "/vertx/error", methods = GET) + void error(RoutingContext context) { + context.response().headers().set("Content-Type", "text/plain"); + context.response().setStatusCode(500).end("Oups!"); + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingServlet.java b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingServlet.java new file mode 100644 index 0000000000000..03abceccb3b90 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/GoogleCloudFunctionsHttpCodestartTest/testContent/src_main_java_ilove_quark_us_googlecloudfunctions_GreetingServlet.java @@ -0,0 +1,27 @@ +package ilove.quark.us.googlecloudfunctionshttp; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet(name = "ServletGreeting", urlPatterns = "/servlet/hello") +public class GreetingServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setStatus(200); + resp.addHeader("Content-Type", "text/plain"); + resp.getWriter().write("hello"); + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String name = req.getReader().readLine(); + resp.setStatus(200); + resp.addHeader("Content-Type", "text/plain"); + resp.getWriter().write("hello " + name); + } +} From 69944e937a556098f848cddc832b147668bd37aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 19 Oct 2021 16:25:36 +0200 Subject: [PATCH 3/3] Add a codestart test for Funqy Google Cloud Function --- ...unqyGoogleCloudFunctionsCodestartTest.java | 29 +++++++++++++++++++ ...ooglecloudfunctions_GreetingFunctions.java | 26 +++++++++++++++++ ...ygooglecloudfunctions_GreetingService.java | 21 ++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/FunqyGoogleCloudFunctionsCodestartTest.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/FunqyGoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_funqygooglecloudfunctions_GreetingFunctions.java create mode 100644 integration-tests/devtools/src/test/resources/__snapshots__/FunqyGoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_funqygooglecloudfunctions_GreetingService.java diff --git a/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/FunqyGoogleCloudFunctionsCodestartTest.java b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/FunqyGoogleCloudFunctionsCodestartTest.java new file mode 100644 index 0000000000000..aa0b1a2b58a51 --- /dev/null +++ b/integration-tests/devtools/src/test/java/io/quarkus/devtools/codestarts/quarkus/FunqyGoogleCloudFunctionsCodestartTest.java @@ -0,0 +1,29 @@ +package io.quarkus.devtools.codestarts.quarkus; + +import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; + +public class FunqyGoogleCloudFunctionsCodestartTest { + @RegisterExtension + public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() + .codestarts("funqy-google-cloud-functions") + .languages(JAVA) + .build(); + + @Test + void testContent() throws Throwable { + codestartTest.checkGeneratedSource("org.acme.funqygooglecloudfunctions.GreetingFunctions"); + codestartTest.checkGeneratedSource("org.acme.funqygooglecloudfunctions.GreetingService"); + } + + @Test + @EnabledIfSystemProperty(named = "build-projects", matches = "true") + void buildAllProjectsForLocalUse() throws Throwable { + codestartTest.buildAllProjects(); + } +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/FunqyGoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_funqygooglecloudfunctions_GreetingFunctions.java b/integration-tests/devtools/src/test/resources/__snapshots__/FunqyGoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_funqygooglecloudfunctions_GreetingFunctions.java new file mode 100644 index 0000000000000..fa3de58c328fe --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/FunqyGoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_funqygooglecloudfunctions_GreetingFunctions.java @@ -0,0 +1,26 @@ +package ilove.quark.us.funqygooglecloudfunctions; + +import javax.inject.Inject; + +import io.quarkus.funqy.Funq; +import io.quarkus.funqy.gcp.functions.event.PubsubMessage; +import io.quarkus.funqy.gcp.functions.event.StorageEvent; + +public class GreetingFunctions { + + @Inject + GreetingService service; + + @Funq + public void helloPubSubWorld(PubsubMessage pubSubEvent) { + String message = service.hello("world"); + System.out.println(pubSubEvent.messageId + " - " + message); + } + + @Funq + public void helloGCSWorld(StorageEvent storageEvent) { + String message = service.hello("world"); + System.out.println(storageEvent.name + " - " + message); + } + +} diff --git a/integration-tests/devtools/src/test/resources/__snapshots__/FunqyGoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_funqygooglecloudfunctions_GreetingService.java b/integration-tests/devtools/src/test/resources/__snapshots__/FunqyGoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_funqygooglecloudfunctions_GreetingService.java new file mode 100644 index 0000000000000..282f37dba7833 --- /dev/null +++ b/integration-tests/devtools/src/test/resources/__snapshots__/FunqyGoogleCloudFunctionsCodestartTest/testContent/src_main_java_ilove_quark_us_funqygooglecloudfunctions_GreetingService.java @@ -0,0 +1,21 @@ +package ilove.quark.us.funqygooglecloudfunctions; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class GreetingService { + private String greeting = "Hello"; + private String punctuation = "!"; + + public void setGreeting(String greet) { + greeting = greet; + } + + public void setPunctuation(String punctuation) { + this.punctuation = punctuation; + } + + public String hello(String val) { + return greeting + " " + val + punctuation; + } +}