Skip to content

Commit

Permalink
Merge pull request #8 from wiremock/imported-proto-fix
Browse files Browse the repository at this point in the history
imported proto fix
  • Loading branch information
tomakehurst authored Oct 11, 2023
2 parents d184af3 + 3606b1f commit 996a875
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ publishing {
}
}

test {
testLogging {
events "PASSED", "FAILED", "SKIPPED"
exceptionFormat "full"
}
}

project.tasks.signMainPublication.dependsOn jar

assemble.dependsOn clean, jar
Expand Down Expand Up @@ -192,6 +199,7 @@ protobuf {
all().each { task ->
task.generateDescriptorSet = true
task.descriptorSetOptions.path = "$projectDir/src/test/resources/wiremock/grpc/services.dsc"
task.descriptorSetOptions.includeImports = true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void decorateMockServiceContextBeforeConfig(
Exceptions.uncheck(
() ->
Descriptors.FileDescriptor.buildFrom(
fileDescriptorProto, new Descriptors.FileDescriptor[0]),
fileDescriptorProto, new Descriptors.FileDescriptor[0], true),
Descriptors.FileDescriptor.class))
.collect(Collectors.toUnmodifiableList());

Expand Down
24 changes: 14 additions & 10 deletions src/test/java/org/wiremock/grpc/GrpcAcceptanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.example.grpc.HelloResponse;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import com.google.protobuf.Empty;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;
Expand All @@ -48,10 +49,9 @@ public class GrpcAcceptanceTest {
WireMockExtension.newInstance()
.options(
wireMockConfig()
.dynamicPort()
.withRootDirectory("src/test/resources/wiremock")
.extensions(new GrpcExtensionFactory())
)
.dynamicPort()
.withRootDirectory("src/test/resources/wiremock")
.extensions(new GrpcExtensionFactory()))
.build();

@BeforeEach
Expand Down Expand Up @@ -89,10 +89,7 @@ void shouldReturnGreetingBuiltViaTemplatedJson() {
mockGreetingService.stubFor(
method("greeting")
.willReturn(
jsonTemplate(
"{\n"
+ " \"greeting\": \"Hello {{jsonPath request.body '$.name'}}\"\n"
+ "}")));
jsonTemplate("{ \"greeting\": \"Hello {{jsonPath request.body '$.name'}}\" }")));

String greeting = greetingsClient.greet("Tom");

Expand All @@ -102,8 +99,7 @@ void shouldReturnGreetingBuiltViaTemplatedJson() {
@Test
void returnsResponseBuiltFromJson() {
mockGreetingService.stubFor(
method("greeting")
.willReturn(json("{\n" + " \"greeting\": \"Hi Tom from JSON\"\n" + "}")));
method("greeting").willReturn(json("{ \"greeting\": \"Hi Tom from JSON\" }")));

String greeting = greetingsClient.greet("Whatever");

Expand Down Expand Up @@ -207,4 +203,12 @@ void returnsStreamedResponseToUnaryRequest() {

assertThat(greetingsClient.oneGreetingManyReplies("Tom"), hasItem("Hi Tom"));
}

@Test
void returnsResponseWithImportedType() {
mockGreetingService.stubFor(
method("oneGreetingEmptyReply").willReturn(message(Empty.newBuilder())));

assertThat(greetingsClient.oneGreetingEmptyReply("Tom"), is(true));
}
}
7 changes: 7 additions & 0 deletions src/test/java/org/wiremock/grpc/client/GreetingsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.example.grpc.HelloRequest;
import com.example.grpc.HelloResponse;
import com.github.tomakehurst.wiremock.common.Exceptions;
import com.google.protobuf.Empty;
import io.grpc.Channel;
import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
Expand Down Expand Up @@ -106,4 +107,10 @@ public void onCompleted() {

return responseHolder.get().getGreeting();
}

public boolean oneGreetingEmptyReply(String name) {
final Empty response =
stub.oneGreetingEmptyReply(HelloRequest.newBuilder().setName(name).build());
return response != null;
}
}
3 changes: 3 additions & 0 deletions src/test/proto/ExampleServices.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package com.example.grpc;

option java_multiple_files = true;

import "google/protobuf/empty.proto";

enum Sentiment {
HAPPY = 0;
SLEEPY = 1;
Expand All @@ -44,4 +46,5 @@ service GreetingService {
rpc greeting(HelloRequest) returns (HelloResponse);
rpc manyGreetingsOneReply(stream HelloRequest) returns (HelloResponse);
rpc oneGreetingManyReplies(HelloRequest) returns (stream HelloResponse);
rpc oneGreetingEmptyReply(HelloRequest) returns (google.protobuf.Empty);
}
Binary file modified src/test/resources/wiremock/grpc/services.dsc
Binary file not shown.

0 comments on commit 996a875

Please sign in to comment.