From ecc19e4b817b7a17b92b29d3a0e5c758492498f9 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Mon, 30 May 2022 21:11:13 +0200 Subject: [PATCH] [KOGITO-7218] Adding integration test for gRPC --- .../pom.xml | 27 +++++++ .../workflows/services/GreeterService.java | 40 ++++++++++ .../src/main/resources/application.properties | 4 +- .../src/main/resources/greeting.proto | 22 ++++++ .../src/main/resources/rpcgreet.sw.json | 35 +++++++++ .../kogito/quarkus/workflows/RPCGreetIT.java | 75 +++++++++++++++++++ 6 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/java/org/kie/kogito/workflows/services/GreeterService.java create mode 100644 quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/greeting.proto create mode 100644 quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/rpcgreet.sw.json create mode 100644 quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/RPCGreetIT.java diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/pom.xml b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/pom.xml index 07bbc5ee783..d98d7dafefc 100644 --- a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/pom.xml +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/pom.xml @@ -149,6 +149,33 @@ + + org.xolstice.maven.plugins + protobuf-maven-plugin + + grpc-java + io.grpc:protoc-gen-grpc-java:${version.io.grpc}:exe:${os.detected.classifier} + ${project.build.directory}/generated-sources/grpc + + + quarkus-grpc-protoc-plugin + io.quarkus + quarkus-grpc-protoc-plugin + ${version.io.quarkus} + io.quarkus.grpc.protoc.plugin.MutinyGrpcGenerator + + + + + + generate-sources + + compile + compile-custom + + + + io.quarkus quarkus-maven-plugin diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/java/org/kie/kogito/workflows/services/GreeterService.java b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/java/org/kie/kogito/workflows/services/GreeterService.java new file mode 100644 index 00000000000..33aa2d49767 --- /dev/null +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/java/org/kie/kogito/workflows/services/GreeterService.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kie.kogito.workflows.services; + +import org.kie.kogito.examples.sw.greeting.Greeter; +import org.kie.kogito.examples.sw.greeting.Greeting.HelloReply; +import org.kie.kogito.examples.sw.greeting.Greeting.HelloRequest; + +import io.quarkus.grpc.GrpcService; +import io.smallrye.mutiny.Uni; + +@GrpcService +public class GreeterService implements Greeter { + @Override + public Uni sayHello(HelloRequest request) { + String message; + switch (request.getLanguage().toLowerCase()) { + case "spanish": + message = "Saludos desde gRPC service " + request.getName(); + break; + case "english": + default: + message = "Hello from gRPC service " + request.getName(); + } + return Uni.createFrom().item(() -> HelloReply.newBuilder().setMessage(message).build()); + } +} diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/application.properties b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/application.properties index 4c46cb12851..66f34024531 100644 --- a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/application.properties +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/application.properties @@ -66,4 +66,6 @@ mp.messaging.incoming.correlation_event_type.value.deserializer=org.apache.kafka mp.messaging.incoming.correlation_event_type.group.id=kogito-sw-it mp.messaging.incoming.correlation_event_type.auto.offset.reset=earliest -kogito.persistence.proto.marshaller=false \ No newline at end of file +kogito.persistence.proto.marshaller=false +quarkus.grpc.clients.Greeter.host=localhost + diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/greeting.proto b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/greeting.proto new file mode 100644 index 00000000000..1dcf95690f5 --- /dev/null +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/greeting.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +option java_package="org.kie.kogito.examples.sw.greeting"; + + + +// The greeter service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; + string language=2; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} \ No newline at end of file diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/rpcgreet.sw.json b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/rpcgreet.sw.json new file mode 100644 index 00000000000..2503919db5a --- /dev/null +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/rpcgreet.sw.json @@ -0,0 +1,35 @@ +{ + "id": "rpcgreet", + "version": "1.0", + "name": "Greeting workflow", + "description": "JSON based greeting workflow using grpc", + "start": "GreetPerson", + "functions": [ + { + "name": "sayHello", + "type": "rpc", + "operation": "greeting.proto#Greeter#SayHello" + } + ], + "states": [ + { + "name": "GreetPerson", + "type": "operation", + "actions": [ + { + "name": "sayHello", + "functionRef" : { + "refName": "sayHello", + "arguments": { + "name": ".name", + "language": ".language" + } + } + } + ], + "end": { + "terminate": "true" + } + } + ] +} \ No newline at end of file diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/RPCGreetIT.java b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/RPCGreetIT.java new file mode 100644 index 00000000000..5fa2e42ae7a --- /dev/null +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/RPCGreetIT.java @@ -0,0 +1,75 @@ +/* + * Copyright 2021 Red Hat, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kie.kogito.quarkus.workflows; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusIntegrationTest; +import io.restassured.http.ContentType; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.containsString; + +@QuarkusIntegrationTest +class RPCGreetRestIT { + @Test + void testEnglish() { + given() + .contentType(ContentType.JSON) + .accept(ContentType.JSON) + .body("{\"workflowdata\" : {\"name\" : \"John\", \"language\":\"English\"}}").when() + .post("/rpcgreet") + .then() + .statusCode(201) + .body("workflowdata.message", containsString("Hello")); + } + + @Test + void testSpanish() { + given() + .contentType(ContentType.JSON) + .accept(ContentType.JSON) + .body("{\"workflowdata\" : {\"name\" : \"Javierito\", \"language\":\"Spanish\"}}").when() + .post("/rpcgreet") + .then() + .statusCode(201) + .body("workflowdata.message", containsString("Saludos")); + } + + @Test + void testDefaultLanguage() { + given() + .contentType(ContentType.JSON) + .accept(ContentType.JSON) + .body("{\"workflowdata\" : {\"name\" : \"John\"}}").when() + .post("/rpcgreet") + .then() + .statusCode(201) + .body("workflowdata.message", containsString("Hello")); + } + + @Test + void testUnsupportedLanguage() { + given() + .contentType(ContentType.JSON) + .accept(ContentType.JSON) + .body("{\"workflowdata\" : {\"name\" : \"Jan\", \"language\":\"Czech\"}}").when() + .post("/rpcgreet") + .then() + .statusCode(201) + .body("workflowdata.message", containsString("Hello")); + } +}