消费者对List 使用pact的期望响应

问题描述 投票:0回答:1

我正在建立这样的契约消费者合同

  private RequestResponsePact createConsumerContract(final PactDslWithProvider pactDslWithProvider,
      final String path,
      final String query,
      final String state,
      final String description,
      final HttpStatus status,
      final DslPart expectedResponseBody,
      final String mediaType) {

    final Map<String, String> responseHeaders = new HashMap<>();
    responseHeaders.put("Content-Type", mediaType);

    return pactDslWithProvider.given(state)
        .uponReceiving(description)
        .path(path)
        .query(query)
        .method("GET")
        .headers("Accept", mediaType)
        .willRespondWith()
        .status(status.value())
        .headers(responseHeaders)
        .body(new PactDslJsonBody().eachArrayLike())
        .toPact();
  }

并且消费者期望响应为List<String>

我如何在契约消费者合同中指定响应主体。

java junit pact
1个回答
0
投票

您可以尝试使用此方法:

PactDslJsonArray.arrayEachLike(PactDslJsonRootValue.stringType("some example string"))
© www.soinside.com 2019 - 2024. All rights reserved.