Skip to content

Commit

Permalink
[KOGITO-7218] Adding integration test for gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed May 30, 2022
1 parent a939408 commit ecc19e4
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,33 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<configuration>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${version.io.grpc}:exe:${os.detected.classifier}</pluginArtifact>
<outputDirectory>${project.build.directory}/generated-sources/grpc</outputDirectory>
<protocPlugins>
<protocPlugin>
<id>quarkus-grpc-protoc-plugin</id>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-protoc-plugin</artifactId>
<version>${version.io.quarkus}</version>
<mainClass>io.quarkus.grpc.protoc.plugin.MutinyGrpcGenerator</mainClass>
</protocPlugin>
</protocPlugins>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<HelloReply> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
kogito.persistence.proto.marshaller=false
quarkus.grpc.clients.Greeter.host=localhost

Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit ecc19e4

Please sign in to comment.