Repository navigation
Support for Pact v3 - #569
Conversation
Codecov Report
@@ Coverage Diff @@
## master #569 +/- ##
============================================
+ Coverage 61.06% 61.48% +0.41%
- Complexity 1834 1935 +101
============================================
Files 210 217 +7
Lines 7534 7918 +384
Branches 1125 1234 +109
============================================
+ Hits 4601 4868 +267
- Misses 2291 2373 +82
- Partials 642 677 +35
Continue to review full report at Codecov.
|
|
Apparently in Pact 2.0 support, I haven't noticed that in the Pact matchers section you could do |
…sing the v3 spec. Introduces breaking change returning a list of `Pact`s instead of one.
… Cloud contracts.
|
Related - #583 |
marcingrzejszczak
left a comment
There was a problem hiding this comment.
WOW, this is absolutely fantastic work, so, first of all, congratulations! I gave my feedback which is, generally speaking, mostly about some minor tweaks and changes. As far as the very conversion is concerned, I guess you know more about Pact then I do, so I can provide little feedback. In general, it looks great and I would be more than happy to merge it once you feel that it's pretty stable :)
| <groupId>au.com.dius</groupId> | ||
| <artifactId>pact-jvm-model</artifactId> | ||
| <optional>true</optional> | ||
| <artifactId>pact-jvm-consumer-java8_2.12</artifactId> |
There was a problem hiding this comment.
Why not optional? Do we want to force that particular version?
There was a problem hiding this comment.
My bad, that wasn't supposed to happen. Then again, I won't know if it will work with future versions.
(except when somebody files an issue)
| private static DslPart traverse(Object value, DslPart parent, Closure dslPropertyValueExtractor) { | ||
| boolean isRoot = parent == null | ||
| Object v = value | ||
|
|
There was a problem hiding this comment.
It's just a matter of preference, but could you get rid of all of those separations between blocks? If not, then I'll do it later
| } | ||
| } | ||
|
|
||
| p |
There was a problem hiding this comment.
Can you add return ? I prefer to always explicitly define return, otherwise you can accidentally return sth you didn't want to return, and also it's more comprehensible for others. Also if you refactor from a method that returns sth to void, your code will still compile even though it shouldn't :)
| }) | ||
| } | ||
|
|
||
| private static void processMap(Map<String, Object> values, PactDslJsonBody jsonObject, Closure dslPropertyValueExtractor) { |
There was a problem hiding this comment.
Isn't iterating JSON a fantastic experience? :D
There was a problem hiding this comment.
Oh yes, really fantastic! I'm glad I can mention this on my resume now :D
| class MatchingRulesConverter { | ||
|
|
||
| static Category matchingRulesForBody(BodyMatchers bodyMatchers) { | ||
| matchingRulesFor("body", bodyMatchers) |
| } | ||
| } else { | ||
| ruleGroup.rules.each { MatchingRule rule -> | ||
| if (rule instanceof RegexMatcher) { |
There was a problem hiding this comment.
Theoretically, you could rewrite this to call jsonPath only once and just pass different value basing on the instance of rule.
There was a problem hiding this comment.
Good idea! But then you would need to explain me how I could pass the current closure context to another method.
Closures, they're possibly great when you understand it completely. :D
There was a problem hiding this comment.
Ah ok, so just ignore it.
| return dsl.request.url.queryParameters | ||
| } | ||
| throw new IllegalStateException("No url provided") | ||
| pactContracts |
There was a problem hiding this comment.
missing return (I wasn't adding this comment everywhere since it doesn't make much sense to repeat myself)
| @PackageScope | ||
| class RequestResponsePactCreator { | ||
|
|
||
| static final Closure requestDslPropertyValueExtractor = { DslProperty property -> property.serverValue } |
There was a problem hiding this comment.
ha! you have to add a modifier e.g. protected if you want this to be a constant field. Otherwise if you check out the MOP, you'll see that a private static final field was created with a public static getter method :)
There was a problem hiding this comment.
Good catch! Both should be private indeed!
| }, | ||
| "$.body.something": { | ||
| "match": "equality" | ||
| "body": { |
There was a problem hiding this comment.
maybe we should check for the headers matchers too?
There was a problem hiding this comment.
Yes, that's for some time later. They also introduced path & query matchers.
See https://github.com/pact-foundation/pact-specification/tree/version-3#drop-the-jsonpath-notation-for-matchers
| }) | ||
| jsonPath('$.id', byType()) | ||
|
|
||
| // TODO: CURRENTLY NOT SUPPORTED |
There was a problem hiding this comment.
Why isn't it supported? That should work I guess OOB ?
There was a problem hiding this comment.
No, it wasn't. They added new matchers to v3, check https://github.com/pact-foundation/pact-specification/tree/version-3#add-an-equality-matcher until the generators
Currently only the AND rule logic is supported.
…s of "matcher groups", eg. header, path & query
… supported by WireMock
PR to track the Pact v3 support.
❗️This is currently a work in progress❗️
Tasks
pact-jvm-modelfrom2.4.18to3.5.13pact-jvm-consumer-java8_2.12)Notes on implementation:
Introduces breaking changes:
TheThis has been reverted in favor of a non-invasive change using deprecationtestMatchersandstubMatchershave been changed to be able to add path, query and header matchersCloses #583
Fixes #595