All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Download JAR files tagged by read with all dependencies

Search JAR files by class name

pact-jvm-consumer-java8_2.12 from group au.com.dius (version 3.6.15)

# pact-jvm-consumer-java8 Provides a Java8 lambda based DSL for use with Junit to build consumer tests. # A Lambda DSL for Pact This is an extension for the pact DSL provided by [pact-jvm-consumer](../pact-jvm-consumer). The difference between the default pact DSL and this lambda DSL is, as the name suggests, the usage of lambdas. The use of lambdas makes the code much cleaner. ## Why a new DSL implementation? The lambda DSL solves the following two main issues. Both are visible in the following code sample: ```java new PactDslJsonArray() .array() # open an array .stringValue("a1") # choose the method that is valid for arrays .stringValue("a2") # choose the method that is valid for arrays .closeArray() # close the array .array() # open an array .numberValue(1) # choose the method that is valid for arrays .numberValue(2) # choose the method that is valid for arrays .closeArray() # close the array .array() # open an array .object() # now we work with an object .stringValue("foo", "Foo") # choose the method that is valid for objects .closeObject() # close the object and we're back in the array .closeArray() # close the array ``` ### The existing DSL is quite error-prone Methods may only be called in certain states. For example `object()` may only be called when you're currently working on an array whereas `object(name)` is only allowed to be called when working on an object. But both of the methods are available. You'll find out at runtime if you're using the correct method. Finally, the need for opening and closing objects and arrays makes usage cumbersome. The lambda DSL has no ambiguous methods and there's no need to close objects and arrays as all the work on such an object is wrapped in a lamda call. ### The existing DSL is hard to read When formatting your source code with an IDE the code becomes hard to read as there's no indentation possible. Of course, you could do it by hand but we want auto formatting! Auto formatting works great for the new DSL! ```java array.object((o) -> { o.stringValue("foo", "Foo"); # an attribute o.stringValue("bar", "Bar"); # an attribute o.object("tar", (tarObject) -> { # an attribute with a nested object tarObject.stringValue("a", "A"); # attribute of the nested object tarObject.stringValue("b", "B"); # attribute of the nested object }) }); ``` ## Installation ### Maven ``` <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-consumer-java8_2.12</artifactId> <version>${pact.version}</version> </dependency> ``` ## Usage Start with a static import of `LambdaDsl`. This class contains factory methods for the lambda dsl extension. When you come accross the `body()` method of `PactDslWithProvider` builder start using the new extensions. The call to `LambdaDsl` replaces the call to instance `new PactDslJsonArray()` and `new PactDslJsonBody()` of the pact library. ```java io.pactfoundation.consumer.dsl.LambdaDsl.* ``` ### Response body as json array ```java import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonArray; ... PactDslWithProvider builder = ... builder.given("some state") .uponReceiving("a request") .path("/my-app/my-service") .method("GET") .willRespondWith() .status(200) .body(newJsonArray((a) -> { a.stringValue("a1"); a.stringValue("a2"); }).build()); ``` ### Response body as json object ```java import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody; ... PactDslWithProvider builder = ... builder.given("some state") .uponReceiving("a request") .path("/my-app/my-service") .method("GET") .willRespondWith() .status(200) .body(newJsonBody((o) -> { o.stringValue("foo", "Foo"); o.stringValue("bar", "Bar"); }).build()); ``` ### Examples #### Simple Json object When creating simple json structures the difference between the two approaches isn't big. ##### JSON ```json { "bar": "Bar", "foo": "Foo" } ``` ##### Pact DSL ```java new PactDslJsonBody() .stringValue("foo", "Foo") .stringValue("bar", "Bar") ``` ##### Lambda DSL ```java newJsonBody((o) -> { o.stringValue("foo", "Foo"); o.stringValue("bar", "Bar"); }).build(); ``` #### An array of arrays When we come to more complex constructs with arrays and nested objects the beauty of lambdas become visible! ##### JSON ```json [ ["a1", "a2"], [1, 2], [{"foo": "Foo"}] ] ``` ##### Pact DSL ```java new PactDslJsonArray() .array() .stringValue("a1") .stringValue("a2") .closeArray() .array() .numberValue(1) .numberValue(2) .closeArray() .array() .object() .stringValue("foo", "Foo") .closeObject() .closeArray(); ``` ##### Lambda DSL ```java newJsonArray((rootArray) -> { rootArray.array((a) -> a.stringValue("a1").stringValue("a2")); rootArray.array((a) -> a.numberValue(1).numberValue(2)); rootArray.array((a) -> a.object((o) -> o.stringValue("foo", "Foo"))); }).build(); ``` `object` is a reserved word in Kotlin. To allow using the DSL without escaping, a Kotlin extension `newObject` is available: ```kotlin newJsonArray { rootArray -> rootArray.array { a -> a.stringValue("a1").stringValue("a2") } rootArray.array { a -> a.numberValue(1).numberValue(2) } rootArray.array { a -> a.newObject { o -> o.stringValue("foo", "Foo") } } }.build(); ```

Group: au.com.dius Artifact: pact-jvm-consumer-java8_2.12
Show all versions Show documentation Show source 
 

0 downloads
Artifact pact-jvm-consumer-java8_2.12
Group au.com.dius
Version 3.6.15
Last update 29. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 1
Dependencies pact-jvm-consumer_2.12,
There are maybe transitive dependencies!

pact-jvm-consumer-java8 from group au.com.dius (version 4.0.10)

# pact-jvm-consumer-java8 Provides a Java8 lambda based DSL for use with Junit to build consumer tests. # A Lambda DSL for Pact This is an extension for the pact DSL provided by [pact-jvm-consumer](../pact-jvm-consumer). The difference between the default pact DSL and this lambda DSL is, as the name suggests, the usage of lambdas. The use of lambdas makes the code much cleaner. ## Why a new DSL implementation? The lambda DSL solves the following two main issues. Both are visible in the following code sample: ```java new PactDslJsonArray() .array() # open an array .stringValue("a1") # choose the method that is valid for arrays .stringValue("a2") # choose the method that is valid for arrays .closeArray() # close the array .array() # open an array .numberValue(1) # choose the method that is valid for arrays .numberValue(2) # choose the method that is valid for arrays .closeArray() # close the array .array() # open an array .object() # now we work with an object .stringValue("foo", "Foo") # choose the method that is valid for objects .closeObject() # close the object and we're back in the array .closeArray() # close the array ``` ### The existing DSL is quite error-prone Methods may only be called in certain states. For example `object()` may only be called when you're currently working on an array whereas `object(name)` is only allowed to be called when working on an object. But both of the methods are available. You'll find out at runtime if you're using the correct method. Finally, the need for opening and closing objects and arrays makes usage cumbersome. The lambda DSL has no ambiguous methods and there's no need to close objects and arrays as all the work on such an object is wrapped in a lamda call. ### The existing DSL is hard to read When formatting your source code with an IDE the code becomes hard to read as there's no indentation possible. Of course, you could do it by hand but we want auto formatting! Auto formatting works great for the new DSL! ```java array.object((o) -> { o.stringValue("foo", "Foo"); # an attribute o.stringValue("bar", "Bar"); # an attribute o.object("tar", (tarObject) -> { # an attribute with a nested object tarObject.stringValue("a", "A"); # attribute of the nested object tarObject.stringValue("b", "B"); # attribute of the nested object }) }); ``` ## Installation ### Maven ``` <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-consumer-java8_2.12</artifactId> <version>${pact.version}</version> </dependency> ``` ## Usage Start with a static import of `LambdaDsl`. This class contains factory methods for the lambda dsl extension. When you come accross the `body()` method of `PactDslWithProvider` builder start using the new extensions. The call to `LambdaDsl` replaces the call to instance `new PactDslJsonArray()` and `new PactDslJsonBody()` of the pact library. ```java io.pactfoundation.consumer.dsl.LambdaDsl.* ``` ### Response body as json array ```java import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonArray; ... PactDslWithProvider builder = ... builder.given("some state") .uponReceiving("a request") .path("/my-app/my-service") .method("GET") .willRespondWith() .status(200) .body(newJsonArray((a) -> { a.stringValue("a1"); a.stringValue("a2"); }).build()); ``` ### Response body as json object ```java import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody; ... PactDslWithProvider builder = ... builder.given("some state") .uponReceiving("a request") .path("/my-app/my-service") .method("GET") .willRespondWith() .status(200) .body(newJsonBody((o) -> { o.stringValue("foo", "Foo"); o.stringValue("bar", "Bar"); }).build()); ``` ### Examples #### Simple Json object When creating simple json structures the difference between the two approaches isn't big. ##### JSON ```json { "bar": "Bar", "foo": "Foo" } ``` ##### Pact DSL ```java new PactDslJsonBody() .stringValue("foo", "Foo") .stringValue("bar", "Bar") ``` ##### Lambda DSL ```java newJsonBody((o) -> { o.stringValue("foo", "Foo"); o.stringValue("bar", "Bar"); }).build(); ``` #### An array of arrays When we come to more complex constructs with arrays and nested objects the beauty of lambdas become visible! ##### JSON ```json [ ["a1", "a2"], [1, 2], [{"foo": "Foo"}] ] ``` ##### Pact DSL ```java new PactDslJsonArray() .array() .stringValue("a1") .stringValue("a2") .closeArray() .array() .numberValue(1) .numberValue(2) .closeArray() .array() .object() .stringValue("foo", "Foo") .closeObject() .closeArray(); ``` ##### Lambda DSL ```java newJsonArray((rootArray) -> { rootArray.array((a) -> a.stringValue("a1").stringValue("a2")); rootArray.array((a) -> a.numberValue(1).numberValue(2)); rootArray.array((a) -> a.object((o) -> o.stringValue("foo", "Foo"))); }).build(); ``` ##### Kotlin Lambda DSL ```kotlin newJsonArray { newArray { stringValue("a1") stringValue("a2") } newArray { numberValue(1) numberValue(2) } newArray { newObject { stringValue("foo", "Foo") } } } ```

Group: au.com.dius Artifact: pact-jvm-consumer-java8
Show all versions Show documentation Show source 
 

0 downloads
Artifact pact-jvm-consumer-java8
Group au.com.dius
Version 4.0.10
Last update 18. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 1
Dependencies pact-jvm-consumer,
There are maybe transitive dependencies!

pact-jvm-consumer-java8_2.11 from group au.com.dius (version 3.5.24)

