-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KOGITO-7218] Adding integration test for gRPC
- Loading branch information
Showing
6 changed files
with
202 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...flow-integration-test/src/main/java/org/kie/kogito/workflows/services/GreeterService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ion/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/greeting.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
35 changes: 35 additions & 0 deletions
35
...n/kogito-quarkus-serverless-workflow-integration-test/src/main/resources/rpcgreet.sw.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} |
75 changes: 75 additions & 0 deletions
75
...-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/RPCGreetIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |