pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.09k stars 480 forks source link

Negative Integer is not recognised as such #1575

Open SandorArpa opened 2 years ago

SandorArpa commented 2 years ago

We have a pact test where one of the variables is a negative number (MessagePactBuilder generated file):

{ "consumer": { "name": "ledger" }, "provider": { "name": "connector" }, "messages": [ { "_id": "c3d524ebb49c46e1e8b100a94d9c880b6a0cc43b", "description": "a dispute lost event", "metaData": { "contentType": "application/json" }, "contents": { "event_type": "DISPUTE_LOST", "service_id": "service-id", "resource_type": "dispute", "event_details": { "amount": 6500, "gateway_account_id": "a-gateway-account-id", "fee": 1500, "net_amount": -8000 }, "live": true, "timestamp": "2022-01-19T07:59:20.000000Z", "resource_external_id": "payment-external-id", "parent_resource_external_id": "external-id" }, "matchingRules": { "body": { ... "$.event_details.net_amount": { "matchers": [ { "match": "integer" } ], "combine": "AND" }, "$.event_details.amount": { "matchers": [ { "match": "integer" } ], "combine": "AND" }, "$.event_details.gateway_account_id": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.event_details.fee": { "matchers": [ { "match": "integer" } ], "combine": "AND" } } } } ], "metadata": { "pactSpecification": { "version": "3.0.0" }, "pact-jvm": { "version": "3.6.15" } }

The provider's response:

{ "resource_external_id": "resource-external-id", "event_details": { "gateway_account_id": "a-gateway-account-id", "net_amount": -8000, "amount": 6500, "fee": 1500 } ... }

The error:

BodyComparisonResult(mismatches={$.event_details.net_amount=[BodyMismatch(expected=-8000, actual=-8000, mismatch=Expected -8000 (JsonPrimitive) to be an integer, path=$.event_details.net_amount, diff=null)]}, diff=[{, - "event_type": "DISPUTE_LOST",, - "service_id": "service-id",, - "resource_type": "dispute",, + "resource_external_id": "resource-external-id",, "event_details": {, - "amount": 6500,, "gateway_account_id": "a-gateway-account-id",, - "fee": 1500,, - "net_amount": -8000, + "net_amount": -8000,, + "amount": 6500,, + "fee": 1500, },, - "live": true,, "timestamp": "2022-01-19T07:59:20.000000Z",, - "resource_external_id": "payment-external-id",, - "parent_resource_external_id": "external-id", + "parent_resource_external_id": "external-id",, + "service_id": "service-id",, + "live": true,, + "resource_type": "dispute",, + "event_type": "DISPUTE_LOST", }])

when running in IDE against a local pact file (Running with PactFolder tag on provider, using PactVerifyProvider, not State) :

rholshausen commented 2 years ago

I've tested this with the latest version (4.3.12), and it works correctly. I've noticed your Pact file has "pact-jvm": { "version": "3.6.15" }, is that the version you are using (3.6.15)?

SandorArpa commented 2 years ago

Yes, we are on 3.6.15

rholshausen commented 2 years ago

Can you upgrade? That version is not supported anymore, and the supported versions do not have this issue.