# pact-jvm-consumer-java8 Provides a Java8 lambda based DSL for use with Junit to build consumer tests. # A Lambda DSL for Pact This is an extension for the pact DSL provided by [pact-jvm-consumer](../pact-jvm-consumer). The difference between the default pact DSL and this lambda DSL is, as the name suggests, the usage of lambdas. The use of lambdas makes the code much cleaner. ## Why a new DSL implementation? The lambda DSL solves the following two main issues. Both are visible in the following code sample: ```java new PactDslJsonArray() .array() # open an array .stringValue("a1") # choose the method that is valid for arrays .stringValue("a2") # choose the method that is valid for arrays .closeArray() # close the array .array() # open an array .numberValue(1) # choose the method that is valid for arrays .numberValue(2) # choose the method that is valid for arrays .closeArray() # close the array .array() # open an array .object() # now we work with an object .stringValue("foo", "Foo") # choose the method that is valid for objects .closeObject() # close the object and we're back in the array .closeArray() # close the array ``` ### The existing DSL is quite error-prone Methods may only be called in certain states. For example `object()` may only be called when you're currently working on an array whereas `object(name)` is only allowed to be called when working on an object. But both of the methods are available. You'll find out at runtime if you're using the correct method. Finally, the need for opening and closing objects and arrays makes usage cumbersome. The lambda DSL has no ambiguous methods and there's no need to close objects and arrays as all the work on such an object is wrapped in a lamda call. ### The existing DSL is hard to read When formatting your source code with an IDE the code becomes hard to read as there's no indentation possible. Of course, you could do it by hand but we want auto formatting! Auto formatting works great for the new DSL! ```java array.object((o) -> { o.stringValue("foo", "Foo"); # an attribute o.stringValue("bar", "Bar"); # an attribute o.object("tar", (tarObject) -> { # an attribute with a nested object tarObject.stringValue("a", "A"); # attribute of the nested object tarObject.stringValue("b", "B"); # attribute of the nested object }) }); ``` ## Installation ### Maven ``` <dependency> <groupId>au.com.dius</groupId> <artifactId>pact-jvm-consumer-java8_2.12</artifactId> <version>${pact.version}</version> </dependency> ``` ## Usage Start with a static import of `LambdaDsl`. This class contains factory methods for the lambda dsl extension. When you come accross the `body()` method of `PactDslWithProvider` builder start using the new extensions. The call to `LambdaDsl` replaces the call to instance `new PactDslJsonArray()` and `new PactDslJsonBody()` of the pact library. ```java io.pactfoundation.consumer.dsl.LambdaDsl.* ``` ### Response body as json array ```java import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonArray; ... PactDslWithProvider builder = ... builder.given("some state") .uponReceiving("a request") .path("/my-app/my-service") .method("GET") .willRespondWith() .status(200) .body(newJsonArray((a) -> { a.stringValue("a1"); a.stringValue("a2"); }).build()); ``` ### Response body as json object ```java import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody; ... PactDslWithProvider builder = ... builder.given("some state") .uponReceiving("a request") .path("/my-app/my-service") .method("GET") .willRespondWith() .status(200) .body(newJsonBody((o) -> { o.stringValue("foo", "Foo"); o.stringValue("bar", "Bar"); }).build()); ``` ### Examples #### Simple Json object When creating simple json structures the difference between the two approaches isn't big. ##### JSON ```json { "bar": "Bar", "foo": "Foo" } ``` ##### Pact DSL ```java new PactDslJsonBody() .stringValue("foo", "Foo") .stringValue("bar", "Bar") ``` ##### Lambda DSL ```java newJsonBody((o) -> { o.stringValue("foo", "Foo"); o.stringValue("bar", "Bar"); }).build() ``` #### An array of arrays When we come to more complex constructs with arrays and nested objects the beauty of lambdas become visible! ##### JSON ```json [ ["a1", "a2"], [1, 2], [{"foo": "Foo"}] ] ``` ##### Pact DSL ```java new PactDslJsonArray() .array() .stringValue("a1") .stringValue("a2") .closeArray() .array() .numberValue(1) .numberValue(2) .closeArray() .array() .object() .stringValue("foo", "Foo") .closeObject() .closeArray() ``` ##### Lambda DSL ```java newJsonArray((rootArray) -> { rootArray.array((a) -> a.stringValue("a1").stringValue("a2")); rootArray.array((a) -> a.numberValue(1).numberValue(2)); rootArray.array((a) -> a.object((o) -> o.stringValue("foo", "Foo")); }).build() ```

Group: au.com.dius Artifact: pact-jvm-consumer-java8_2.11
Show all versions Show documentation Show source 
 

3 downloads
Artifact pact-jvm-consumer-java8_2.11
Group au.com.dius
Version 3.5.24
Last update 04. November 2018
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 8
Dependencies kotlin-stdlib-jdk8, kotlin-reflect, slf4j-api, groovy-all, kotlin-logging, scala-library, scala-logging_2.11, pact-jvm-consumer-junit_2.11,
There are maybe transitive dependencies!

minitest from group rubygems (version 5.4.1)

minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking. "I had a class with Jim Weirich on testing last week and we were allowed to choose our testing frameworks. Kirk Haines and I were paired up and we cracked open the code for a few test frameworks... I MUST say that minitest is *very* readable / understandable compared to the 'other two' options we looked at. Nicely done and thank you for helping us keep our mental sanity." -- Wayne E. Seguin minitest/unit is a small and incredibly fast unit testing framework. It provides a rich set of assertions to make your tests clean and readable. minitest/spec is a functionally complete spec engine. It hooks onto minitest/unit and seamlessly bridges test assertions over to spec expectations. minitest/benchmark is an awesome way to assert the performance of your algorithms in a repeatable manner. Now you can assert that your newb co-worker doesn't replace your linear algorithm with an exponential one! minitest/mock by Steven Baker, is a beautifully tiny mock (and stub) object framework. minitest/pride shows pride in testing and adds coloring to your test output. I guess it is an example of how to write IO pipes too. :P minitest/unit is meant to have a clean implementation for language implementors that need a minimal set of methods to bootstrap a working test suite. For example, there is no magic involved for test-case discovery. "Again, I can't praise enough the idea of a testing/specing framework that I can actually read in full in one sitting!" -- Piotr Szotkowski Comparing to rspec: rspec is a testing DSL. minitest is ruby. -- Adam Hawkins, "Bow Before MiniTest" minitest doesn't reinvent anything that ruby already provides, like: classes, modules, inheritance, methods. This means you only have to learn ruby to use minitest and all of your regular OO practices like extract-method refactorings still apply.

Group: rubygems Artifact: minitest
There is no JAR file uploaded. A download is not possible! Please choose another version.
0 downloads
Artifact minitest
Group rubygems
Version 5.4.1
Last update 28. March 2015
Organization not specified
URL https://github.com/seattlerb/minitest
License MIT
Dependencies amount 0
Dependencies No dependencies
There are maybe transitive dependencies!

alphatier from group io.alphatier (version 0.3.0)

