JVM minArrayLike matching rules

223 views
Skip to first unread message

Andrew Fitzgerald

unread,
Jun 17, 2016, 6:30:49 AM6/17/16
to Pact
I'm just getting started with pact and am running into issues with array matchers.

I have the following pact fragment, and it generates
@Pact(consumer = "idm-client")
public PactFragment getUsersFragment(PactDslWithProvider builder) {
    return builder
            .given("a user with an id named 'user' exists")
            .uponReceiving("get all users")
            .path("idm/user")
            .method("GET")
            .willRespondWith()
            .status(200)
            .body(new PactDslJsonArray()
                    .minArrayLike(1)
                    .uuid("id")
                    .stringType("username")
                    .stringType("email")
                    .closeObject())
            .toFragment();
}

and it generates a pact file like this
    "interactions": [
        {
            "providerState": "a user with an id named 'user' exists",
            "description": "get all users",
            "request": {
                "method": "GET",
                "path": "idm/user",
                "body": null
            },
            "response": {
                "status": 200,
                "headers": {
                    "Content-Type": "application/json; charset=UTF-8"
                },
                "body": [
                    {
                        "email": "dnpVDMuTXwIduMLiOTKg",
                        "id": "946e570b-386d-4a22-b5cc-a0b429f063aa",
                        "username": "vhICeWvqPNYeZErsIWkZ"
                    }
                ],
                "matchingRules": {
                    "$.body[*].username": {
                        "match": "type"
                    },
                    "$.body[*].email": {
                        "match": "type"
                    },
                    "$.body[*].id": {
                        "regex": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
                    }
                }
            }
        }
    ],Enter code here...


I would expect something in the matching rules to specify the minimum array size, but that doesn't seem to be the case.
Changing it to minArrayLike(5) doesn't change the pact file, nor does changing it to maxArrayLike(1) or maxArrayLike(5).

This is causing my provider tests to fail in an unexpected manner.
The provider is currently returning 2 users, and the test fails because it only expects 1. (using pact-jvm-provider-spring-mvc).

java.lang.AssertionError: []: Expected 1 values but got 2

The error message isn't very useful on it's own, but I was able to verify by debugging that it failed because the provider had 2 items in the response, but the expected payload only had 1.

What exactly are minArrayLike and maxArrayLike supposed to do?

$ diff minArrayLike5 maxArrayLike5 

24,26c24,26

<                         "email": "nrUfIlvNMdmjSZwsNPHv",

<                         "id": "cae2db77-487a-4b6b-8e6f-9cb7411ab2b1",

<                         "userName": "rzFvcALwDaqNBDghdalp"

---

>                         "email": "DNoDFLraARDfMgKAygIA",

>                         "id": "e0f1456b-3257-490a-aff3-757b016a8d9d",

>                         "userName": "gMjLmufHxdJctMzroWRv"


Andrew Fitzgerald

unread,
Jun 17, 2016, 6:34:46 AM6/17/16
to Pact
Opened a related pact-jvm issue: https://github.com/DiUS/pact-jvm/issues/266

Ronald Holshausen

unread,
Jun 17, 2016, 5:00:35 PM6/17/16
to Andrew Fitzgerald, Pact
Thanks for raising the issue, Andrew. I'll look into it.

--
You received this message because you are subscribed to the Google Groups "Pact" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pact-support...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Ronald Holshausen

DiUS Computing Pty Ltd

Level 10, 99 Queens Street
Melbourne, VIC 3000

Phone: +61 3 9008 5400
Mobile: +61 413 162 439

http://www.diuscomputing.com.au
Reply all
Reply to author
Forward
0 new messages