我是Pact合同测试的新手。契约消费者测试似乎因以下错误而失败。
如果我将try / catch放在api调用周围,则它最初通过了,但是当我删除它时,我收到了有关HtmlMessageConverter的异常,因为响应提取程序无法提取响应,我将标头设置为(application / json&application / octate-stream) 。现在,在接受了该标头之后,我将遵循以下协定例外。
我在这里做错了什么?
Pact Test function failed with an exception, possibly due to Mismatches(mismatches=[PartialMismatch(mismatches=[BodyMismatch(expected=Map(OrderHeaderId -> ORD-001, ExternalOrderId -> 22194528), actual={"OrderHeaderId":"ORD-001","ExternalOrderId":"22194528"}, mismatch=Type mismatch: Expected Map Map(OrderHeaderId -> ORD-001, ExternalOrderId -> 22194528) but received String '{"OrderHeaderId":"ORD-001","ExternalOrderId":"22194528"}', path=$, diff=-{
- "OrderHeaderId": "ORD-001",
- "ExternalOrderId": "22194528"
-}
+"{\"OrderHeaderId\":\"ORD-001\",\"ExternalOrderId\":\"22194528\"}")])])
String inputJson =
"{\n" + " \"OrderHeaderId\":\"ORD-001\",\n" + " \"ExternalOrderId\": \"22194528\"\n" + "} ";
return builder
.given("order-created")
.uponReceiving("a request to create order")
.path(restOrderCreatePath)
.method("POST")
.headers(headers)
.body(inputJson)
.willRespondWith()
.status(200)
.body(jsonBody)
.toPact();
@Test
@PactVerification(fragment = "createOrderPactWithRibbon")
public void verifycreateOrderPactWithRibbon() throws Exception {
Document document = new Document();
document.put("OrderHeaderId","ORD-001");
document.put("ExternalOrderId","22194528");
// try {
ResponseEntity<RestApiResponse<Document>> response =
restApiService.processPostRequest(
document, restOrderComponentUrl, restOrderCreatePath);
Assert.assertTrue("No data received in response.", !(response == null));
/* } catch (Exception ignored) {
ignored.printStackTrace();
}*/
}