Reputation: 51
I am writing integration tests for my Java Service. We are thinking of using WireMock to mock upstream services. However, one of our upstream returns a Protobuf (grpc) response and I can't seem to understand how to mock a gRPC response using WireMock. I tried to convert the response to byteArray and use that ,however, wiremock fails to deserialize it to Protobuf Java Object.
We have a limitation that we can only use 1 mock server since all our upstream requests are forwarded via a servicemesh sidecar running on a fixed port.
Thanks!
Upvotes: 5
Views: 5239
Reputation: 4149
WireMock now has an official extension that supports gRPC mocking.
It works by converting protobuf messages to and from JSON so that WireMock's JSON matching can be used as normal.
Matching and responses can be expressed directly as JSON, or Java classes generated by protoc
can be used via the extension's DSL:
mockGreetingService.stubFor(
method("greeting")
.withRequestMessage(equalToMessage(HelloRequest.newBuilder().setName("Tom")))
.willReturn(message(HelloResponse.newBuilder().setGreeting("Hi"))));
Upvotes: 0
Reputation: 1530
You could use Wiremock-gRPC or any of the other tools mentioned on the Wikipedia comparison site such as the commercial tool Traffic Parrot that supports gRPC or Camouflage.
Upvotes: 4