Alphatier is a resource management library. It is designed to allow different schedulers to share the resources of a pool of executors in order to execute tasks with those. Read the [detailed documentation](#io.alphatier.pools) below to get an in-depth understanding. ## License Copyright &copy; 2014 [Tobias Sarnowski](mailto:[email protected]), [Willi Schönborn](mailto:[email protected]) Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ## Usage The library is written in [Clojure](http://clojure.org/) and is available in the [central Maven repository](https://repo1.maven.org/maven2/io/alphatier/alphatier/): <dependency> <groupId>io.alphatier</groupId> <artifactId>alphatier</artifactId> <version>0.3.0</version> </dependency> The library is written in pure Clojure without [ahead-of-time compilation](http://clojure.org/compilation). This means, that the library does not contain any *.class files. If you work with Clojure, this is not a problem but if you like to use the library from another JVM language (like Java, Scala or Groovy), you can use [Clojure's built-in tools](http://clojure.org/java_interop#Java%20Interop-Calling%20Clojure%20From%20Java) for interoperability or try our Java library: [https://github.com/sarnowski/alphatier-java](https://github.com/sarnowski/alphatier-java) ### Development If you like to change this library, please have a look at the [README](README.md). Development is done via [Github](https://github.com/sarnowski/alphatier).

Group: io.alphatier Artifact: alphatier
Show all versions 
 

0 downloads
Artifact alphatier
Group io.alphatier
Version 0.3.0
Last update 16. October 2014
Organization not specified
URL http://alphatier.io
License ISC License
Dependencies amount 3
Dependencies clojure, core.incubator, core.typed,
There are maybe transitive dependencies!

java8 from group au.com.dius.pact.consumer (version 4.1.42)

# pact-jvm-consumer-java8 Provides a Java8 lambda based DSL for use with Junit to build consumer tests. ## Dependency The library is available on maven central using: * group-id = `au.com.dius.pact.consumer` * artifact-id = `java8` * version-id = `4.1.x` # A Lambda DSL for Pact This is an extension for the pact DSL provided by [consumer](../consumer). The difference between the default pact DSL and this lambda DSL is, as the name suggests, the usage of lambdas. The use of lambdas makes the code much cleaner. ## Why a new DSL implementation? The lambda DSL solves the following two main issues. Both are visible in the following code sample: ```java new PactDslJsonArray() .array() # open an array .stringValue(&quot;a1&quot;) # choose the method that is valid for arrays .stringValue(&quot;a2&quot;) # choose the method that is valid for arrays .closeArray() # close the array .array() # open an array .numberValue(1) # choose the method that is valid for arrays .numberValue(2) # choose the method that is valid for arrays .closeArray() # close the array .array() # open an array .object() # now we work with an object .stringValue(&quot;foo&quot;, &quot;Foo&quot;) # choose the method that is valid for objects .closeObject() # close the object and we&apos;re back in the array .closeArray() # close the array ``` ### The existing DSL is quite error-prone Methods may only be called in certain states. For example `object()` may only be called when you&apos;re currently working on an array whereas `object(name)` is only allowed to be called when working on an object. But both of the methods are available. You&apos;ll find out at runtime if you&apos;re using the correct method. Finally, the need for opening and closing objects and arrays makes usage cumbersome. The lambda DSL has no ambiguous methods and there&apos;s no need to close objects and arrays as all the work on such an object is wrapped in a lamda call. ### The existing DSL is hard to read When formatting your source code with an IDE the code becomes hard to read as there&apos;s no indentation possible. Of course, you could do it by hand but we want auto formatting! Auto formatting works great for the new DSL! ```java array.object((o) -&gt; { o.stringValue(&quot;foo&quot;, &quot;Foo&quot;); # an attribute o.stringValue(&quot;bar&quot;, &quot;Bar&quot;); # an attribute o.object(&quot;tar&quot;, (tarObject) -&gt; { # an attribute with a nested object tarObject.stringValue(&quot;a&quot;, &quot;A&quot;); # attribute of the nested object tarObject.stringValue(&quot;b&quot;, &quot;B&quot;); # attribute of the nested object }) }); ``` ## Installation ### Maven ``` &lt;dependency&gt; &lt;groupId&gt;au.com.dius.pact.consumer&lt;/groupId&gt; &lt;artifactId&gt;java8&lt;/artifactId&gt; &lt;version&gt;${pact.version}&lt;/version&gt; &lt;/dependency&gt; ``` ## Usage Start with a static import of `LambdaDsl`. This class contains factory methods for the lambda dsl extension. When you come accross the `body()` method of `PactDslWithProvider` builder start using the new extensions. The call to `LambdaDsl` replaces the call to instance `new PactDslJsonArray()` and `new PactDslJsonBody()` of the pact library. ```java io.pactfoundation.consumer.dsl.LambdaDsl.* ``` ### Response body as json array ```java import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonArray; ... PactDslWithProvider builder = ... builder.given(&quot;some state&quot;) .uponReceiving(&quot;a request&quot;) .path(&quot;/my-app/my-service&quot;) .method(&quot;GET&quot;) .willRespondWith() .status(200) .body(newJsonArray((a) -&gt; { a.stringValue(&quot;a1&quot;); a.stringValue(&quot;a2&quot;); }).build()); ``` ### Response body as json object ```java import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody; ... PactDslWithProvider builder = ... builder.given(&quot;some state&quot;) .uponReceiving(&quot;a request&quot;) .path(&quot;/my-app/my-service&quot;) .method(&quot;GET&quot;) .willRespondWith() .status(200) .body(newJsonBody((o) -&gt; { o.stringValue(&quot;foo&quot;, &quot;Foo&quot;); o.stringValue(&quot;bar&quot;, &quot;Bar&quot;); }).build()); ``` ### Examples #### Simple Json object When creating simple json structures the difference between the two approaches isn&apos;t big. ##### JSON ```json { &quot;bar&quot;: &quot;Bar&quot;, &quot;foo&quot;: &quot;Foo&quot; } ``` ##### Pact DSL ```java new PactDslJsonBody() .stringValue(&quot;foo&quot;, &quot;Foo&quot;) .stringValue(&quot;bar&quot;, &quot;Bar&quot;) ``` ##### Lambda DSL ```java newJsonBody((o) -&gt; { o.stringValue(&quot;foo&quot;, &quot;Foo&quot;); o.stringValue(&quot;bar&quot;, &quot;Bar&quot;); }).build(); ``` #### An array of arrays When we come to more complex constructs with arrays and nested objects the beauty of lambdas become visible! ##### JSON ```json [ [&quot;a1&quot;, &quot;a2&quot;], [1, 2], [{&quot;foo&quot;: &quot;Foo&quot;}] ] ``` ##### Pact DSL ```java new PactDslJsonArray() .array() .stringValue(&quot;a1&quot;) .stringValue(&quot;a2&quot;) .closeArray() .array() .numberValue(1) .numberValue(2) .closeArray() .array() .object() .stringValue(&quot;foo&quot;, &quot;Foo&quot;) .closeObject() .closeArray(); ``` ##### Lambda DSL ```java newJsonArray((rootArray) -&gt; { rootArray.array((a) -&gt; a.stringValue(&quot;a1&quot;).stringValue(&quot;a2&quot;)); rootArray.array((a) -&gt; a.numberValue(1).numberValue(2)); rootArray.array((a) -&gt; a.object((o) -&gt; o.stringValue(&quot;foo&quot;, &quot;Foo&quot;))); }).build(); ``` ##### Kotlin Lambda DSL ```kotlin newJsonArray { newArray { stringValue(&quot;a1&quot;) stringValue(&quot;a2&quot;) } newArray { numberValue(1) numberValue(2) } newArray { newObject { stringValue(&quot;foo&quot;, &quot;Foo&quot;) } } } ``` # Test Analytics We are tracking anonymous analytics to gather important usage statistics like JVM version and operating system. To disable tracking, set the &apos;pact_do_not_track&apos; system property or environment variable to &apos;true&apos;.

Group: au.com.dius.pact.consumer Artifact: java8
Show all versions Show documentation Show source 
 

0 downloads
Artifact java8
Group au.com.dius.pact.consumer
Version 4.1.42
Last update 28. July 2023
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 1
Dependencies consumer,
There are maybe transitive dependencies!

pact-jvm-provider-maven_2.11 from group au.com.dius (version 3.5.24)

Maven plugin to verify a provider ================================= Maven plugin for verifying pacts against a provider. The Maven plugin provides a `verify` goal which will verify all configured pacts against your provider. ## To Use It ### 1. Add the pact-jvm-provider-maven plugin to your `build` section of your pom file. ```xml &lt;build&gt; [...] &lt;plugins&gt; [...] &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;/plugin&gt; [...] &lt;/plugins&gt; [...] &lt;/build&gt; ``` ### 2. Define the pacts between your consumers and providers You define all the providers and consumers within the configuration element of the maven plugin. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;!-- You can define as many as you need, but each must have a unique name --&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;!-- All the provider properties are optional, and have sensible defaults (shown below) --&gt; &lt;protocol&gt;http&lt;/protocol&gt; &lt;host&gt;localhost&lt;/host&gt; &lt;port&gt;8080&lt;/port&gt; &lt;path&gt;/&lt;/path&gt; &lt;consumers&gt; &lt;!-- Again, you can define as many consumers for each provider as you need, but each must have a unique name --&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;!-- currently supports a file path using pactFile or a URL using pactUrl --&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### 3. Execute `mvn pact:verify` You will have to have your provider running for this to pass. ## Verifying all pact files in a directory for a provider You can specify a directory that contains pact files, and the Pact plugin will scan for all pact files that match that provider and define a consumer for each pact file in the directory. Consumer name is read from contents of pact file. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;!-- You can define as many as you need, but each must have a unique name --&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;!-- All the provider properties are optional, and have sensible defaults (shown below) --&gt; &lt;protocol&gt;http&lt;/protocol&gt; &lt;host&gt;localhost&lt;/host&gt; &lt;port&gt;8080&lt;/port&gt; &lt;path&gt;/&lt;/path&gt; &lt;pactFileDirectory&gt;path/to/pacts&lt;/pactFileDirectory&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### Verifying all pact files from multiple directories for a provider [3.5.18+] If you want to specify multiple directories, you can use `pactFileDirectories`. The plugin will only fail the build if no pact files are loaded after processing all the directories in the list. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.18&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;pactFileDirectories&gt; &lt;pactFileDirectory&gt;path/to/pacts1&lt;/pactFileDirectory&gt; &lt;pactFileDirectory&gt;path/to/pacts2&lt;/pactFileDirectory&gt; &lt;/pactFileDirectories&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Enabling insecure SSL For providers that are running on SSL with self-signed certificates, you need to enable insecure SSL mode by setting `&lt;insecure&gt;true&lt;/insecure&gt;` on the provider. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;pactFileDirectory&gt;path/to/pacts&lt;/pactFileDirectory&gt; &lt;insecure&gt;true&lt;/insecure&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Specifying a custom trust store For environments that are running their own certificate chains: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;pactFileDirectory&gt;path/to/pacts&lt;/pactFileDirectory&gt; &lt;trustStore&gt;relative/path/to/trustStore.jks&lt;/trustStore&gt; &lt;trustStorePassword&gt;changeit&lt;/trustStorePassword&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` `trustStore` is either relative to the current working (build) directory. `trustStorePassword` defaults to `changeit`. NOTE: The hostname will still be verified against the certificate. ## Modifying the requests before they are sent Sometimes you may need to add things to the requests that can&apos;t be persisted in a pact file. Examples of these would be authentication tokens, which have a small life span. The Pact Maven plugin provides a request filter that can be set to a Groovy script on the provider that will be called before the request is made. This script will receive the HttpRequest bound to a variable named `request` prior to it being executed. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;requestFilter&gt; // This is a Groovy script that adds an Authorization header to each request request.addHeader(&apos;Authorization&apos;, &apos;oauth-token eyJhbGciOiJSUzI1NiIsIm...&apos;) &lt;/requestFilter&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` __*Important Note:*__ You should only use this feature for things that can not be persisted in the pact file. By modifying the request, you are potentially modifying the contract from the consumer tests! ## Modifying the HTTP Client Used The default HTTP client is used for all requests to providers (created with a call to `HttpClients.createDefault()`). This can be changed by specifying a closure assigned to createClient on the provider that returns a CloseableHttpClient. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;createClient&gt; // This is a Groovy script that will enable the client to accept self-signed certificates import org.apache.http.ssl.SSLContextBuilder import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.HttpClients HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, { x509Certificates, s -&gt; true }) .build()) .build() &lt;/createClient&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Turning off URL decoding of the paths in the pact file By default the paths loaded from the pact file will be decoded before the request is sent to the provider. To turn this behaviour off, set the system property `pact.verifier.disableUrlPathDecoding` to `true`. __*Important Note:*__ If you turn off the url path decoding, you need to ensure that the paths in the pact files are correctly encoded. The verifier will not be able to make a request with an invalid encoded path. ## Plugin Properties The following plugin properties can be specified with `-Dproperty=value` on the command line or in the configuration section: |Property|Description| |--------|-----------| |pact.showStacktrace|This turns on stacktrace printing for each request. It can help with diagnosing network errors| |pact.showFullDiff|This turns on displaying the full diff of the expected versus actual bodies| |pact.filter.consumers|Comma separated list of consumer names to verify| |pact.filter.description|Only verify interactions whose description match the provided regular expression| |pact.filter.providerState|Only verify interactions whose provider state match the provided regular expression. An empty string matches interactions that have no state| |pact.verifier.publishResults|Publishing of verification results will be skipped unless this property is set to &apos;true&apos; [version 3.5.18+]| |pact.matching.wildcard|Enables matching of map values ignoring the keys when this property is set to &apos;true&apos;| Example in the configuration section: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;configuration&gt; &lt;pact.showStacktrace&gt;true&lt;/pact.showStacktrace&gt; &lt;/configuration&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Provider States For each provider you can specify a state change URL to use to switch the state of the provider. This URL will receive the providerState description and parameters from the pact file before each interaction via a POST. The stateChangeUsesBody controls if the state is passed in the request body or as query parameters. These values can be set at the provider level, or for a specific consumer. Consumer values take precedent if both are given. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;stateChangeUsesBody&gt;false&lt;/stateChangeUsesBody&gt; &lt;!-- defaults to true --&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChangeForConsumer1&lt;/stateChangeUrl&gt; &lt;stateChangeUsesBody&gt;false&lt;/stateChangeUsesBody&gt; &lt;!-- defaults to true --&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` If the `stateChangeUsesBody` is not specified, or is set to true, then the provider state description and parameters will be sent as JSON in the body of the request. If it is set to false, they will passed as query parameters. As for normal requests (see Modifying the requests before they are sent), a state change request can be modified before it is sent. Set `stateChangeRequestFilter` to a Groovy script on the provider that will be called before the request is made. #### Teardown calls for state changes You can enable teardown state change calls by setting the property `&lt;stateChangeTeardown&gt;true&lt;/stateChangeTeardown&gt;` on the provider. This will add an `action` parameter to the state change call. The setup call before the test will receive `action=setup`, and then a teardown call will be made afterwards to the state change URL with `action=teardown`. ## Verifying pact files from a pact broker You can setup your build to validate against the pacts stored in a pact broker. The pact plugin will query the pact broker for all consumers that have a pact with the provider based on its name. To use it, just configure the `pactBrokerUrl` or `pactBroker` value for the provider with the base URL to the pact broker. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBrokerUrl&gt;http://pact-broker:5000/&lt;/pactBrokerUrl&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### Verifying pacts from an authenticated pact broker If your pact broker requires authentication (basic authentication is only supported), you can configure the username and password to use by configuring the `authentication` element of the `pactBroker` element of your provider. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBroker&gt; &lt;url&gt;http://pactbroker:1234&lt;/url&gt; &lt;authentication&gt; &lt;username&gt;test&lt;/username&gt; &lt;password&gt;test&lt;/password&gt; &lt;/authentication&gt; &lt;/pactBroker&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` #### Using the Maven servers configuration [version 3.5.6+] From version 3.5.6, you can use the servers setup in the Maven settings. To do this, setup a server as per the [Maven Server Settings](https://maven.apache.org/settings.html#Servers). Then set the server ID in the pact broker configuration in your POM. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.6&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBroker&gt; &lt;url&gt;http://pactbroker:1234&lt;/url&gt; &lt;serverId&gt;test-pact-broker&lt;/serverId&gt; &lt;!-- This must match the server id in the maven settings --&gt; &lt;/pactBroker&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### Verifying pacts from an pact broker that match particular tags If your pacts in your pact broker have been tagged, you can set the tags to fetch by configuring the `tags` element of the `pactBroker` element of your provider. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBroker&gt; &lt;url&gt;http://pactbroker:1234&lt;/url&gt; &lt;tags&gt; &lt;tag&gt;TEST&lt;/tag&gt; &lt;tag&gt;DEV&lt;/tag&gt; &lt;/tags&gt; &lt;/pactBroker&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` This example will fetch and validate the pacts for the TEST and DEV tags. ## Filtering the interactions that are verified You can filter the interactions that are run using three properties: `pact.filter.consumers`, `pact.filter.description` and `pact.filter.providerState`. Adding `-Dpact.filter.consumers=consumer1,consumer2` to the command line or configuration section will only run the pact files for those consumers (consumer1 and consumer2). Adding `-Dpact.filter.description=a request for payment.*` will only run those interactions whose descriptions start with &apos;a request for payment&apos;. `-Dpact.filter.providerState=.*payment` will match any interaction that has a provider state that ends with payment, and `-Dpact.filter.providerState=` will match any interaction that does not have a provider state. ## Not failing the build if no pact files are found [version 3.5.19+] By default, if there are no pact files to verify, the plugin will raise an exception. This is to guard against false positives where the build is passing but nothing has been verified due to mis-configuration. To disable this behaviour, set the `failIfNoPactsFound` parameter to `false`. # Verifying a message provider The Maven plugin has been updated to allow invoking test methods that can return the message contents from a message producer. To use it, set the way to invoke the verification to `ANNOTATED_METHOD`. This will allow the pact verification task to scan for test methods that return the message contents. Add something like the following to your maven pom file: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;messageProvider&lt;/name&gt; &lt;verificationType&gt;ANNOTATED_METHOD&lt;/verificationType&gt; &lt;!-- packagesToScan is optional, but leaving it out will result in the entire test classpath being scanned. Set it to the packages where your annotated test method can be found. --&gt; &lt;packagesToScan&gt; &lt;packageToScan&gt;au.com.example.messageprovider.*&lt;/packageToScan&gt; &lt;/packagesToScan&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/messageprovider-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` Now when the pact verify task is run, will look for methods annotated with `@PactVerifyProvider` in the test classpath that have a matching description to what is in the pact file. ```groovy class ConfirmationKafkaMessageBuilderTest { @PactVerifyProvider(&apos;an order confirmation message&apos;) String verifyMessageForOrder() { Order order = new Order() order.setId(10000004) order.setExchange(&apos;ASX&apos;) order.setSecurityCode(&apos;CBA&apos;) order.setPrice(BigDecimal.TEN) order.setUnits(15) order.setGst(new BigDecimal(&apos;15.0&apos;)) odrer.setFees(BigDecimal.TEN) def message = new ConfirmationKafkaMessageBuilder() .withOrder(order) .build() JsonOutput.toJson(message) } } ``` It will then validate that the returned contents matches the contents for the message in the pact file. ## Changing the class path that is scanned By default, the test classpath is scanned for annotated methods. You can override this by setting the `classpathElements` property: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;messageProvider&lt;/name&gt; &lt;verificationType&gt;ANNOTATED_METHOD&lt;/verificationType&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/messageprovider-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;classpathElements&gt; &lt;classpathElement&gt; build/classes/test &lt;/classpathElement&gt; &lt;/classpathElements&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` # Publishing pact files to a pact broker The pact maven plugin provides a `publish` mojo that can publish all pact files in a directory to a pact broker. To use it, you need to add a publish configuration to the POM that defines the directory where the pact files are and the URL to the pact broker. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;pactDirectory&gt;path/to/pact/files&lt;/pactDirectory&gt; &lt;!-- Defaults to ${project.build.directory}/pacts --&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;projectVersion&gt;1.0.100&lt;/projectVersion&gt; &lt;!-- Defaults to ${project.version} --&gt; &lt;trimSnapshot&gt;true&lt;/trimSnapshot&gt; &lt;!-- Defaults to false --&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` You can now execute `mvn pact:publish` to publish the pact files. _NOTE:_ The pact broker requires a version for all published pacts. The `publish` task will use the version of the project by default, but can be overwritten with the `projectVersion` property. Make sure you have set one otherwise the broker will reject the pact files. _NOTE_: By default, the pact broker has issues parsing `SNAPSHOT` versions. You can configure the publisher to automatically remove `-SNAPSHOT` from your version number by setting `trimSnapshot` to true. This setting does not modify non-snapshot versions. You can set any tags that the pacts should be published with by setting the `tags` list property (version 3.5.12+). A common use of this is setting the tag to the current source control branch. This supports using pact with feature branches. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.12&lt;/version&gt; &lt;configuration&gt; &lt;pactDirectory&gt;path/to/pact/files&lt;/pactDirectory&gt; &lt;!-- Defaults to ${project.build.directory}/pacts --&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;projectVersion&gt;1.0.100&lt;/projectVersion&gt; &lt;!-- Defaults to ${project.version} --&gt; &lt;tags&gt; &lt;tag&gt;feature/feature_name&lt;/tag&gt; &lt;/tags&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Publishing to an authenticated pact broker For an authenticated pact broker, you can pass in the credentials with the `pactBrokerUsername` and `pactBrokerPassword` properties. Currently it only supports basic authentication. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;pactBrokerUsername&gt;USERNAME&lt;/pactBrokerUsername&gt; &lt;pactBrokerPassword&gt;PASSWORD&lt;/pactBrokerPassword&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` #### Using the Maven servers configuration [version 3.5.6+] From version 3.5.6, you can use the servers setup in the Maven settings. To do this, setup a server as per the [Maven Server Settings](https://maven.apache.org/settings.html#Servers). Then set the server ID in the pact broker configuration in your POM. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.5.19&lt;/version&gt; &lt;configuration&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;pactBrokerServerId&gt;test-pact-broker&lt;/pactBrokerServerId&gt; &lt;!-- This must match the server id in the maven settings --&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Excluding pacts from being published [version 3.5.19+] You can exclude some of the pact files from being published by providing a list of regular expressions that match against the base names of the pact files. For example: ```groovy pact { publish { pactBrokerUrl = &apos;https://mypactbroker.com&apos; excludes = [ &apos;.*\\-\\d+$&apos; ] // exclude all pact files that end with a dash followed by a number in the name } } ``` ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.19&lt;/version&gt; &lt;configuration&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;excludes&gt; &lt;exclude&gt;.*\\-\\d+$&lt;/exclude&gt; &lt;!-- exclude pact files where the name ends in a dash followed by a number --&gt; &lt;/excludes&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` # Publishing verification results to a Pact Broker [version 3.5.4+] For pacts that are loaded from a Pact Broker, the results of running the verification can be published back to the broker against the URL for the pact. You will be able to then see the result on the Pact Broker home screen. To turn on the verification publishing, set the system property `pact.verifier.publishResults` to `true` in the pact maven plugin, not surefire, configuration. # Enabling other verification reports [version 3.5.20+] By default the verification report is written to the console. You can also enable a JSON or Markdown report by setting the `reports` configuration list. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.20&lt;/version&gt; &lt;configuration&gt; &lt;reports&gt; &lt;report&gt;console&lt;/report&gt; &lt;report&gt;json&lt;/report&gt; &lt;report&gt;markdown&lt;/report&gt; &lt;/reports&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` These reports will be written to `target/reports/pact`.

Group: au.com.dius Artifact: pact-jvm-provider-maven_2.11
Show all versions Show documentation Show source 
 

4 downloads
Artifact pact-jvm-provider-maven_2.11
Group au.com.dius
Version 3.5.24
Last update 04. November 2018
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 12
Dependencies kotlin-stdlib-jdk8, kotlin-reflect, slf4j-api, groovy-all, kotlin-logging, scala-library, scala-logging_2.11, pact-jvm-provider_2.11, maven-plugin-api, maven-plugin-annotations, maven-core, jansi,
There are maybe transitive dependencies!

pact-jvm-provider-maven_2.10 from group au.com.dius (version 2.4.20)

Maven plugin to verify a provider [version 2.1.9+] ================================================== Maven plugin for verifying pacts against a provider. The Maven plugin provides a `verify` goal which will verify all configured pacts against your provider. ## To Use It ### 1. Add the pact-jvm-provider-maven plugin to your `build` section of your pom file. ```xml &lt;build&gt; [...] &lt;plugins&gt; [...] &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;/plugin&gt; [...] &lt;/plugins&gt; [...] &lt;/build&gt; ``` ### 2. Define the pacts between your consumers and providers You define all the providers and consumers within the configuration element of the maven plugin. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;!-- You can define as many as you need, but each must have a unique name --&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;!-- All the provider properties are optional, and have sensible defaults (shown below) --&gt; &lt;protocol&gt;http&lt;/protocol&gt; &lt;host&gt;localhost&lt;/host&gt; &lt;port&gt;8080&lt;/port&gt; &lt;path&gt;/&lt;/path&gt; &lt;consumers&gt; &lt;!-- Again, you can define as many consumers for each provider as you need, but each must have a unique name --&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;!-- currently supports a file path using pactFile or a URL using pactUrl --&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### 3. Execute `mvn pact:verify` You will have to have your provider running for this to pass. ## Verifying all pact files in a directory for a provider. [2.1.10+] You can specify a directory that contains pact files, and the Pact plugin will scan for all pact files that match that provider and define a consumer for each pact file in the directory. Consumer name is read from contents of pact file. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;!-- You can define as many as you need, but each must have a unique name --&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;!-- All the provider properties are optional, and have sensible defaults (shown below) --&gt; &lt;protocol&gt;http&lt;/protocol&gt; &lt;host&gt;localhost&lt;/host&gt; &lt;port&gt;8080&lt;/port&gt; &lt;path&gt;/&lt;/path&gt; &lt;pactFileDirectory&gt;path/to/pacts&lt;/pactFileDirectory&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Enabling insecure SSL [version 2.2.8+] For providers that are running on SSL with self-signed certificates, you need to enable insecure SSL mode by setting `&lt;insecure&gt;true&lt;/insecure&gt;` on the provider. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;pactFileDirectory&gt;path/to/pacts&lt;/pactFileDirectory&gt; &lt;insecure&gt;true&lt;/insecure&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Specifying a custom trust store [version 2.2.8+] For environments that are running their own certificate chains: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;pactFileDirectory&gt;path/to/pacts&lt;/pactFileDirectory&gt; &lt;trustStore&gt;relative/path/to/trustStore.jks&lt;/trustStore&gt; &lt;trustStorePassword&gt;changeit&lt;/trustStorePassword&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` `trustStore` is either relative to the current working (build) directory. `trustStorePassword` defaults to `changeit`. NOTE: The hostname will still be verified against the certificate. ## Modifying the requests before they are sent Sometimes you may need to add things to the requests that can&apos;t be persisted in a pact file. Examples of these would be authentication tokens, which have a small life span. The Pact Maven plugin provides a request filter that can be set to a Groovy script on the provider that will be called before the request is made. This script will receive the HttpRequest bound to a variable named `request` prior to it being executed. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;requestFilter&gt; // This is a Groovy script that adds an Authorization header to each request request.addHeader(&apos;Authorization&apos;, &apos;oauth-token eyJhbGciOiJSUzI1NiIsIm...&apos;) &lt;/requestFilter&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` __*Important Note:*__ You should only use this feature for things that can not be persisted in the pact file. By modifying the request, you are potentially modifying the contract from the consumer tests! ## Modifying the HTTP Client Used [version 2.2.4+] The default HTTP client is used for all requests to providers (created with a call to `HttpClients.createDefault()`). This can be changed by specifying a closure assigned to createClient on the provider that returns a CloseableHttpClient. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;createClient&gt; // This is a Groovy script that will enable the client to accept self-signed certificates import org.apache.http.ssl.SSLContextBuilder import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.HttpClients HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, { x509Certificates, s -&gt; true }) .build()) .build() &lt;/createClient&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Turning off URL decoding of the paths in the pact file [version 3.3.3+] By default the paths loaded from the pact file will be decoded before the request is sent to the provider. To turn this behaviour off, set the system property `pact.verifier.disableUrlPathDecoding` to `true`. __*Important Note:*__ If you turn off the url path decoding, you need to ensure that the paths in the pact files are correctly encoded. The verifier will not be able to make a request with an invalid encoded path. ## Plugin Properties The following plugin properties can be specified with `-Dproperty=value` on the command line or in the configuration section: |Property|Description| |--------|-----------| |pact.showStacktrace|This turns on stacktrace printing for each request. It can help with diagnosing network errors| |pact.showFullDiff|This turns on displaying the full diff of the expected versus actual bodies [version 3.3.6+]| |pact.filter.consumers|Comma seperated list of consumer names to verify| |pact.filter.description|Only verify interactions whose description match the provided regular expression| |pact.filter.providerState|Only verify interactions whose provider state match the provided regular expression. An empty string matches interactions that have no state| Example in the configuration section: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;configuration&gt; &lt;pact.showStacktrace&gt;true&lt;/pact.showStacktrace&gt; &lt;/configuration&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Provider States For each provider you can specify a state change URL to use to switch the state of the provider. This URL will receive the providerState description from the pact file before each interaction via a POST. The stateChangeUsesBody controls if the state is passed in the request body or as a query parameter. These values can be set at the provider level, or for a specific consumer. Consumer values take precedent if both are given. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;stateChangeUsesBody&gt;false&lt;/stateChangeUsesBody&gt; &lt;!-- defaults to true --&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChangeForConsumer1&lt;/stateChangeUrl&gt; &lt;stateChangeUsesBody&gt;false&lt;/stateChangeUsesBody&gt; &lt;!-- defaults to true --&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` If the `stateChangeUsesBody` is not specified, or is set to true, then the provider state description will be sent as JSON in the body of the request. If it is set to false, it will passed as a query parameter. As for normal requests (see Modifying the requests before they are sent), a state change request can be modified before it is sent. Set `stateChangeRequestFilter` to a Groovy script on the provider that will be called before the request is made. #### Teardown calls for state changes [version 3.2.5/2.4.7+] You can enable teardown state change calls by setting the property `&lt;stateChangeTeardown&gt;true&lt;/stateChangeTeardown&gt;` on the provider. This will add an `action` parameter to the state change call. The setup call before the test will receive `action=setup`, and then a teardown call will be made afterwards to the state change URL with `action=teardown`. ## Verifying pact files from a pact broker [version 3.1.1+/2.3.1+] You can setup your build to validate against the pacts stored in a pact broker. The pact plugin will query the pact broker for all consumers that have a pact with the provider based on its name. To use it, just configure the `pactBrokerUrl` or `pactBroker` value for the provider with the base URL to the pact broker. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBrokerUrl&gt;http://pact-broker:5000/&lt;/pactBrokerUrl&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### Verifying pacts from an authenticated pact broker [version 3.3.5+] If your pact broker requires authentication (basic authentication is only supported), you can configure the username and password to use by configuring the `authentication` element of the `pactBroker` element of your provider. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBroker&gt; &lt;url&gt;http://pactbroker:1234&lt;/url&gt; &lt;authentication&gt; &lt;username&gt;test&lt;/username&gt; &lt;password&gt;test&lt;/password&gt; &lt;/authentication&gt; &lt;/pactBroker&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### Verifying pacts from an pact broker that match particular tags [version 3.3.5+] If your pacts in your pact broker have been tagged, you can set the tags to fetch by configuring the `tags` element of the `pactBroker` element of your provider. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBroker&gt; &lt;url&gt;http://pactbroker:1234&lt;/url&gt; &lt;tags&gt; &lt;tag&gt;TEST&lt;/tag&gt; &lt;tag&gt;DEV&lt;/tag&gt; &lt;/tags&gt; &lt;/pactBroker&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` This example will fetch and validate the pacts for the TEST and DEV tags. ## Filtering the interactions that are verified You can filter the interactions that are run using three properties: `pact.filter.consumers`, `pact.filter.description` and `pact.filter.providerState`. Adding `-Dpact.filter.consumers=consumer1,consumer2` to the command line or configuration section will only run the pact files for those consumers (consumer1 and consumer2). Adding `-Dpact.filter.description=a request for payment.*` will only run those interactions whose descriptions start with &apos;a request for payment&apos;. `-Dpact.filter.providerState=.*payment` will match any interaction that has a provider state that ends with payment, and `-Dpact.filter.providerState=` will match any interaction that does not have a provider state. # Verifying a message provider [version 2.2.12+] The Maven plugin has been updated to allow invoking test methods that can return the message contents from a message producer. To use it, set the way to invoke the verification to `ANNOTATED_METHOD`. This will allow the pact verification task to scan for test methods that return the message contents. Add something like the following to your maven pom file: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;messageProvider&lt;/name&gt; &lt;verificationType&gt;ANNOTATED_METHOD&lt;/verificationType&gt; &lt;!-- packagesToScan is optional, but leaving it out will result in the entire test classpath being scanned. Set it to the packages where your annotated test method can be found. --&gt; &lt;packagesToScan&gt; &lt;packageToScan&gt;au.com.example.messageprovider.*&lt;/packageToScan&gt; &lt;/packagesToScan&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/messageprovider-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` Now when the pact verify task is run, will look for methods annotated with `@PactVerifyProvider` in the test classpath that have a matching description to what is in the pact file. ```groovy class ConfirmationKafkaMessageBuilderTest { @PactVerifyProvider(&apos;an order confirmation message&apos;) String verifyMessageForOrder() { Order order = new Order() order.setId(10000004) order.setExchange(&apos;ASX&apos;) order.setSecurityCode(&apos;CBA&apos;) order.setPrice(BigDecimal.TEN) order.setUnits(15) order.setGst(new BigDecimal(&apos;15.0&apos;)) odrer.setFees(BigDecimal.TEN) def message = new ConfirmationKafkaMessageBuilder() .withOrder(order) .build() JsonOutput.toJson(message) } } ``` It will then validate that the returned contents matches the contents for the message in the pact file. ## Changing the class path that is scanned By default, the test classpath is scanned for annotated methods. You can override this by setting the `classpathElements` property: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;messageProvider&lt;/name&gt; &lt;verificationType&gt;ANNOTATED_METHOD&lt;/verificationType&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/messageprovider-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;classpathElements&gt; &lt;classpathElement&gt; build/classes/test &lt;/classpathElement&gt; &lt;/classpathElements&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` # Publishing pact files to a pact broker [version 3.2.0+] The pact maven plugin provides a `publish` mojo that can publish all pact files in a directory to a pact broker. To use it, you need to add a publish configuration to the POM that defines the directory where the pact files are and the URL to the pact broker. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.8&lt;/version&gt; &lt;configuration&gt; &lt;pactDirectory&gt;path/to/pact/files&lt;/pactDirectory&gt; &lt;!-- Defaults to ${project.build.directory}/pacts --&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;projectVersion&gt;1.0.100&lt;/projectVersion&gt; &lt;!-- Defaults to ${project.version} --&gt; &lt;trimSnapshot&gt;true&lt;/trimSnapshot&gt; &lt;!-- Defaults to false --&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` You can now execute `mvn pact:publish` to publish the pact files. _NOTE:_ The pact broker requires a version for all published pacts. The `publish` task will use the version of the project by default, but can be overwritten with the `projectVersion` property. Make sure you have set one otherwise the broker will reject the pact files. _NOTE_: By default, the pact broker has issues parsing `SNAPSHOT` versions. You can configure the publisher to automatically remove `-SNAPSHOT` from your version number by setting `trimSnapshot` to true. This setting does not modify non-snapshot versions. ## Publishing to an authenticated pact broker [version 3.3.9+] For an authenticated pact broker, you can pass in the credentials with the `pactBrokerUsername` and `pactBrokerPassword` properties. Currently it only supports basic authentication. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.3.9&lt;/version&gt; &lt;configuration&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;pactBrokerUsername&gt;USERNAME&lt;/pactBrokerUsername&gt; &lt;pactBrokerPassword&gt;PASSWORD&lt;/pactBrokerPassword&gt; &lt;/configuration&gt; &lt;/plugin&gt; ```

Group: au.com.dius Artifact: pact-jvm-provider-maven_2.10
Show all versions Show documentation Show source 
 

0 downloads
Artifact pact-jvm-provider-maven_2.10
Group au.com.dius
Version 2.4.20
Last update 14. April 2018
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 6
Dependencies slf4j-api, scala-library, pact-jvm-provider_2.10, groovy-all, maven-plugin-api, maven-plugin-annotations,
There are maybe transitive dependencies!

pact-jvm-provider-maven_2.12 from group au.com.dius (version 3.6.15)

Maven plugin to verify a provider ================================= Maven plugin for verifying pacts against a provider. The Maven plugin provides a `verify` goal which will verify all configured pacts against your provider. ## To Use It ### 1. Add the pact-jvm-provider-maven plugin to your `build` section of your pom file. ```xml &lt;build&gt; [...] &lt;plugins&gt; [...] &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;/plugin&gt; [...] &lt;/plugins&gt; [...] &lt;/build&gt; ``` ### 2. Define the pacts between your consumers and providers You define all the providers and consumers within the configuration element of the maven plugin. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;!-- You can define as many as you need, but each must have a unique name --&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;!-- All the provider properties are optional, and have sensible defaults (shown below) --&gt; &lt;protocol&gt;http&lt;/protocol&gt; &lt;host&gt;localhost&lt;/host&gt; &lt;port&gt;8080&lt;/port&gt; &lt;path&gt;/&lt;/path&gt; &lt;consumers&gt; &lt;!-- Again, you can define as many consumers for each provider as you need, but each must have a unique name --&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;!-- currently supports a file path using pactFile or a URL using pactUrl --&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### 3. Execute `mvn pact:verify` You will have to have your provider running for this to pass. ## Verifying all pact files in a directory for a provider You can specify a directory that contains pact files, and the Pact plugin will scan for all pact files that match that provider and define a consumer for each pact file in the directory. Consumer name is read from contents of pact file. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;!-- You can define as many as you need, but each must have a unique name --&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;!-- All the provider properties are optional, and have sensible defaults (shown below) --&gt; &lt;protocol&gt;http&lt;/protocol&gt; &lt;host&gt;localhost&lt;/host&gt; &lt;port&gt;8080&lt;/port&gt; &lt;path&gt;/&lt;/path&gt; &lt;pactFileDirectory&gt;path/to/pacts&lt;/pactFileDirectory&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### Verifying all pact files from multiple directories for a provider [3.5.18+] If you want to specify multiple directories, you can use `pactFileDirectories`. The plugin will only fail the build if no pact files are loaded after processing all the directories in the list. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.18&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;pactFileDirectories&gt; &lt;pactFileDirectory&gt;path/to/pacts1&lt;/pactFileDirectory&gt; &lt;pactFileDirectory&gt;path/to/pacts2&lt;/pactFileDirectory&gt; &lt;/pactFileDirectories&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Enabling insecure SSL For providers that are running on SSL with self-signed certificates, you need to enable insecure SSL mode by setting `&lt;insecure&gt;true&lt;/insecure&gt;` on the provider. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;pactFileDirectory&gt;path/to/pacts&lt;/pactFileDirectory&gt; &lt;insecure&gt;true&lt;/insecure&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Specifying a custom trust store For environments that are running their own certificate chains: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;pactFileDirectory&gt;path/to/pacts&lt;/pactFileDirectory&gt; &lt;trustStore&gt;relative/path/to/trustStore.jks&lt;/trustStore&gt; &lt;trustStorePassword&gt;changeit&lt;/trustStorePassword&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` `trustStore` is either relative to the current working (build) directory. `trustStorePassword` defaults to `changeit`. NOTE: The hostname will still be verified against the certificate. ## Modifying the requests before they are sent Sometimes you may need to add things to the requests that can&apos;t be persisted in a pact file. Examples of these would be authentication tokens, which have a small life span. The Pact Maven plugin provides a request filter that can be set to a Groovy script on the provider that will be called before the request is made. This script will receive the HttpRequest bound to a variable named `request` prior to it being executed. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;requestFilter&gt; // This is a Groovy script that adds an Authorization header to each request request.addHeader(&apos;Authorization&apos;, &apos;oauth-token eyJhbGciOiJSUzI1NiIsIm...&apos;) &lt;/requestFilter&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` __*Important Note:*__ You should only use this feature for things that can not be persisted in the pact file. By modifying the request, you are potentially modifying the contract from the consumer tests! ## Modifying the HTTP Client Used The default HTTP client is used for all requests to providers (created with a call to `HttpClients.createDefault()`). This can be changed by specifying a closure assigned to createClient on the provider that returns a CloseableHttpClient. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;createClient&gt; // This is a Groovy script that will enable the client to accept self-signed certificates import org.apache.http.ssl.SSLContextBuilder import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.HttpClients HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, { x509Certificates, s -&gt; true }) .build()) .build() &lt;/createClient&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Turning off URL decoding of the paths in the pact file By default the paths loaded from the pact file will be decoded before the request is sent to the provider. To turn this behaviour off, set the system property `pact.verifier.disableUrlPathDecoding` to `true`. __*Important Note:*__ If you turn off the url path decoding, you need to ensure that the paths in the pact files are correctly encoded. The verifier will not be able to make a request with an invalid encoded path. ## Plugin Properties The following plugin properties can be specified with `-Dproperty=value` on the command line or in the configuration section: |Property|Description| |--------|-----------| |pact.showStacktrace|This turns on stacktrace printing for each request. It can help with diagnosing network errors| |pact.showFullDiff|This turns on displaying the full diff of the expected versus actual bodies| |pact.filter.consumers|Comma separated list of consumer names to verify| |pact.filter.description|Only verify interactions whose description match the provided regular expression| |pact.filter.providerState|Only verify interactions whose provider state match the provided regular expression. An empty string matches interactions that have no state| |pact.verifier.publishResults|Publishing of verification results will be skipped unless this property is set to `true` [version 3.5.18+]| |pact.matching.wildcard|Enables matching of map values ignoring the keys when this property is set to `true`| |pact.verifier.disableUrlPathDecoding|Disables decoding of request paths| |pact.pactbroker.httpclient.usePreemptiveAuthentication|Enables preemptive authentication with the pact broker when set to `true`| |`pact.consumer.tags`|Overrides the tags used when publishing pacts [version 4.0.7+]| Example in the configuration section: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;configuration&gt; &lt;pact.showStacktrace&gt;true&lt;/pact.showStacktrace&gt; &lt;/configuration&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Provider States For each provider you can specify a state change URL to use to switch the state of the provider. This URL will receive the providerState description and parameters from the pact file before each interaction via a POST. The stateChangeUsesBody controls if the state is passed in the request body or as query parameters. These values can be set at the provider level, or for a specific consumer. Consumer values take precedent if both are given. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;stateChangeUsesBody&gt;false&lt;/stateChangeUsesBody&gt; &lt;!-- defaults to true --&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/provider1-consumer1-pact.json&lt;/pactFile&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChangeForConsumer1&lt;/stateChangeUrl&gt; &lt;stateChangeUsesBody&gt;false&lt;/stateChangeUsesBody&gt; &lt;!-- defaults to true --&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` If the `stateChangeUsesBody` is not specified, or is set to true, then the provider state description and parameters will be sent as JSON in the body of the request. If it is set to false, they will passed as query parameters. As for normal requests (see Modifying the requests before they are sent), a state change request can be modified before it is sent. Set `stateChangeRequestFilter` to a Groovy script on the provider that will be called before the request is made. #### Teardown calls for state changes You can enable teardown state change calls by setting the property `&lt;stateChangeTeardown&gt;true&lt;/stateChangeTeardown&gt;` on the provider. This will add an `action` parameter to the state change call. The setup call before the test will receive `action=setup`, and then a teardown call will be made afterwards to the state change URL with `action=teardown`. #### Returning values that can be injected (3.6.11+) You can have values from the provider state callbacks be injected into most places (paths, query parameters, headers, bodies, etc.). This works by using the V3 spec generators with provider state callbacks that return values. One example of where this would be useful is API calls that require an ID which would be auto-generated by the database on the provider side, so there is no way to know what the ID would be beforehand. There are methods on the consumer DSLs that can provider an expression that contains variables (like &apos;/api/user/${id}&apos; for the path). The provider state callback can then return a map for values, and the `id` attribute from the map will be expanded in the expression. For URL callbacks, the values need to be returned as JSON in the response body. ## Verifying pact files from a pact broker You can setup your build to validate against the pacts stored in a pact broker. The pact plugin will query the pact broker for all consumers that have a pact with the provider based on its name. To use it, just configure the `pactBrokerUrl` or `pactBroker` value for the provider with the base URL to the pact broker. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBrokerUrl&gt;http://pact-broker:5000/&lt;/pactBrokerUrl&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### Verifying pacts from an authenticated pact broker If your pact broker requires authentication (basic authentication is only supported), you can configure the username and password to use by configuring the `authentication` element of the `pactBroker` element of your provider. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBroker&gt; &lt;url&gt;http://pactbroker:1234&lt;/url&gt; &lt;authentication&gt; &lt;username&gt;test&lt;/username&gt; &lt;password&gt;test&lt;/password&gt; &lt;/authentication&gt; &lt;/pactBroker&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` Preemptive Authentication can be enabled by setting the `pact.pactbroker.httpclient.usePreemptiveAuthentication` Java system property to `true`. #### Using the Maven servers configuration [version 3.5.6+] From version 3.5.6, you can use the servers setup in the Maven settings. To do this, setup a server as per the [Maven Server Settings](https://maven.apache.org/settings.html#Servers). Then set the server ID in the pact broker configuration in your POM. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.6&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBroker&gt; &lt;url&gt;http://pactbroker:1234&lt;/url&gt; &lt;serverId&gt;test-pact-broker&lt;/serverId&gt; &lt;!-- This must match the server id in the maven settings --&gt; &lt;/pactBroker&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ### Verifying pacts from an pact broker that match particular tags If your pacts in your pact broker have been tagged, you can set the tags to fetch by configuring the `tags` element of the `pactBroker` element of your provider. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;provider1&lt;/name&gt; &lt;stateChangeUrl&gt;http://localhost:8080/tasks/pactStateChange&lt;/stateChangeUrl&gt; &lt;pactBroker&gt; &lt;url&gt;http://pactbroker:1234&lt;/url&gt; &lt;tags&gt; &lt;tag&gt;TEST&lt;/tag&gt; &lt;tag&gt;DEV&lt;/tag&gt; &lt;/tags&gt; &lt;/pactBroker&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` This example will fetch and validate the pacts for the TEST and DEV tags. ## Filtering the interactions that are verified You can filter the interactions that are run using three properties: `pact.filter.consumers`, `pact.filter.description` and `pact.filter.providerState`. Adding `-Dpact.filter.consumers=consumer1,consumer2` to the command line or configuration section will only run the pact files for those consumers (consumer1 and consumer2). Adding `-Dpact.filter.description=a request for payment.*` will only run those interactions whose descriptions start with &apos;a request for payment&apos;. `-Dpact.filter.providerState=.*payment` will match any interaction that has a provider state that ends with payment, and `-Dpact.filter.providerState=` will match any interaction that does not have a provider state. ## Not failing the build if no pact files are found [version 3.5.19+] By default, if there are no pact files to verify, the plugin will raise an exception. This is to guard against false positives where the build is passing but nothing has been verified due to mis-configuration. To disable this behaviour, set the `failIfNoPactsFound` parameter to `false`. # Verifying a message provider The Maven plugin has been updated to allow invoking test methods that can return the message contents from a message producer. To use it, set the way to invoke the verification to `ANNOTATED_METHOD`. This will allow the pact verification task to scan for test methods that return the message contents. Add something like the following to your maven pom file: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;messageProvider&lt;/name&gt; &lt;verificationType&gt;ANNOTATED_METHOD&lt;/verificationType&gt; &lt;!-- packagesToScan is optional, but leaving it out will result in the entire test classpath being scanned. Set it to the packages where your annotated test method can be found. --&gt; &lt;packagesToScan&gt; &lt;packageToScan&gt;au.com.example.messageprovider.*&lt;/packageToScan&gt; &lt;/packagesToScan&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/messageprovider-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` Now when the pact verify task is run, will look for methods annotated with `@PactVerifyProvider` in the test classpath that have a matching description to what is in the pact file. ```groovy class ConfirmationKafkaMessageBuilderTest { @PactVerifyProvider(&apos;an order confirmation message&apos;) String verifyMessageForOrder() { Order order = new Order() order.setId(10000004) order.setExchange(&apos;ASX&apos;) order.setSecurityCode(&apos;CBA&apos;) order.setPrice(BigDecimal.TEN) order.setUnits(15) order.setGst(new BigDecimal(&apos;15.0&apos;)) odrer.setFees(BigDecimal.TEN) def message = new ConfirmationKafkaMessageBuilder() .withOrder(order) .build() JsonOutput.toJson(message) } } ``` It will then validate that the returned contents matches the contents for the message in the pact file. ## Changing the class path that is scanned By default, the test classpath is scanned for annotated methods. You can override this by setting the `classpathElements` property: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;serviceProviders&gt; &lt;serviceProvider&gt; &lt;name&gt;messageProvider&lt;/name&gt; &lt;verificationType&gt;ANNOTATED_METHOD&lt;/verificationType&gt; &lt;consumers&gt; &lt;consumer&gt; &lt;name&gt;consumer1&lt;/name&gt; &lt;pactFile&gt;path/to/messageprovider-consumer1-pact.json&lt;/pactFile&gt; &lt;/consumer&gt; &lt;/consumers&gt; &lt;/serviceProvider&gt; &lt;/serviceProviders&gt; &lt;classpathElements&gt; &lt;classpathElement&gt; build/classes/test &lt;/classpathElement&gt; &lt;/classpathElements&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` # Publishing pact files to a pact broker The pact maven plugin provides a `publish` mojo that can publish all pact files in a directory to a pact broker. To use it, you need to add a publish configuration to the POM that defines the directory where the pact files are and the URL to the pact broker. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;pactDirectory&gt;path/to/pact/files&lt;/pactDirectory&gt; &lt;!-- Defaults to ${project.build.directory}/pacts --&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;projectVersion&gt;1.0.100&lt;/projectVersion&gt; &lt;!-- Defaults to ${project.version} --&gt; &lt;trimSnapshot&gt;true&lt;/trimSnapshot&gt; &lt;!-- Defaults to false --&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` You can now execute `mvn pact:publish` to publish the pact files. _NOTE:_ The pact broker requires a version for all published pacts. The `publish` task will use the version of the project by default, but can be overwritten with the `projectVersion` property. Make sure you have set one otherwise the broker will reject the pact files. _NOTE_: By default, the pact broker has issues parsing `SNAPSHOT` versions. You can configure the publisher to automatically remove `-SNAPSHOT` from your version number by setting `trimSnapshot` to true. This setting does not modify non-snapshot versions. You can set any tags that the pacts should be published with by setting the `tags` list property (version 3.5.12+). A common use of this is setting the tag to the current source control branch. This supports using pact with feature branches. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.12&lt;/version&gt; &lt;configuration&gt; &lt;pactDirectory&gt;path/to/pact/files&lt;/pactDirectory&gt; &lt;!-- Defaults to ${project.build.directory}/pacts --&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;projectVersion&gt;1.0.100&lt;/projectVersion&gt; &lt;!-- Defaults to ${project.version} --&gt; &lt;tags&gt; &lt;tag&gt;feature/feature_name&lt;/tag&gt; &lt;/tags&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` You can also specify the tags using the `pact.consumer.tags` Java system property [version 4.0.7+]. ## Publishing to an authenticated pact broker For an authenticated pact broker, you can pass in the credentials with the `pactBrokerUsername` and `pactBrokerPassword` properties. Currently it only supports basic authentication. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;pactBrokerUsername&gt;USERNAME&lt;/pactBrokerUsername&gt; &lt;pactBrokerPassword&gt;PASSWORD&lt;/pactBrokerPassword&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` Or to use a bearer token: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.11&lt;/version&gt; &lt;configuration&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;pactBrokerToken&gt;TOKEN&lt;/pactBrokerToken&gt; &lt;!-- Replace TOKEN with the actual token --&gt; &lt;pactBrokerAuthenticationScheme&gt;Bearer&lt;/pactBrokerAuthenticationScheme&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` #### Using the Maven servers configuration [version 3.5.6+] From version 3.5.6, you can use the servers setup in the Maven settings. To do this, setup a server as per the [Maven Server Settings](https://maven.apache.org/settings.html#Servers). Then set the server ID in the pact broker configuration in your POM. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.11&lt;/artifactId&gt; &lt;version&gt;3.5.19&lt;/version&gt; &lt;configuration&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;pactBrokerServerId&gt;test-pact-broker&lt;/pactBrokerServerId&gt; &lt;!-- This must match the server id in the maven settings --&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` ## Excluding pacts from being published [version 3.5.19+] You can exclude some of the pact files from being published by providing a list of regular expressions that match against the base names of the pact files. For example: ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.19&lt;/version&gt; &lt;configuration&gt; &lt;pactBrokerUrl&gt;http://pactbroker:1234&lt;/pactBrokerUrl&gt; &lt;excludes&gt; &lt;exclude&gt;.*\\-\\d+$&lt;/exclude&gt; &lt;!-- exclude pact files where the name ends in a dash followed by a number --&gt; &lt;/excludes&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` # Publishing verification results to a Pact Broker [version 3.5.4+] For pacts that are loaded from a Pact Broker, the results of running the verification can be published back to the broker against the URL for the pact. You will be able to then see the result on the Pact Broker home screen. To turn on the verification publishing, set the system property `pact.verifier.publishResults` to `true` in the pact maven plugin, not surefire, configuration. # Enabling other verification reports [version 3.5.20+] By default the verification report is written to the console. You can also enable a JSON or Markdown report by setting the `reports` configuration list. ```xml &lt;plugin&gt; &lt;groupId&gt;au.com.dius&lt;/groupId&gt; &lt;artifactId&gt;pact-jvm-provider-maven_2.12&lt;/artifactId&gt; &lt;version&gt;3.5.20&lt;/version&gt; &lt;configuration&gt; &lt;reports&gt; &lt;report&gt;console&lt;/report&gt; &lt;report&gt;json&lt;/report&gt; &lt;report&gt;markdown&lt;/report&gt; &lt;/reports&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` These reports will be written to `target/reports/pact`.

Group: au.com.dius Artifact: pact-jvm-provider-maven_2.12
Show all versions Show documentation Show source 
 

5 downloads
Artifact pact-jvm-provider-maven_2.12
Group au.com.dius
Version 3.6.15
Last update 29. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 7
Dependencies pact-jvm-provider_2.12, maven-plugin-api, maven-plugin-annotations, maven-core, kotlin-stdlib-jdk8, kotlin-reflect, jansi,
There are maybe transitive dependencies!

pact-jvm-provider-gradle_2.12 from group au.com.dius (version 3.6.15)

pact-jvm-provider-gradle ======================== Gradle plugin for verifying pacts against a provider. The Gradle plugin creates a task `pactVerify` to your build which will verify all configured pacts against your provider. ## To Use It ### For Gradle versions prior to 2.1 #### 1.1. Add the pact-jvm-provider-gradle jar file to your build script class path: ```groovy buildscript { repositories { mavenCentral() } dependencies { classpath &apos;au.com.dius:pact-jvm-provider-gradle_2.10:3.2.11&apos; } } ``` #### 1.2. Apply the pact plugin ```groovy apply plugin: &apos;au.com.dius.pact&apos; ``` ### For Gradle versions 2.1+ ```groovy plugins { id &quot;au.com.dius.pact&quot; version &quot;3.2.11&quot; } ``` ### 2. Define the pacts between your consumers and providers ```groovy pact { serviceProviders { // You can define as many as you need, but each must have a unique name provider1 { // All the provider properties are optional, and have sensible defaults (shown below) protocol = &apos;http&apos; host = &apos;localhost&apos; port = 8080 path = &apos;/&apos; // Again, you can define as many consumers for each provider as you need, but each must have a unique name hasPactWith(&apos;consumer1&apos;) { // currently supports a file path using file() or a URL using url() pactSource = file(&apos;path/to/provider1-consumer1-pact.json&apos;) } // Or if you have many pact files in a directory hasPactsWith(&apos;manyConsumers&apos;) { // Will define a consumer for each pact file in the directory. // Consumer name is read from contents of pact file pactFileLocation = file(&apos;path/to/pacts&apos;) } } } } ``` ### 3. Execute `gradle pactVerify` ## Specifying the provider hostname at runtime If you need to calculate the provider hostname at runtime, you can give a Closure as the provider `host`. ```groovy pact { serviceProviders { provider1 { host = { lookupHostName() } hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) } } } } ``` _Since version 3.3.2+/2.4.17+_ you can also give a Closure as the provider `port`. ## Specifying the pact file or URL at runtime [versions 3.2.7/2.4.9+] If you need to calculate the pact file or URL at runtime, you can give a Closure as the provider `pactFile`. ```groovy pact { serviceProviders { provider1 { host = &apos;localhost&apos; hasPactWith(&apos;consumer1&apos;) { pactFile = { lookupPactFile() } } } } } ``` ## Starting and shutting down your provider If you need to start-up or shutdown your provider, define Gradle tasks for each action and set `startProviderTask` and `terminateProviderTask` properties of each provider. You could use the jetty tasks here if you provider is built as a WAR file. ```groovy // This will be called before the provider task task(&apos;startTheApp&apos;) { doLast { // start up your provider here } } // This will be called after the provider task task(&apos;killTheApp&apos;) { doLast { // kill your provider here } } pact { serviceProviders { provider1 { startProviderTask = startTheApp terminateProviderTask = killTheApp hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) } } } } ``` Following typical Gradle behaviour, you can set the provider task properties to the actual tasks, or to the task names as a string (for the case when they haven&apos;t been defined yet). ## Preventing the chaining of provider verify task to `pactVerify` [version 3.4.1+] Normally a gradle task named `pactVerify_${provider.name}` is created and added as a task dependency for `pactVerify`. You can disable this dependency on a provider by setting `isDependencyForPactVerify` to `false` (defaults to `true`). ```groovy pact { serviceProviders { provider1 { isDependencyForPactVerify = false hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) } } } } ``` To run this task, you would then have to explicitly name it as in ```gradle pactVerify_provider1```, a normal ```gradle pactVerify``` would skip it. This can be useful when you want to define two providers, one with `startProviderTask`/`terminateProviderTask` and as second without, so you can manually start your provider (to debug it from your IDE, for example) but still want a `pactVerify` to run normally from your CI build. ## Enabling insecure SSL [version 2.2.8+] For providers that are running on SSL with self-signed certificates, you need to enable insecure SSL mode by setting `insecure = true` on the provider. ```groovy pact { serviceProviders { provider1 { insecure = true // allow SSL with a self-signed cert hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) } } } } ``` ## Specifying a custom trust store [version 2.2.8+] For environments that are running their own certificate chains: ```groovy pact { serviceProviders { provider1 { trustStore = new File(&apos;relative/path/to/trustStore.jks&apos;) trustStorePassword = &apos;changeit&apos; hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) } } } } ``` `trustStore` is either relative to the current working (build) directory. `trustStorePassword` defaults to `changeit`. NOTE: The hostname will still be verified against the certificate. ## Modifying the HTTP Client Used [version 2.2.4+] The default HTTP client is used for all requests to providers (created with a call to `HttpClients.createDefault()`). This can be changed by specifying a closure assigned to createClient on the provider that returns a CloseableHttpClient. For example: ```groovy pact { serviceProviders { provider1 { createClient = { provider -&gt; // This will enable the client to accept self-signed certificates HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, { x509Certificates, s -&gt; true }) .build()) .build() } hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) } } } } ``` ## Modifying the requests before they are sent **NOTE on breaking change: Version 2.1.8+ uses Apache HttpClient instead of HttpBuilder so the closure will receive a HttpRequest object instead of a request Map.** Sometimes you may need to add things to the requests that can&apos;t be persisted in a pact file. Examples of these would be authentication tokens, which have a small life span. The Pact Gradle plugin provides a request filter that can be set to a closure on the provider that will be called before the request is made. This closure will receive the HttpRequest prior to it being executed. ```groovy pact { serviceProviders { provider1 { requestFilter = { req -&gt; // Add an authorization header to each request req.addHeader(&apos;Authorization&apos;, &apos;OAUTH eyJhbGciOiJSUzI1NiIsImN0eSI6ImFw...&apos;) } hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) } } } } ``` __*Important Note:*__ You should only use this feature for things that can not be persisted in the pact file. By modifying the request, you are potentially modifying the contract from the consumer tests! ## Turning off URL decoding of the paths in the pact file [version 3.3.3+] By default the paths loaded from the pact file will be decoded before the request is sent to the provider. To turn this behaviour off, set the system property `pact.verifier.disableUrlPathDecoding` to `true`. __*Important Note:*__ If you turn off the url path decoding, you need to ensure that the paths in the pact files are correctly encoded. The verifier will not be able to make a request with an invalid encoded path. ## Project Properties The following project properties can be specified with `-Pproperty=value` on the command line: |Property|Description| |--------|-----------| |pact.showStacktrace|This turns on stacktrace printing for each request. It can help with diagnosing network errors| |pact.showFullDiff|This turns on displaying the full diff of the expected versus actual bodies [version 3.3.6+]| |pact.filter.consumers|Comma seperated list of consumer names to verify| |pact.filter.description|Only verify interactions whose description match the provided regular expression| |pact.filter.providerState|Only verify interactions whose provider state match the provided regular expression. An empty string matches interactions that have no state| |pact.verifier.publishResults|Publishing of verification results will be skipped unless this property is set to &apos;true&apos;| |pact.matching.wildcard|Enables matching of map values ignoring the keys when this property is set to &apos;true&apos;| |pact.verifier.disableUrlPathDecoding|Disables decoding of request paths| |pact.pactbroker.httpclient.usePreemptiveAuthentication|Enables preemptive authentication with the pact broker when set to `true`| ## Provider States For a description of what provider states are, see the pact documentations: http://docs.pact.io/documentation/provider_states.html ### Using a state change URL For each provider you can specify a state change URL to use to switch the state of the provider. This URL will receive the providerState description and all the parameters from the pact file before each interaction via a POST. As for normal requests, a request filter (`stateChangeRequestFilter`) can also be set to manipulate the request before it is sent. ```groovy pact { serviceProviders { provider1 { hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) stateChangeUrl = url(&apos;http://localhost:8001/tasks/pactStateChange&apos;) stateChangeUsesBody = false // defaults to true stateChangeRequestFilter = { req -&gt; // Add an authorization header to each request req.addHeader(&apos;Authorization&apos;, &apos;OAUTH eyJhbGciOiJSUzI1NiIsImN0eSI6ImFw...&apos;) } } // or hasPactsWith(&apos;consumers&apos;) { pactFileLocation = file(&apos;path/to/pacts&apos;) stateChangeUrl = url(&apos;http://localhost:8001/tasks/pactStateChange&apos;) stateChangeUsesBody = false // defaults to true } } } } ``` If the `stateChangeUsesBody` is not specified, or is set to true, then the provider state description and parameters will be sent as JSON in the body of the request : ```json { &quot;state&quot; : &quot;a provider state description&quot;, &quot;params&quot;: { &quot;a&quot;: &quot;1&quot;, &quot;b&quot;: &quot;2&quot; } } ``` If it is set to false, they will be passed as query parameters. #### Teardown calls for state changes [version 3.2.5/2.4.7+] You can enable teardown state change calls by setting the property `stateChangeTeardown = true` on the provider. This will add an `action` parameter to the state change call. The setup call before the test will receive `action=setup`, and then a teardown call will be made afterwards to the state change URL with `action=teardown`. ### Using a Closure [version 2.2.2+] You can set a closure to be called before each verification with a defined provider state. The closure will be called with the state description and parameters from the pact file. ```groovy pact { serviceProviders { provider1 { hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) // Load a fixture file based on the provider state and then setup some database // data. Does not require a state change request so returns false stateChange = { providerState -&gt; // providerState is an instance of ProviderState def fixture = loadFixtuerForProviderState(providerState) setupDatabase(fixture) } } } } } ``` #### Teardown calls for state changes [version 3.2.5/2.4.7+] You can enable teardown state change calls by setting the property `stateChangeTeardown = true` on the provider. This will add an `action` parameter to the state change closure call. The setup call before the test will receive `setup`, as the second parameter, and then a teardown call will be made afterwards with `teardown` as the second parameter. ```groovy pact { serviceProviders { provider1 { hasPactWith(&apos;consumer1&apos;) { pactFile = file(&apos;path/to/provider1-consumer1-pact.json&apos;) // Load a fixture file based on the provider state and then setup some database // data. Does not require a state change request so returns false stateChange = { providerState, action -&gt; if (action == &apos;setup&apos;) { def fixture = loadFixtuerForProviderState(providerState) setupDatabase(fixture) } else { cleanupDatabase() } false } } } } } ``` #### Returning values that can be injected (3.6.11+) You can have values from the provider state callbacks be injected into most places (paths, query parameters, headers, bodies, etc.). This works by using the V3 spec generators with provider state callbacks that return values. One example of where this would be useful is API calls that require an ID which would be auto-generated by the database on the provider side, so there is no way to know what the ID would be beforehand. There are methods on the consumer DSLs that can provider an expression that contains variables (like &apos;/api/user/${id}&apos; for the path). The provider state callback can then return a map for values, and the `id` attribute from the map will be expanded in the expression. For URL callbacks, the values need to be returned as JSON in the response body. ## Filtering the interactions that are verified You can filter the interactions that are run using three project properties: `pact.filter.consumers`, `pact.filter.description` and `pact.filter.providerState`. Adding `-Ppact.filter.consumers=consumer1,consumer2` to the command line will only run the pact files for those consumers (consumer1 and consumer2). Adding `-Ppact.filter.description=a request for payment.*` will only run those interactions whose descriptions start with &apos;a request for payment&apos;. `-Ppact.filter.providerState=.*payment` will match any interaction that has a provider state that ends with payment, and `-Ppact.filter.providerState=` will match any interaction that does not have a provider state. ## Verifying pact files from a pact broker [version 3.1.1+/2.3.1+] You can setup your build to validate against the pacts stored in a pact broker. The pact gradle plugin will query the pact broker for all consumers that have a pact with the provider based on its name. For example: ```groovy pact { serviceProviders { provider1 { // You can get the latest pacts from the broker hasPactsFromPactBroker(&apos;http://pact-broker:5000/&apos;) // And/or you can get the latest pact with a specific tag hasPactsFromPactBrokerWithTag(&apos;http://pact-broker:5000/&apos;,&quot;tagname&quot;) } } } ``` This will verify all pacts found in the pact broker where the provider name is &apos;provider1&apos;. If you need to set any values on the consumers from the pact broker, you can add a Closure to configure them. ```groovy pact { serviceProviders { provider1 { hasPactsFromPactBroker(&apos;http://pact-broker:5000/&apos;) { consumer -&gt; stateChange = { providerState -&gt; /* state change code here */ true } } } } } ``` **NOTE: Currently the pacts are fetched from the broker during the configuration phase of the build. This means that if the broker is not available, you will not be able to run any Gradle tasks.** This should be fixed in a forth coming release. In the mean time, to only load the pacts when running the validate task, you can do something like: ```groovy pact { serviceProviders { provider1 { // Only load the pacts from the broker if the start tasks from the command line include pactVerify if (&apos;pactVerify&apos; in gradle.startParameter.taskNames) { hasPactsFromPactBroker(&apos;http://pact-broker:5000/&apos;) { consumer -&gt; stateChange = { providerState -&gt; /* state change code here */ true } } } } } } ``` ### Using an authenticated Pact Broker You can add the authentication details for the Pact Broker like so: ```groovy pact { serviceProviders { provider1 { hasPactsFromPactBroker(&apos;http://pact-broker:5000/&apos;, authentication: [&apos;Basic&apos;, pactBrokerUser, pactBrokerPassword]) } } } ``` `pactBrokerUser` and `pactBrokerPassword` can be defined in the gradle properties. Or with a bearer token: ```groovy pact { serviceProviders { provider1 { hasPactsFromPactBroker(&apos;http://pact-broker:5000/&apos;, authentication: [&apos;Bearer&apos;, pactBrokerToken]) } } } ``` Preemptive Authentication can be enabled by setting the `pact.pactbroker.httpclient.usePreemptiveAuthentication` Java system property to `true`. ## Verifying pact files from a S3 bucket [version 3.3.2+/2.4.17+] Pact files stored in an S3 bucket can be verified by using an S3 URL to the pact file. I.e., ```groovy pact { serviceProviders { provider1 { hasPactWith(&apos;consumer1&apos;) { pactFile = &apos;s3://bucketname/path/to/provider1-consumer1-pact.json&apos; } } } } ``` **NOTE:** you can&apos;t use the `url` function with S3 URLs, as the URL and URI classes from the Java SDK don&apos;t support URLs with the s3 scheme. # Publishing pact files to a pact broker [version 2.2.7+] The pact gradle plugin provides a `pactPublish` task that can publish all pact files in a directory to a pact broker. To use it, you need to add a publish configuration to the pact configuration that defines the directory where the pact files are and the URL to the pact broker. For example: ```groovy pact { publish { pactDirectory = &apos;/pact/dir&apos; // defaults to $buildDir/pacts pactBrokerUrl = &apos;http://pactbroker:1234&apos; } } ``` You can set any tags that the pacts should be published with by setting the `tags` property. A common use of this is setting the tag to the current source control branch. This supports using pact with feature branches. ```groovy pact { publish { pactDirectory = &apos;/pact/dir&apos; // defaults to $buildDir/pacts pactBrokerUrl = &apos;http://pactbroker:1234&apos; tags = [project.pactBrokerTag] } } ``` _NOTE:_ The pact broker requires a version for all published pacts. The `pactPublish` task will use the version of the gradle project by default. Make sure you have set one otherwise the broker will reject the pact files. _Version 3.2.2/2.4.3+_ you can override the version in the publish block. ## Publishing to an authenticated pact broker To publish to a broker protected by basic auth, include the username/password in the `pactBrokerUrl`. For example: ```groovy pact { publish { pactBrokerUrl = &apos;https://username:[email protected]&apos; } } ``` ### [version 3.3.9+] You can add the username and password as properties since version 3.3.9+ ```groovy pact { publish { pactBrokerUrl = &apos;https://mypactbroker.com&apos; pactBrokerUsername = &apos;username&apos; pactBrokerPassword = &apos;password&apos; } } ``` or with a bearer token ```groovy pact { publish { pactBrokerUrl = &apos;https://mypactbroker.com&apos; pactBrokerToken = &apos;token&apos; } } ``` ## Excluding pacts from being published [version 3.5.19+] You can exclude some of the pact files from being published by providing a list of regular expressions that match against the base names of the pact files. For example: ```groovy pact { publish { pactBrokerUrl = &apos;https://mypactbroker.com&apos; excludes = [ &apos;.*\\-\\d+$&apos; ] // exclude all pact files that end with a dash followed by a number in the name } } ``` # Verifying a message provider [version 2.2.12+] The Gradle plugin has been updated to allow invoking test methods that can return the message contents from a message producer. To use it, set the way to invoke the verification to `ANNOTATED_METHOD`. This will allow the pact verification task to scan for test methods that return the message contents. Add something like the following to your gradle build file: ```groovy pact { serviceProviders { messageProvider { verificationType = &apos;ANNOTATED_METHOD&apos; packagesToScan = [&apos;au.com.example.messageprovider.*&apos;] // This is optional, but leaving it out will result in the entire // test classpath being scanned hasPactWith(&apos;messageConsumer&apos;) { pactFile = url(&apos;url/to/messagepact.json&apos;) } } } } ``` Now when the `pactVerify` task is run, will look for methods annotated with `@PactVerifyProvider` in the test classpath that have a matching description to what is in the pact file. ```groovy class ConfirmationKafkaMessageBuilderTest { @PactVerifyProvider(&apos;an order confirmation message&apos;) String verifyMessageForOrder() { Order order = new Order() order.setId(10000004) order.setExchange(&apos;ASX&apos;) order.setSecurityCode(&apos;CBA&apos;) order.setPrice(BigDecimal.TEN) order.setUnits(15) order.setGst(new BigDecimal(&apos;15.0&apos;)) order.setFees(BigDecimal.TEN) def message = new ConfirmationKafkaMessageBuilder() .withOrder(order) .build() JsonOutput.toJson(message) } } ``` It will then validate that the returned contents matches the contents for the message in the pact file. ## Publishing to the Gradle Community Portal To publish the plugin to the community portal: $ ./gradlew :pact-jvm-provider-gradle_2.11:publishPlugins # Verification Reports [versions 3.2.7/2.4.9+] The default behaviour is to display the verification being done to the console, and pass or fail the build via the normal Gradle mechanism. From versions 3.2.7/2.4.9+, additional reports can be generated from the verification. ## Enabling additional reports The verification reports can be controlled by adding a reports section to the pact configuration in the gradle build file. For example: ```groovy pact { reports { defaultReports() // adds the standard console output markdown // report in markdown format json // report in json format } } ``` Any report files will be written to &quot;build/reports/pact&quot;. ## Additional Reports The following report types are available in addition to console output (which is enabled by default): `markdown`, `json`. # Publishing verification results to a Pact Broker [version 3.5.4+] For pacts that are loaded from a Pact Broker, the results of running the verification can be published back to the broker against the URL for the pact. You will be able to see the result on the Pact Broker home screen. To turn on the verification publishing, set the project property `pact.verifier.publishResults` to `true` [version 3.5.18+].

Group: au.com.dius Artifact: pact-jvm-provider-gradle_2.12
Show all versions Show documentation Show source 
 

1 downloads
Artifact pact-jvm-provider-gradle_2.12
Group au.com.dius
Version 3.6.15
Last update 29. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 2
Dependencies pact-jvm-provider_2.12, jansi,
There are maybe transitive dependencies!



Page 115 from 116 (items total 1154)


© 2015 - 2024 Weber Informatics LLC | Privacy Policy