Type matching support for pact-jvm

745 views
Skip to first unread message

ag...@thoughtworks.com

unread,
Jan 21, 2015, 12:50:24 AM1/21/15
to pact-s...@googlegroups.com
Hi,

I am trying to figure out if there is type matching support for pact-jvm. I have managed to define the type matching on the consumer end via the PactDSLJsonBody but can't seem to figure out how get the type matching working on the provider end. 

Cheers,
Adrian

Ronald Holshausen

unread,
Jan 21, 2015, 3:34:29 PM1/21/15
to pact-s...@googlegroups.com
Hi Adrian,

Pact-Jvm currently supports type matching for strings and numbers. How are you verifying your provider? Is it with pact-jvm, or are you using one of the other pact libraries?

If you could give a description of what your are trying to do, or post code examples, it would help.

Regards,

Ronald

ag...@thoughtworks.com

unread,
Jan 22, 2015, 12:20:51 AM1/22/15
to pact-s...@googlegroups.com
Hi Ron,

Thanks for your reply. I am currently verifying the provider with pact-jvm using the gradle plug-in. I have managed to create the consumer pact with type matching using PactDslJsonBody shown below and then verifying the pact file on the provider side using the pactVerify gradle task. We noticed that the rules defined in responseMatchingRules section were not being validated, when we modified the json paths from $.body.numbers.1.number to anything else our pact still passes. Hope this makes sense. 


PactDSLJsonBody usage
PactDslJsonBody responseBody = new PactDslJsonBody();
        responseBody
                .array("numbers")
                .object()
                .stringType("number")
                .closeObject()
                .object()
                .stringValue("number", "020173268")
                .closeObject()
                .closeArray();



Pact File
{
  "provider" : {
    "name" : "Provider"
  },
  "consumer" : {
    "name" : "Consumer"
  },
  "interactions" : [ {
    "description" : "a request for numbers",
    "request" : {
      "method" : "GET",
      "path" : "/api/numbers"
    },
    "response" : {
      "status" : 200,
      "headers" : {
        "Content-Type" : "application/json; charset=UTF-8"
      },
      "body" : {
        "numbers" : [ {
          "number" : "2676138263163"
        }, {
          "number" : "020173268"
        } ]
      },
      "responseMatchingRules" : {
        "$.body.numbers.1.number" : {
          "match" : "type"
        }
      }
    }
  } ],
  "metadata" : {
    "pact-specification" : {
      "version" : "2.0.0"
    },
    "pact-jvm" : {
      "version" : "2.1.9"
    }
  }
}


Ronald Holshausen

unread,
Jan 22, 2015, 5:33:15 PM1/22/15
to pact-s...@googlegroups.com
Hi Adrian,

That looks correct. 

Looking through the verification code, there is no logging of the matching so we won't be able to see why it is not working. I have raised an issue for this (https://github.com/DiUS/pact-jvm/issues/82).

Can you post the output from running the pactverify task with debug turned on (gradle -d pactverify)? It will be extremely verbose, but you should be able to see the request and responses being made (although not the response bodies).

I'll try setup a test to duplicate your issue.

Regards,

Ronald

Ronald Holshausen

unread,
Jan 22, 2015, 9:23:28 PM1/22/15
to pact-s...@googlegroups.com
I've committed debug logging to the matchers. If you checkout the project and build it, you should be able to run `./gradlew -q pactvertify` with version 2.1.10 and it will include logging about the matching.
Reply all
Reply to author
Forward
0 new messages