1

我有两种不同的合同 mS 方案:

1st- 直接 mS-mS 合同测试,我使用 RequestResponsePact 创建 Pact。

第二 - 在两个名为 Kafka 的微服务之间有一个 mq,我使用 MessagePact 创建 Pact。

不允许我对两个合同使用相同的 buildername。

代码:

//Contract 1
    @Rule
        public PactProviderRuleMk2  rule= new PactProviderRuleMk2("provider1", "localhost", 8080,PactSpecVersion.V3, this);

        @Pact(provider="provider1", consumer="consumer")
              public RequestResponsePact createPact(PactDslWithProvider builder) {

                 Map<String, String> headers = new HashMap<String, String>();
                 headers.put("Content-Type", "application/json");  

            return builder.given("/Any Given Statement/)
                .uponReceiving("/Any Receiving Statement/")
                    .path("/path/")
                    .method("GET")

                .willRespondWith()
                    .headers(headers)
                    .status(200)
                    .body(/body/)
                .toPact();
                }

         @Test
            @PactVerification({"provider1", "createPact"})
            public void runTest(){
            //Asser test for StatusCode

            }

//Contract 2
     @Rule
        public MessagePactProviderRule messageProviderProcessOrder = new MessagePactProviderRule("provider2",PactSpecVersion.V3);

        @Pact(provider = "provider2", consumer = "consumer") //SameConsumer
            public MessagePact msgresponse(MessagePactBuilder builder) throws ClassNotFoundException, JsonProcessingException, SQLException, InterruptedException {

                    Map<String, String> metadata = new HashMap<String, String>();
                    metadata.put("contentType", "application/json");

                    return builder.given(/Any Given Statement/)

                            .expectsToReceive("/Any Receiving Statement/")
                                .withMetadata(metadata)
                                .withConten(//body/)
                            .toPact();   
        }
         @Test
            @PactVerification({"provider2", "msgresponse"})
            public void test() throws Exception {
            //Asser test for StatusCode
            }

注意:当我单独运行这两个合约时,它会生成 Success 和 Pact 文件。当我同时运行它们时,抛出了以下错误消息:

Error:

Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 11.328 sec <<< FAILURE! - in com.att.udas.xxx.yyy.pact.PactTestSuit
test on test(com.att.udas.xxx.yyy.pact.ConsumerMessagePact)(com.att.udas.xxx.yyy.pact.ConsumerMessagePact)  Time elapsed: 1.228 sec  <<< FAILURE!
java.lang.UnsupportedOperationException: Method msgresponse does not conform required method signature 'public RequestResponsePact xxx(PactDslWithProvider builder)'

runTest on runTest(com.att.udas.manage.account.pact.ConsumerMessagePact)(com.att.udas.manage.account.pact.ConsumerMessagePact)  Time elapsed: 0.005 sec  <<< FAILURE!
java.lang.UnsupportedOperationException: Method msgresponse does not conform required method signature 'public RequestResponsePact xxx(PactDslWithProvider builder)'
4

0 回答 0