合同测试不适用于具有两个不同合同的microService(messagePact和RequestResponsePact)

时间:2017-12-14 06:17:52

标签: java pact pact-jvm

我有两种不同的合约mS场景:

1st-直接mS-mS合同测试我正在使用RequestResponsePact来创建契约。

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

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

代码:

<div class=header>
  <a href="index.html">
    <img src="https://lh4.googleusercontent.com/-IqHfCyPGn00/AAAAAAAAAAI/AAAAAAAAAA8/WsxciIskxSo/photo.jpg?sz=328" alt="Logo.png" style="height:150px; width:150px; border-bottom: 0px;">
  </a>
</div>

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

//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
            }

0 个答案:

没有答案