I have a request class which has this fields:
private final String pk;
private final String sk;
private final List<String> tags;
private final ZoneId timeZone;
private final String pattern;
private final SomeEnum action;
private final String target;
private final String data;
private final Map<String, String> additionalInfo;
The request can be dynamic, so I am creating a DslPart for this:
DslPart body = new PactDslJsonBody()
.stringType("pk")
.stringType("sk")
.stringType("pattern")
.stringType("target")
.stringType("template")
.object("action").closeObject()
.object("timeZone").closeObject()
.object("metadata").stringType("detail-type").closeObject();
And using it here while creating contract:
pactHelper.contract(pact ->
pact.uponReceiving("Create scheduler rule")
.method("POST")
.path("/rule")
.body(body)
.willRespondWith()
.body("OK")
.status(HttpStatusCode.OK).toPact())
This result in 500: Unexpected Request error
It's hard to see why this would fail, because we can't see your test case.
A 500
from the mock server indicates it got a request it wasn't expecting.
Set the log level to DEBUG to see what the pact server thinks it saw, it should print out the expected and actual request. If you're using JUnit, it should also have already produced a report in the usual folder that will tell you why it failed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.