<@UB7B75EE4> just a little more context for the re...
# pact-jvm
a
@rholshausen just a little more context for the reason why I am looking to switch to the Lamda DSL docs — it’s because as pointed out in the docs, the junit4 DSL seems to be buggy (I’m on version
4.2.20
). We’ve got 2 different similar requests like:
Copy code
DslPart requestOneResponseBodyDslPart = PactDslJsonArray
                .arrayEachLike()
                    .uuid("id", UUID.randomUUID())
                    .datetime("startTime", INSTANT_FORMAT_STRING)
                    // More keys here
                .closeObject();

DslPart requestTwoResponseBodyDslPart = PactDslJsonArray
                .arrayEachLike()
                    .uuid("id", UUID.randomUUID())
                    .datetime("scheduledStartTime", INSTANT_FORMAT_STRING)
                .closeObject();
Both of them generate random UUIDs and the default datetime string adhering to the format like:
"2000-02-01T00:00:00.000000Z"
in the pact JSON file. The problem is that `requestOneResponseBodyDslPart`’s provider verification is expecting exact value matches for both the
.uuid
and
.datetime
fields, which is really odd, considering we’ve used PactDslJsonArray before too.
r
Switching to lambda based DSL will not resolve your problems, as it all uses the same implementation. You need to work out the correct values to use in your tests.
a
Actually, I just spotted that the pact being generated for
requestOneResponseBodyDslPart
doesn’t include any
generators
and
matchingRules
for that request 🤔
Looking closer, at least one of our requests that works fine doesn’t have a generator for all the fields, despite all the fields in that request’s body being
.stringType
🤔
r
How are the DSL parts used (ie. ``requestOneResponseBodyDslPart``)
a
Like so:
Copy code
return builder
                .given("MY STATE")
                    .uponReceiving("a request to get all of a participant's recommendations")
                        .path(String.format("/api/participants/%s/recommendations", DEFAULT_PARTICIPANT_ID))
                        .method("GET")
                        .headers(REQUEST_HEADERS_WITH_AUTH)
                    .willRespondWith()
                        .status(200)
                        .headers(RESPONSE_HEADERS_FOR_VALIDATION)
                        .body(getRecommendationsPactDslJsonBody.toString())
.toPact();
r
Don't do this:
getRecommendationsPactDslJsonBody.toString()
, it converts it to pure JSON and you loose all the matchers and generators. Just remove the
toString()
call
a
Jeez, thanks heaps!
👍 1