Versions of artifact au.com.dius:pact-jvm-consumer-junit_2.11

pact-jvm-consumer-junit_2.11

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 = `au.com.dius` * artifact-id = `pact-jvm-consumer-junit_2.11` * version-id = `3.2.x` ## Usage ### Using the base ConsumerPactTest To write a pact spec extend ConsumerPactTestMk2. 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 au.com.dius.pact.consumer.dsl.PactDslWithProvider; import au.com.dius.pact.consumer.exampleclients.ConsumerClient; import au.com.dius.pact.consumer.ConsumerPactTest; import au.com.dius.pact.model.PactFragment; import org.junit.Assert; import java.io.IOException; 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](https://github.com/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 127.0.0.1 and a random available port. You can get the URL and port f

Artifact Version Name Latest uploaded at
3.5.7-jre7.0 pact-jvm-consumer-junit_2.11 2017-10-03 05:47:34 UTC
3.5.7 pact-jvm-consumer-junit_2.11 2017-10-03 00:45:07 UTC
3.5.6-jre7.0 pact-jvm-consumer-junit_2.11 2017-09-28 05:10:55 UTC
3.5.6 pact-jvm-consumer-junit_2.11 2017-09-27 01:50:59 UTC
3.5.5-jre7.0 pact-jvm-consumer-junit_2.11 2017-09-14 02:33:09 UTC
3.5.5 pact-jvm-consumer-junit_2.11 2017-09-11 23:08:33 UTC
3.5.4-jre7.0 pact-jvm-consumer-junit_2.11 2017-08-19 07:53:52 UTC
3.5.4 pact-jvm-consumer-junit_2.11 2017-08-18 05:33:32 UTC
2.4.19 pact-jvm-consumer-junit_2.11 2017-08-16 23:55:50 UTC
3.5.3-jre7.0 pact-jvm-consumer-junit_2.11 2017-08-10 00:26:42 UTC
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
3.3.9 pact-jvm-consumer-junit_2.11 2017-05-08 11:27:19 UTC
3.3.8 pact-jvm-consumer-junit_2.11 2017-04-14 03:52:05 UTC
3.3.7 pact-jvm-consumer-junit_2.11 2017-03-27 04:33:59 UTC
3.5.0-beta.3 pact-jvm-consumer-junit_2.11 2017-02-05 05:55:06 UTC
3.3.6 pact-jvm-consumer-junit_2.11 2017-01-26 06:37:14 UTC