消费者使用pact期望List <String>的响应

时间:2019-06-28 14:34:19

标签: java junit pact

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

  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>

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

1 个答案:

答案 0 :(得分:0)

您可以尝试以下操作:

PactDslJsonArray.arrayEachLike(PactDslJsonRootValue.stringType("some example string"))