Versions of artifact


pact-jvm-consumer-junit ======================= Provides a DSL and a base test class for use with Junit to build consumer tests. ## Dependency The library is available on maven central using: * group-id = `` * artifact-id = `pact-jvm-consumer-junit_2.11` * version-id = `3.2.x` ## Usage ### Using the base ConsumerPactTest To write a pact spec extend ConsumerPactTest. This base class defines the following four methods which must be overridden in your test class. * *providerName:* Returns the name of the API provider that Pact will mock * *consumerName:* Returns the name of the API consumer that we are testing. * *createFragment:* Returns the PactFragment containing the interactions that the test setup using the ConsumerPactBuilder DSL * *runTest:* The actual test run. It receives the URL to the mock server as a parameter. Here is an example: ```java import; import; import; import; import org.junit.Assert; import; import java.util.HashMap; import java.util.Map; import static org.junit.Assert.assertEquals; public class ExampleJavaConsumerPactTest extends ConsumerPactTestMk2 { @Override protected RequestResponsePact createFragment(PactDslWithProvider builder) { Map<String, String> headers = new HashMap<String, String>(); headers.put("testreqheader", "testreqheadervalue"); return builder .given("test state") // NOTE: Using provider states are optional, you can leave it out .uponReceiving("ExampleJavaConsumerPactTest test interaction") .path("/") .method("GET") .headers(headers) .willRespondWith() .status(200) .headers(headers) .body("{\"responsetest\": true, \"name\": \"harry\"}") .given("test state 2") // NOTE: Using provider states are optional, you can leave it out .uponReceiving("ExampleJavaConsumerPactTest second test interaction") .method("OPTIONS") .headers(headers) .path("/second") .body("") .willRespondWith() .status(200) .headers(headers) .body("") .toPact(); } @Override protected String providerName() { return "test_provider"; } @Override protected String consumerName() { return "test_consumer"; } @Override protected void runTest(MockServer mockServer) throws IOException { Assert.assertEquals(new ConsumerClient(mockServer.getUrl()).options("/second"), 200); Map expectedResponse = new HashMap(); expectedResponse.put("responsetest", true); expectedResponse.put("name", "harry"); assertEquals(new ConsumerClient(mockServer.getUrl()).getAsMap("/", ""), expectedResponse); assertEquals(new ConsumerClient(mockServer.getUrl()).options("/second"), 200); } } ``` ### Using the Pact JUnit Rule Thanks to [@warmuuh]( we have a JUnit rule that simplifies running Pact consumer tests. To use it, create a test class and then add the rule: #### 1. Add the Pact Rule to your test class to represent your provider. ```java @Rule public PactProviderRuleMk2 mockProvider = new PactProviderRuleMk2("test_provider", "localhost", 8080, this); ``` The hostname and port are optional. If left out, it will default to and a random available port. You can get the URL and port from

Artifact Version Name Latest uploaded at
3.5.3 pact-jvm-consumer-junit_2.11 2017-08-06 07:53:34 UTC
3.5.2 pact-jvm-consumer-junit_2.11 2017-07-12 01:08:28 UTC
3.5.2-jre7.0 pact-jvm-consumer-junit_2.11 2017-07-12 00:34:21 UTC
3.5.1 pact-jvm-consumer-junit_2.11 2017-07-09 08:14:09 UTC
3.5.1-jre7.1 pact-jvm-consumer-junit_2.11 2017-07-09 06:52:59 UTC
3.5.0-jre7.1 pact-jvm-consumer-junit_2.11 2017-06-24 13:13:26 UTC
3.5.0-jre7 pact-jvm-consumer-junit_2.11 2017-06-24 11:23:35 UTC
3.5.0 pact-jvm-consumer-junit_2.11 2017-06-24 08:08:21 UTC
3.5.0-rc.3 pact-jvm-consumer-junit_2.11 2017-06-20 23:38:11 UTC
3.5.0-rc.2 pact-jvm-consumer-junit_2.11 2017-06-11 07:07:50 UTC
3.4.1 pact-jvm-consumer-junit_2.11 2017-06-11 01:59:52 UTC
3.5.0-rc.1 pact-jvm-consumer-junit_2.11 2017-05-25 03:39:38 UTC
3.4.0 pact-jvm-consumer-junit_2.11 2017-05-18 05:35:36 UTC
3.3.10 pact-jvm-consumer-junit_2.11 2017-05-18 03:59:24 UTC
3.5.0-beta.4 pact-jvm-consumer-junit_2.11 2017-05-14 11:46:33 UTC