[英]Pact Test function failed with an exception, possibly due to Mismatches
I am new to Pact contract testing. 我是Pact合同测试的新手。 It seems like pact consumer test is failing with following error.
契约消费者测试似乎失败,并出现以下错误。
Initially it passed if I put try/catch around api call but when I removed it , I received exception regarding HtmlMessageConverter as response extractor couldn't extract response, I set header as (application/json & application/octate-stream). 最初,如果我将try / catch放在api调用周围,则它通过了,但是当我删除它时,我收到了有关HtmlMessageConverter的异常,因为响应提取程序无法提取响应,因此将标头设置为(application / json&application / octate-stream)。 Now after accepting that header I am getting following pact exception.
现在,在接受该标头之后,我得到了以下协定例外。
What I am doing wrong here? 我在这里做错了什么?
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();
}*/
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.