Open vasile21 opened 11 months ago
Update: PactDslRootValue receivedResponse= new PactDslRootValue(); receivedResponse.setValue(response); MatchingRuleCategory category = receivedResponse.getMatchers(); -> generates matchingRules section in the pact json file but I am waiting for your view on this approach
You need to set the values for the matching rules from the Pact object. This code
MatchingRuleCategory categoryBody = new MatchingRuleCategory("body");
categoryBody.addRule("$.testField", new RegexMatcher(".+"));
will just create a new MatchingRuleCategory that is not associated with anything.
protected PactDslRootValue myMatcherRules(String response) { final PactDslRootValue expectedResponse = new PactDslRootValue(); expectedResponse.setValue(response); MatchingRuleCategory matchers = expectedResponse.getMatchers(); categoryBody.addRule("$.testField", new RegexMatcher(".+")); this seems to attach defined rules to body category
Hi Currently I am trying to migrate from the old pact-jvm-consumer-junit5 (version 4.0.10) to the new au.com.dius.pact.consumer (version 4.6.3)
I noticed that in the examples and documentation for the new library there is no example/usage of the approach to define matchingRules via Category or MatchingRuleCategory. eg MatchingRuleCategory categoryBody = new MatchingRuleCategory("body"); categoryBody.addRule("$.testField", new RegexMatcher(".+")); -> this does not generate matchingRules section in pact.
The examples with LambdaDsl. newJsonBody or PactDslJsonBody seems quite cumbersome to use on responses with a lot of different data types and various objects structure.
Could you point me towards an pact-consumer test / documentation that is still using the more friendly way (imo) of defining matchingRules for response body?