Pact-jvm: [pact-jvm-consumer-junit] Provide a way to shuffle generated values only once

Created on 31 Jul 2017  路  5Comments  路  Source: pact-foundation/pact-jvm

Hi there,

in my Pact, I am using (among others) "id" of type integer in the request body.

final DslPart body = new PactDslJsonBody()
  .integerType("id")

When doing my requests against the "Pact-server", "id" is shuffled on each request. In my test, I am having some subsequent HTTP-calls to my Pact-endpoint, where I expect the result to be constant (for that test).
Is there a way to not shuffle "id" on each request?

question

Most helpful comment

In my case, it a little bit more complex. Let's say, I am expecting

[{"id":1}{"id":2}]

So, if I set "id" to "1000", both ids will have fixed value "1000", but I need different ones (which should stay constant between HTTP requests to the "Pact-server").

All 5 comments

The shuffle you refer to is due to you not providing an example value, so a random one is generated each time. You can provide an actual value to use as the second parameter.

final DslPart body = new PactDslJsonBody()
  .integerType("id", 1000)

In my case, it a little bit more complex. Let's say, I am expecting

[{"id":1}{"id":2}]

So, if I set "id" to "1000", both ids will have fixed value "1000", but I need different ones (which should stay constant between HTTP requests to the "Pact-server").

Pact doesn't have any mechanism for keeping things constant between different requests, as this is starting to stray into behavioural testing space. Each request is validated in isolation.

We could look at using a sequence generator for IDs, but subsequent requests will get different IDs.

Now that I think of it, by resetting the sequence for each request, you should then always get the same sequence of IDs

Hmm, in my opinion, within the same JUnit-test, I would expect the Pact-server to answer the same response - just as I would expect it from another service.

Was this page helpful?
0 / 5 - 0 ratings