au.com.dius:pact-jvm-consumer-groovy_2.11:3.4.0

Group / Artifact / Version au.com.dius / pact-jvm-consumer-groovy_2.11 / 3.4.0
Namepact-jvm-consumer-groovy_2.11
Descriptionpact-jvm-consumer-groovy ========================= Groovy DSL for Pact JVM ##Dependency The library is available on maven central using: * group-id = `au.com.dius` * artifact-id = `pact-jvm-consumer-groovy_2.11` * version-id = `2.4.x` or `3.3.x` ##Usage Add the `pact-jvm-consumer-groovy` library to your test class path. This provides a `PactBuilder` class for you to use to define your pacts. For a full example, have a look at the example JUnit `ExampleGroovyConsumerPactTest`. If you are using gradle for your build, add it to your `build.gradle`: dependencies { testCompile 'au.com.dius:pact-jvm-consumer-groovy_2.11:3.3.8' } Then create an instance of the `PactBuilder` in your test. ```groovy @Test void "A service consumer side of a pact goes a little something like this"() { def alice_service = new PactBuilder() // Create a new PactBuilder alice_service { serviceConsumer "Consumer" // Define the service consumer by name hasPactWith "Alice Service" // Define the service provider that it has a pact with port 1234 // The port number for the service. It is optional, leave it out to // to use a random one given('there is some good mallory') // defines a provider state. It is optional. uponReceiving('a retrieve Mallory request') // upon_receiving starts a new interaction withAttributes(method: 'get', path: '/mallory') // define the request, a GET request to '/mallory' willRespondWith( // define the response we want returned status: 200, headers: ['Content-Type': 'text/html'], body: '"That is some good Mallory."' ) } // Execute the run method to have the mock server run. // It takes a closure to execute your requests and returns a Pact VerificationResult. PactVerificationResult result = alice_service.runTest { def client = new RESTClient('http://localhost:1234/') def alice_response = client.get(path: '/mallory') assert alice_response.status == 200 assert alice_response.contentType == 'text/html' def data = alice_response.data.text() assert data == '"That is some good Mallory."' } assert result == PactVerificationResult.Ok.INSTANCE // This means it is all good } ``` After running this test, the following pact file is produced: { "provider" : { "name" : "Alice Service" }, "consumer" : { "name" : "Consumer" }, "interactions" : [ { "provider_state" : "there is some good mallory", "description" : "a retrieve Mallory request", "request" : { "method" : "get", "path" : "/mallory", "requestMatchers" : { } }, "response" : { "status" : 200, "headers" : { "Content-Type" : "text/html" }, "body" : "That is some good Mallory.", "responseMatchers" : { } } } ] } ### DSL Methods #### serviceConsumer(String consumer) This names the service consumer for the pact. #### hasPactWith(String provider) This names the service provider for the pact. #### port(int port) Sets the port that the mock server will run on. If not supplied, a random port will be used. #### given(String providerState) Defines a state that the provider needs to be in for the request to succeed. For more info, see https://github.com/realestate-com-au/pact/wiki/Provider-states #### uponReceiving(String requestDescription) Starts the definition of a of a pact interaction. #### withAttributes(Map requestData) Defines the request for the interaction. The request data map can contain the following: | key | Description | Default Value
Last modified2017-05-18 05:35:09 UTC
URL https://github.com/DiUS/pact-jvm
Repository URL http://repo1.maven.org/maven2/au/com/dius/pact-jvm-consumer-groovy_2.11/3.4.0/
Packaging jar
POM File View
Effective POM File View
Dependency tag
<dependency>
  <groupId>au.com.dius</groupId>
  <artifactId>pact-jvm-consumer-groovy_2.11</artifactId>
  <version>3.4.0</version>
</dependency>
'au.com.dius:pact-jvm-consumer-groovy_2.11:jar:3.4.0'
<dependency org="au.com.dius" name="pact-jvm-consumer-groovy_2.11" rev="3.4.0" />
@Grapes(@Grab(group='au.com.dius', module='pact-jvm-consumer-groovy_2.11', version='3.4.0'))
compile 'au.com.dius:pact-jvm-consumer-groovy_2.11:3.4.0'
libraryDependencies += "au.com.dius" % "pact-jvm-consumer-groovy_2.11" % "3.4.0"
Repository tag
  <repository>
    <id>central</id>
    <url>http://repo1.maven.org/maven2/</url>
  </repository>
Used by
GroupArtifactVersion
au.com.dius pact-jvm-provider_2.11 3.4.0 
Packages

au.com.dius.pact.consumer.groovy

au.com.dius.pact.consumer.groovy.messaging