Java GRPC Pact Testing - PactPluginMockServerErrorException

55 Views Asked by At

Hi guys I am trying to implement PACT in our tests, but I am having some problems. I am using Java 17 with Maven (Quarkus) and GRPC. When I try to run the test, I am getting this exception:

PactPluginMockServerErrorException: Plugin protobuf failed to start a mock server: Failed to start gRPC mock server: Pact file does not contain any Protobuf descriptors

This is my code:

@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "some-service", providerType = ProviderType.SYNCH_MESSAGE, pactVersion = PactSpecVersion.V4)
public class SomePactTest {
    
    @Pact(consumer = "other-service")
    V4Pact someTransactions(PactBuilder builder) {
        return builder
                .usingPlugin("protobuf")
                .expectsToReceive("submit request", "core/interaction/message")  // tried also synchronous-message
                .with(Map.of(
                        "pact:proto", filePath("target/schemas/proto/some-transaction.proto"),
                        "pact:content-type", "application/protobuf",  // tried also grpc
                        "pact:proto-service", "SomeTransactions/SubmitSomeTransactions",
                        "pact:message-type", "SubmitSomeTransactionsRequest",
                        "pact:protobuf-config", Map.of(  // tried without this
                                "additionalIncludes",
                                List.of(filePath("../type"))),
                        "request", Map.of(
                                "product", "PRODUCT_TEST",
                                "customer_id", "1234567890",
                                "transactions", Map.of(
                                        "type_code", "SOMETHING",
                                        "amount", "10.0",
                                        "metadata", Map.of(
                                                "key1", "value1",
                                                "key2", "value2"
                                        )
                                )
                        ),
                        "response", Map.of(
                                "main", Map.of(
                                        "balance", "100.0"
                                )
                        )
                ))
                .toPact();
    }
    
    @Test
    @PactTestFor(pactMethod = "someTransactions")
    @MockServerConfig(implementation = MockServerImplementation.Plugin, registryEntry = "protobuf/transport/grpc")
    void someTransaction(MockServer mockServer, V4Interaction.SynchronousMessages interaction) throws InvalidProtocolBufferException {
        ManagedChannel channel = ManagedChannelBuilder.forAddress("127.0.0.1", mockServer.getPort()).usePlaintext().build();
        SomeTransactionsGrpc.SubmitSomeTransactionsBlockingStub stub = newBlockingStub(channel);

        SubmitSomeTransactionsRequest request = SubmitSomeTransactionsRequest.newBuilder()
                .setProduct(ProductItem.PRODUCT_TEST)
                .setCustomerId(1234567890L)
                .addTransactions(TransactionItem.newBuilder()
                        .setTransactionTypeCode("SOMETHING")
                        .setAmount("10.0")
                        .putAllMetadata(Map.of(
                                "key1", "value1",
                                "key2", "value2"
                        ))
                        .build())
                .build();

        SomeTransactionsResponse response = stub.SubmitSomeTransactions(request);
        assertNotNull(response.getMain());
    }
}

Not really sure what it means, but I went through this Slack convo (https://docs.pact.io/slack/protobufs), and the proposed solution was to add 'pact:protobuf-config' since the proto file contains types based in another proto file. But without success.

If anyone could help, I cannot find much resources on this. Much appreciated.

0

There are 0 best solutions below