@Pact(provider =“Appointment_Provider”,consumer =“Appointment_Consumer”) public PactFragment createFragmentAppointmentDetails(PactDslWithProvider builder)抛出ParseException {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
return builder
.given("GetAppoinment")
.uponReceiving("Get Appointment information")
.path("/getappointment")
.query("apptId=11207")
.method("GET")
.willRespondWith()
.headers(headers)
.status(200)
.body(new PactDslJsonBody()
.object("appointments")
.stringValue("type","Test \\u0026 Turn up")
.stringValue("apptId","11207")
.closeObject()
)
.toFragment()
;
}
答案 0 :(得分:1)
new PactDslJsonBody()
结束closeObject()
(因此在您打开其中的另一个对象时最终会有2个),因为JsonBody会自己创建一个对象。它应该是这样的:
builder
.given("GetAppoinment")
.uponReceiving("Get Appointment information")
.path("/getappointment")
.query("apptId=11207")
.method("GET")
.willRespondWith()
.headers(headers)
.status(200)
.body(
new PactDslJsonBody() // This opens a root object
.object("appointments") // creates a new object with in the root one
.stringValue("type","Test \\u0026 Turn up")
.stringValue("apptId","11207")
.closeObject() // closes the child object
.closeObject() // closes the root object
)
.toFragment();