Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML matching rules incorrect in version 4.0.11 #1186

Open
mefellows opened this issue Aug 6, 2020 · 1 comment
Open

XML matching rules incorrect in version 4.0.11 #1186

mefellows opened this issue Aug 6, 2020 · 1 comment

Comments

@mefellows
Copy link
Member

Matching rules in junit5 consumer tests appear to produce an invalid contract, when manually adjusted to what I believe are correct matching rules, the provider is still matching on exact values.

Versions

Versions

  • Consumer version: au.com.dius:pact-jvm-consumer-junit5:4.0.10
  • Provider version: au.com.dius:pact-jvm-provider-junit5:4.0.10
  • OS: Mac OSX

Repro

Problem 1: consumer produces invalid matching rules

Given a test that produces (expects) this XML Document:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ns:projects id="1234" xmlns:ns="http://some.namespace/and/more/stuff">
    <project due="2016-02-11T09:46:56.023Z" id="100" name="Project 1" type="activity">
        <tasks>
            <task done="true" id="100" name="Task 1"/>
            <task done="true" id="100" name="Task 1"/>
            <task done="true" id="100" name="Task 1"/>
            <task done="true" id="100" name="Task 1"/>
        </tasks>
    </project>
</ns:projects>

It produces this pact file:

{
  "provider": {
    "name": "pactflow-example-provider-java-soap"
  },
  "consumer": {
    "name": "pactflow-example-consumer-java-soap"
  },
  "interactions": [
    {
      "description": "a request for projects in XML",
      "request": {
        "method": "GET",
        "path": "/projects",
        "headers": {
          "Accept": "application/xml"
        },
        "query": {
          "from": [
            "today"
          ]
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/xml"
        },
        "body": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<ns:projects id=\"1234\" xmlns:ns=\"http://some.namespace/and/more/stuff\">\n    <project due=\"2016-02-11T09:46:56.023Z\" id=\"100\" name=\"Project 1\" type=\"activity\">\n        <tasks>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n        </tasks>\n    </project>\n    <project due=\"2016-02-11T09:46:56.023Z\" id=\"100\" name=\"Project 1\" type=\"activity\">\n        <tasks>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n            <task done=\"true\" id=\"100\" name=\"Task 1\"/>\n        </tasks>\n    </project>\n</ns:projects>\n",
        "matchingRules": {
          "body": {
            "$.projects.project.['@due']": {
              "matchers": [
                {
                  "match": "timestamp",
                  "timestamp": "yyyy-MM-dd'T'HH:mm:ss.SSSX"
                }
              ],
              "combine": "AND"
            },
            "$.projects.project.['@name']": {
              "matchers": [
                {
                  "match": "type"
                }
              ],
              "combine": "AND"
            },
            "$.projects.project.['@id']": {
              "matchers": [
                {
                  "match": "integer"
                }
              ],
              "combine": "AND"
            },
            "$.projects.project.tasks.task.['@name']": {
              "matchers": [
                {
                  "match": "type"
                }
              ],
              "combine": "AND"
            },
            "$.projects.project.tasks.task.['@id']": {
              "matchers": [
                {
                  "match": "integer"
                }
              ],
              "combine": "AND"
            },
            "$.projects.project.tasks.task.['@done']": {
              "matchers": [
                {
                  "match": "type"
                }
              ],
              "combine": "AND"
            }
          }
        },
        "generators": {
          "body": {
            "$.projects.project.['@id']": {
              "type": "RandomInt",
              "min": 0,
              "max": 2147483647
            },
            "$.projects.project.tasks.task.['@id']": {
              "type": "RandomInt",
              "min": 0,
              "max": 2147483647
            }
          }
        }
      },
      "providerStates": [
        {
          "name": "i have a list of projects"
        }
      ]
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    },
    "pact-jvm": {
      "version": "4.0.10"
    }
  }
}

When verifying on the provider, the following error is observed:

Expected either a "*" or path identifier in path expression "$.projects.project.['@Due']" at index 19

Problem 2: Provider only matches exact values

I worked around this temporarily by adjusting all of the incorrect $.projects.project.['@id'] type problems to -> $.projects.project['@id']. This allowed the provider to progress further, but the matching rules aren't applied and thus exact values are required for a test to pass.

@uglyog
Copy link
Member

uglyog commented Aug 9, 2020

4.1.7 has been released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants