au.com.dius:pact-jvm-consumer_2.11:3.3.5

Group / Artifact / Version au.com.dius / pact-jvm-consumer_2.11 / 3.3.5
Namepact-jvm-consumer_2.11
DescriptionPact consumer ============= Pact Consumer is used by projects that are consumers of an API. Most projects will want to use pact-consumer via one of the test framework specific projects. If your favourite framework is not implemented, this module should give you all the hooks you need. Provides a DSL for use with Java to build consumer pacts. ## Dependency The library is available on maven central using: * group-id = `au.com.dius` * artifact-id = `pact-jvm-consumer_2.11` ## DSL Usage Example in a JUnit test: ```java import au.com.dius.pact.model.MockProviderConfig; import au.com.dius.pact.model.PactFragment; import org.junit.Test; import java.io.IOException; import java.util.HashMap; import java.util.Map; import static org.junit.Assert.assertEquals; public class PactTest { @Test public void testPact() { PactFragment pactFragment = ConsumerPactBuilder .consumer("Some Consumer") .hasPactWith("Some Provider") .uponReceiving("a request to say Hello") .path("/hello") .method("POST") .body("{\"name\": \"harry\"}") .willRespondWith() .status(200) .body("{\"hello\": \"harry\"}") .toFragment(); MockProviderConfig config = MockProviderConfig.createDefault(); VerificationResult result = pactFragment.runConsumer(config, new TestRun() { @Override public void run(MockProviderConfig config) { Map expectedResponse = new HashMap(); expectedResponse.put("hello", "harry"); try { assertEquals(new ProviderClient(config.url()).hello("{\"name\": \"harry\"}"), expectedResponse); } catch (IOException e) {} } }); if (result instanceof PactError) { throw new RuntimeException(((PactError)result).error()); } assertEquals(ConsumerPactTest.PACT_VERIFIED, result); } } ``` The DSL has the following pattern: ```java .consumer("Some Consumer") .hasPactWith("Some Provider") .given("a certain state on the provider") .uponReceiving("a request for something") .path("/hello") .method("POST") .body("{\"name\": \"harry\"}") .willRespondWith() .status(200) .body("{\"hello\": \"harry\"}") .uponReceiving("another request for something") .path("/hello") .method("POST") .body("{\"name\": \"harry\"}") .willRespondWith() .status(200) .body("{\"hello\": \"harry\"}") . . . .toFragment() ``` You can define as many interactions as required. Each interaction starts with `uponReceiving` followed by `willRespondWith`. The test state setup with `given` is a mechanism to describe what the state of the provider should be in before the provider is verified. It is only recorded in the consumer tests and used by the provider verification tasks. ### Building JSON bodies with PactDslJsonBody DSL The body method of the ConsumerPactBuilder can accept a PactDslJsonBody, which can construct a JSON body as well as define regex and type matchers. For example: ```java PactDslJsonBody body = new PactDslJsonBody() .stringType("name") .booleanType("happy") .hexValue("hexCode") .id() .ipAddress("localAddress") .numberValue("age", 100) .timestamp(); ``` #### DSL Matching methods The following matching methods are provided with the DSL. In most cases, they take an optional value parameter which will be used to generate example values (i.e. when returning a mock response). If no example value is given, a random one will be generated. | method | description | |--------|-------------| | string, stringValue | Match a string value (using string equality) | | number, numberValue | Match a number value (using Number.equals)\* | | booleanValue | Match a boolean value (using equality) |
Last modified2017-01-14 06:49:34 UTC
URL https://github.com/DiUS/pact-jvm
Repository URL https://oss.sonatype.org/content/repositories/releases/au/com/dius/pact-jvm-consumer_2.11/3.3.5/
Packaging jar
POM File View
Effective POM File View
Dependency tag
<dependency>
  <groupId>au.com.dius</groupId>
  <artifactId>pact-jvm-consumer_2.11</artifactId>
  <version>3.3.5</version>
</dependency>
'au.com.dius:pact-jvm-consumer_2.11:jar:3.3.5'
<dependency org="au.com.dius" name="pact-jvm-consumer_2.11" rev="3.3.5" />
@Grapes(@Grab(group='au.com.dius', module='pact-jvm-consumer_2.11', version='3.3.5'))
compile 'au.com.dius:pact-jvm-consumer_2.11:3.3.5'
libraryDependencies += "au.com.dius" % "pact-jvm-consumer_2.11" % "3.3.5"
Repository tag
  <repository>
    <id>central</id>
    <url>http://repo1.maven.org/maven2/</url>
  </repository>
  <repository>
    <id>pentaho-releases</id>
    <url>http://repository.pentaho.org/artifactory/repo/</url>
  </repository>
  <repository>
    <id>sonatype-releases</id>
    <url>https://oss.sonatype.org/content/repositories/releases/</url>
  </repository>
  <repository>
    <id>sonatype-staging</id>
    <url>https://oss.sonatype.org/content/repositories/staging/</url>
  </repository>
  <repository>
    <id>spring-milestones</id>
    <url>http://repo.spring.io/libs-milestone/</url>
  </repository>
  <repository>
    <id>spring-plugin-releases</id>
    <url>http://repo.spring.io/plugins-release/</url>
  </repository>
  <repository>
    <id>spring-releases</id>
    <url>http://repo.spring.io/libs-release-remote/</url>
  </repository>
Used by
Packages

au.com.dius.pact.consumer

au.com.dius.pact.consumer.dispatch

au.com.dius.pact.consumer.dsl

au.com.dius.pact.model

au.com.dius.pact.model.unfiltered