Hi. I'm on version 4.3.5 of pact libraries and am...
# pact-jvm
r
Hi. I'm on version 4.3.5 of pact libraries and am trying to define the following pact in my consumer using the LambdaDsl (in a java+spring boot project)
Copy code
final DslPart body = newJsonBody(root -> {
            root.stringMatcher("callCount", "\\d+", "10");
            root.unorderedMinArray("distribution", 0, item -> item.object(o -> {
                o.stringMatcher("id", "\\d+", "1");
                o.stringMatcher("callCount", "\\d+", "10");
            }));
        }).build();
        
        return builder
            .usingLegacyMessageDsl()
            .given("non-empty-greeting-usage-statistics")
            .expectsToReceive("private.metrics.greeting.usage")
            .withContent(body)
            .toPact(V4Pact.class);
My intent is to state that this consumer accepts message content of the general shape { callCount: x, distribution: [] } where distribution array can be empty, and if not empty the items must match the general structure { id: x, callCount: y }. The pact generates and is loaded in the broker. However when in my provider I return payloads such as:
Copy code
"{\"callCount\":\"0\",\"distribution\":[]}";
It is failing with:
Copy code
1) private.metrics.greeting.usage: generates a message which has a matching body

    1.1) body: $.distribution Expected [{"callCount":"10","id":"1"}] to match [] ignoring order of elements

        [
        -  {
        -    "callCount": "10",
        -    "id": "1"
        -  }
        +
        ]
Any thoughts what I am missing? Maybe my expectation that in one pact I can define both scenarios were the array have items matching the example, or have no items is incorrect. Thoughts?
m
Yes, you need to test it with data and without data