question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pact-jvm-consumer-groovy generates incorrect contents in message pact file

See original GitHub issue

Version 4.0.2 of pact-jvm-consumer-groovy seems to have introduced a bug where the generated message pact file contains incorrect contents. Rather than being a JSON object, contents is a String representation of the expected JSON.

With this code:

def pactMessageBuilder = new PactMessageBuilder().with {
    serviceConsumer 'consumer'
    hasPactWith 'provider'
    expectsToReceive 'feed entry'
    withMetaData(contentType: 'application/json')
    withContent(contentType: 'application/json') {
        type 'foo'
        data {
            reference {
                id string('abc')
            }
        }
    }
}

4.0.2 generates:

{
  "consumer": {
    "name": "consumer"
  },
  "provider": {
    "name": "provider"
  },
  "messages": [
    {
      "description": "feed entry",
      "metaData": {
        "contentType": "application/json"
      },
      "contents": "{\n    \"type\": \"foo\",\n    \"data\": {\n        \"reference\": {\n            \"id\": \"abc\"\n        }\n    }\n}",
      "matchingRules": {
        "body": {
          "$.data.reference.id": {
            "matchers": [
              {
                "match": "type"
              }
            ],
            "combine": "AND"
          }
        }
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    },
    "pact-jvm": {
      "version": "4.0.2"
    }
  }
}

whereas 4.0.1 generates:

{
  "consumer": {
    "name": "consumer"
  },
  "provider": {
    "name": "provider"
  },
  "messages": [
    {
      "description": "feed entry",
      "metaData": {
        "contentType": "application/json"
      },
      "contents": {
        "type": "foo",
        "data": {
          "reference": {
            "id": "abc"
          }
        }
      },
      "matchingRules": {
        "body": {
          "$.data.reference.id": {
            "matchers": [
              {
                "match": "type"
              }
            ],
            "combine": "AND"
          }
        }
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    },
    "pact-jvm": {
      "version": "4.0.1"
    }
  }
}

I have created a repo to reproduce the issue here: https://github.com/qmg-rbass/pact-bug

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
qmg-rbasscommented, Mar 23, 2020

Working well after upgrade, thanks @uglyog

0reactions
uglyogcommented, Mar 8, 2020

Version 4.0.7 has been released with this change

Read more comments on GitHub >

github_iconTop Results From Across the Web

pact-jvm-consumer-groovy generates incorrect contents in ...
Version 4.0.2 of pact-jvm-consumer-groovy seems to have introduced a bug where the generated message pact file contains incorrect contents.
Read more >
pact-jvm-consumer-groovy | Pact Docs
Introduces a new message pact format for testing interactions via a message queue. Multiple provider states can be defined with data parameters.
Read more >
“How-to” Guides - Spring Cloud
Starting from Spring Cloud Contract 2.0.0, you can fetch Pact files from the Pact Broker to generate tests and stubs. Pact follows the...
Read more >
Contract Tests With Pact JVM — The Tricky Parts - Medium
Below you can find three code excerpts, limited to body matchers only, using different DSL variants: groovy, java, and java 8 (with lambdas):....
Read more >
Writing Contract Tests with Pact in Spring Boot - kreuzwerker
The consumer is a messaging app that shows the user's name. ... The easiest way to create the Pact file is via a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found