Skip to content

Commit

Permalink
feat(grpc): added test profiles to grpc transcoding and fixed depende…
Browse files Browse the repository at this point in the history
…ncies
  • Loading branch information
zZHorizonZz committed Apr 29, 2024
1 parent 94c0bc3 commit 5c74729
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion extensions/grpc/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.24.3</version>
<version>${protobuf-java.version}</version>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
quarkus.grpc.server.port=9001
quarkus.grpc.server.instances=2
quarkus.grpc.server.use-separate-server=false
quarkus.grpc.transcoding.enabled=true

%vertx.quarkus.grpc.server.use-separate-server=false
%n2o.quarkus.grpc.server.use-separate-server=true
%o2n.quarkus.grpc.server.use-separate-server=false
quarkus.grpc.server.port=9001

quarkus.grpc.clients.hello.host=localhost
quarkus.grpc.clients.hello.port=9001

%vertx.quarkus.grpc.clients.hello.port=8081
%vertx.quarkus.grpc.clients.hello.use-quarkus-grpc-client=true

%n2o.quarkus.grpc.clients.hello.port=9001
%n2o.quarkus.grpc.clients.hello.use-quarkus-grpc-client=true

%o2n.quarkus.grpc.clients.hello.port=8081
%o2n.quarkus.grpc.clients.hello.use-quarkus-grpc-client=false
%vertx.quarkus.grpc.server.use-separate-server=false
Original file line number Diff line number Diff line change
@@ -1,47 +1,7 @@
package io.quarkus.grpc.examples.hello;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;

import examples.HelloRequest;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;

@QuarkusTest
public class HelloWorldTranscodingEndpointTest {

@Test
public void testSimplePath() {
given()
.body(getJsonRequest("simple-test"))
.contentType(ContentType.JSON)
.when().post("/v2/simple")
.then()
.statusCode(200)
.body("message", is("Hello from Simple Path, simple-test!"));
}

@Test
public void testComplexPath() {
given()
.contentType(ContentType.JSON)
.when().post("/v2/complex/complex-test/path")
.then()
.statusCode(200)
.body("message", is("Hello from Complex Path, complex-test!"));
}

private String getJsonRequest(String name) {
try {
return JsonFormat.printer().omittingInsignificantWhitespace()
.print(HelloRequest.newBuilder().setName(name).build());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
}
public class HelloWorldTranscodingEndpointTest extends HelloWorldTranscodingEndpointTestBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkus.grpc.examples.hello;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;

import examples.HelloRequest;
import io.restassured.http.ContentType;

class HelloWorldTranscodingEndpointTestBase {

@Test
public void testSimplePath() {
given()
.body(getJsonRequest("simple-test"))
.contentType(ContentType.JSON)
.when().post("/v2/simple")
.then()
.statusCode(200)
.body("message", is("Hello from Simple Path, simple-test!"));
}

@Test
public void testComplexPath() {
given()
.contentType(ContentType.JSON)
.when().post("/v2/complex/complex-test/path")
.then()
.statusCode(200)
.body("message", is("Hello from Complex Path, complex-test!"));
}

private String getJsonRequest(String name) {
try {
return JsonFormat.printer().omittingInsignificantWhitespace()
.print(HelloRequest.newBuilder().setName(name).build());
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void testInvalidMethod() {
.contentType(ContentType.JSON)
.when().post("/v1/resources/resource-type-1/resource/1234")
.then()
.statusCode(405);
.statusCode(404);
}

@Test
Expand All @@ -115,7 +115,7 @@ public void testInvalidContentType() {
.contentType(ContentType.TEXT)
.when().post("/v1/simple")
.then()
.statusCode(415);
.statusCode(404);
}

private String getJsonRequest(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkus.grpc.examples.hello;

import io.quarkus.grpc.test.utils.VertxGRPCTestProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(VertxGRPCTestProfile.class)
public class VertxHelloWorldTranscodingEndpointTest extends HelloWorldTranscodingEndpointTestBase {
}

0 comments on commit 5c74729

Please sign in to comment.