Good morning (evening, afternoon) :wave: We're on ...
# pact-jvm
s
Good morning (evening, afternoon) 👋 We're on pact v3. I've got an issue with NumberTypeMatcher where the matcher does not recognise a negative number as Integer. The part of generated contract file (from MessageBuilder) that fails:
Copy code
$.event_details.net_amount=MatchingRuleGroup(rules=[NumberTypeMatcher(numberType=INTEGER)]
The error I get:
BodyMismatch(expected=-8000, actual=-8000, mismatch=Expected -8000 (JsonPrimitive) to be an integer
m
As discussed in the other channel, could you please provide the additional details requested?
s
I just need to format the files. Won't be a sec
the generated contract file:
Copy code
au.com.dius.pact.model.v3.messaging.MessagePact([
  au.com.dius.pact.model.v3.messaging.Message(a
  dispute
  lost
  event,
  [],
  PRESENT(
  {
    "event_type": "DISPUTE_LOST",
    "service_id": "service-id",
    "resource_type": "dispute",
    "event_details": {
      "gateway_account_id": "a-gateway-account-id",
      "amount": 6500,
      "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(rules=
  {
    body=Category(name=body,
    matchingRules=
  {
    $.event_type=MatchingRuleGroup(rules=
  [
    au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363
  ],
  ruleLogic=AND),
  $.timestamp=MatchingRuleGroup(rules=
  [
    au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363
  ],
  ruleLogic=AND),
  $.resource_external_id=MatchingRuleGroup(rules=
  [
    au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363
  ],
  ruleLogic=AND),
  $.live=MatchingRuleGroup(rules=
  [
    au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363,
    au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363
  ],
  ruleLogic=AND),
  $.resource_type=MatchingRuleGroup(rules=
  [
    au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363
  ],
  ruleLogic=AND),
  $.parent_resource_external_id=MatchingRuleGroup(rules=
  [
    au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363
  ],
  ruleLogic=AND),
  $.service_id=MatchingRuleGroup(rules=
  [
    au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363
  ],
  ruleLogic=AND),
  $.event_details.gateway_account_id=MatchingRuleGroup(rules=
  [
    au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363
  ],
  ruleLogic=AND),
  $.event_details.amount=MatchingRuleGroup(rules=
  [
    NumberTypeMatcher(numberType=INTEGER)
  ],
  ruleLogic=AND),
  $.event_details.net_amount=MatchingRuleGroup(rules=
  [
    NumberTypeMatcher(numberType=INTEGER)
  ],
  ruleLogic=AND),
  $.event_details.fee=MatchingRuleGroup(rules=
  [
    NumberTypeMatcher(numberType=INTEGER)
  ],
  ruleLogic=AND)
  }
  )
  }
  ),
  Generators(categories={}),
  [
    contentType
    :
    application/json
  ],
  null,
  application/json,
  null,
  application/json)
],
Consumer(name=ledger), Provider(name=connector), [pactSpecification:[version: 3.0.0], pact-jvm:[version: 3.6.15]], null, [
au.com.dius.pact.model.v3.messaging.Message(a dispute lost event, [], 
PRESENT({"event_type": "DISPUTE_LOST", "service_id": "service-id", "resource_type": "dispute", 
"event_details": {"gateway_account_id":"a-gateway-account-id", "amount": 6500, "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(rules={body=Category(name=body, 
 matchingRules={$.event_type=MatchingRuleGroup(rules=[au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363], ruleLogic=AND), 
$.timestamp=MatchingRuleGroup(rules=[au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363], ruleLogic=AND), 
$.resource_external_id=MatchingRuleGroup(rules=[au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363], ruleLogic=AND), 
$.live=MatchingRuleGroup(rules=[au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363, au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363], ruleLogic=AND), 
$.resource_type=MatchingRuleGroup(rules=[au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363], ruleLogic=AND), 
$.parent_resource_external_id=MatchingRuleGroup(rules=[au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363], ruleLogic=AND), 
$.service_id=MatchingRuleGroup(rules=[au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363], ruleLogic=AND), 
$.event_details.gateway_account_id=MatchingRuleGroup(rules=[au.com.dius.pact.model.matchingrules.TypeMatcher@3c3e363], ruleLogic=AND), 
$.event_details.amount=MatchingRuleGroup(rules=[NumberTypeMatcher(numberType=INTEGER)], ruleLogic=AND), 
$.event_details.net_amount=MatchingRuleGroup(rules=[NumberTypeMatcher(numberType=INTEGER)], ruleLogic=AND), 
$.event_details.fee=MatchingRuleGroup(rules=[NumberTypeMatcher(numberType=INTEGER)], ruleLogic=AND)})}), Generators(categories={}), [contentType: application/json], null, application/json, null, application/json)
])
(So sorry, I tried my best to format the one line)
And this is the response:
Copy code
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", }])
the variable in question is
net_amount
m
Right, I need the actual Pact file sorry (i.e. the json file), not the Java model of it.
Also, i’d like to see the actual JSON response from your provider, not the interpretation of it in the log file
I think if you set DEBUG logging, you’ll get a raw dump of it in the terminal output
(I ask because this helps rule in/out certain classes of bugs in the Java code. If the input and output is correct, we can assume it’s probably a bug in Pact JVM)
s
We don't have a pact file as per se. It's generated in realtime
m
what do you mean, sorry? How is the provider verifying it? This is a mode I’m not aware of 🤔
That file should produce a JSON contract though right?
and you publish that to the broker?
s
Copy code
{
  "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_type": {
                "matchers": [
                  {
                    "match": "type"
                  }
                ],
                "combine": "AND"
              },
              "$.timestamp": {
                "matchers": [
                  {
                    "match": "type"
                  }
                ],
                "combine": "AND"
              },
              "$.resource_external_id": {
                "matchers": [
                  {
                    "match": "type"
                  }
                ],
                "combine": "AND"
              },
              "$.live": {
                "matchers": [
                  {
                    "match": "type"
                  },
                  {
                    "match": "type"
                  }
                ],
                "combine": "AND"
              },
              "$.resource_type": {
                "matchers": [
                  {
                    "match": "type"
                  }
                ],
                "combine": "AND"
              },
              "$.parent_resource_external_id": {
                "matchers": [
                  {
                    "match": "type"
                  }
                ],
                "combine": "AND"
              },
              "$.service_id": {
                "matchers": [
                  {
                    "match": "type"
                  }
                ],
                "combine": "AND"
              },
              "$.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"
    }
  }
I think this is the one you meant?
provider response:
Copy code
{
  "resource_external_id": "resource-external-id",
  "event_details": {
    "gateway_account_id": "a-gateway-account-id",
    "net_amount": -8000,
    "amount": 6500,
    "fee": 1500
  },
  "timestamp": "2022-01-19T07:59:20.000000Z",
  "parent_resource_external_id": "external-id",
  "service_id": "service-id",
  "live": true,
  "resource_type": "dispute",
  "event_type": "DISPUTE_LOST"
}
🙏 1
One more thing to add, when running in IDE against a local pact file: • without
matchingRules
- it passes • with
matchingRules
but
net_amount
type set to
number
- it passes • with
matchingRules
and
net_amount
type is
integer
- fails
(Running from PactFolder on provider)
Using PactVerifyProvider, not State
m
interesting.
it sounds like it’s a bug
I wonder if a DEBUG level log of the above might yield a useful hint
i.e. I’d be keen to see what this log says
s
The stacktrace that is provided:
Copy code
at au.com.dius.pact.provider.junit.target.BaseTarget.getAssertionError(BaseTarget.kt:73)
	at au.com.dius.pact.provider.junit.target.AmqpTarget.testInteraction(AmqpTarget.kt:50)
	at au.com.dius.pact.provider.junit.InteractionRunner$interactionBlock$statement$1.evaluate(InteractionRunner.kt:204)
	at au.com.dius.pact.provider.junit.InteractionRunner.run(InteractionRunner.kt:145)
	at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:147)
	at au.com.dius.pact.provider.junit.PactRunner.runChild(PactRunner.kt:52)
u
Please raise an issue, this is a defect
s
How do I do that?
s
Thank you!