Versions of artifact


Pact 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 = `` * artifact-id = `pact-jvm-consumer_2.11` ## DSL Usage Example in a JUnit test: ```java import; import; import org.apache.http.entity.ContentType; import org.jetbrains.annotations.NotNull; import org.junit.Test; import; import java.util.HashMap; import java.util.Map; import static; import static org.junit.Assert.assertEquals; public class PactTest { @Test public void testPact() { RequestResponsePact pact = 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\"}") .toPact(); MockProviderConfig config = MockProviderConfig.createDefault(); PactVerificationResult result = runConsumerTest(pact, config, new PactTestRun() { @Override public void run(@NotNull MockServer mockServer) throws IOException { Map expectedResponse = new HashMap(); expectedResponse.put("hello", "harry"); assertEquals(expectedResponse, new ConsumerClient(mockServer.getUrl()).post("/hello", "{\"name\": \"harry\"}", ContentType.APPLICATION_JSON)); } }); if (result instanceof PactVerificationResult.Error) { throw new RuntimeException(((PactVerificationResult.Error)result).getError()); } assertEquals(PactVerificationResult.Ok.INSTANCE, 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\"}") . . . .toPact() ``` 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

Artifact Version Name Latest uploaded at
3.5.3 pact-jvm-consumer_2.11 2017-08-06 07:54:56 UTC
3.5.2 pact-jvm-consumer_2.11 2017-07-12 01:09:47 UTC
3.5.2-jre7.0 pact-jvm-consumer_2.11 2017-07-12 00:35:36 UTC
3.5.1 pact-jvm-consumer_2.11 2017-07-09 08:15:43 UTC
3.5.1-jre7.1 pact-jvm-consumer_2.11 2017-07-09 06:54:14 UTC
3.5.0-jre7.1 pact-jvm-consumer_2.11 2017-06-24 13:14:44 UTC
3.5.0-jre7 pact-jvm-consumer_2.11 2017-06-24 11:24:47 UTC
3.5.0 pact-jvm-consumer_2.11 2017-06-24 08:09:39 UTC
3.5.0-rc.3 pact-jvm-consumer_2.11 2017-06-20 23:39:14 UTC
3.5.0-rc.2 pact-jvm-consumer_2.11 2017-06-11 07:11:19 UTC
3.4.1 pact-jvm-consumer_2.11 2017-06-11 02:01:20 UTC
3.5.0-rc.1 pact-jvm-consumer_2.11 2017-05-25 03:41:24 UTC
3.4.0 pact-jvm-consumer_2.11 2017-05-18 05:36:45 UTC
3.3.10 pact-jvm-consumer_2.11 2017-05-18 04:00:46 UTC
3.5.0-beta.4 pact-jvm-consumer_2.11 2017-05-14 11:47:53 UTC
3.2.13 pact-jvm-consumer_2.11 2016-08-14 01:50:57 UTC
3.2.12 pact-jvm-consumer_2.11 2016-08-07 04:37:21 UTC
3.2.11 pact-jvm-consumer_2.11 2016-07-31 06:27:47 UTC
3.2.10 pact-jvm-consumer_2.11 2016-07-15 04:13:49 UTC