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

pact-jvm-consumer-junit_2.10

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.0.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 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 ConsumerPactTest { @Override protected PactFragment 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("") .toFragment(); } @Override protected String providerName() { return "test_provider"; } @Override protected String consumerName() { return "test_consumer"; } @Override protected void runTest(String url) throws IOException { Assert.assertEquals(new ConsumerClient(url).options("/second"), 200); Map expectedResponse = new HashMap(); expectedResponse.put("responsetest", true); expectedResponse.put("name", "harry"); assertEquals(new ConsumerClient(url).getAsMap("/", ""), expectedResponse); assertEquals(new ConsumerClient(url).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 PactProviderRule mockProvider = new PactProviderRule("test_provider", "localhost", 8080, this); ``` The hostname and port are optional. If left out, it will default to localhost and a random available port. #### 2. Annotate a method with Pact that returns a pact fragment for the provider and consumer ```java @Pact(provider="test_provider", consumer="test_consumer") public PactFragment createFragment(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("ExampleJavaConsumerPactRuleTest test interaction") .

Artifact Version Name Latest uploaded at
2.4.18 pact-jvm-consumer-junit_2.10 2016-12-30 01:40:09 UTC
2.4.17 pact-jvm-consumer-junit_2.10 2016-10-22 06:53:58 UTC
2.4.16 pact-jvm-consumer-junit_2.10 2016-10-01 21:30:46 UTC
2.4.15 pact-jvm-consumer-junit_2.10 2016-08-23 12:47:37 UTC
2.4.14 pact-jvm-consumer-junit_2.10 2016-08-07 03:33:03 UTC
2.4.13 pact-jvm-consumer-junit_2.10 2016-07-31 05:02:47 UTC
2.4.12 pact-jvm-consumer-junit_2.10 2016-07-15 02:51:04 UTC
2.4.11 pact-jvm-consumer-junit_2.10 2016-07-06 05:07:52 UTC
2.4.10 pact-jvm-consumer-junit_2.10 2016-06-17 23:09:26 UTC
2.4.9 pact-jvm-consumer-junit_2.10 2016-05-04 02:34:49 UTC
2.4.8 pact-jvm-consumer-junit_2.10 2016-03-29 02:18:02 UTC
2.4.7 pact-jvm-consumer-junit_2.10 2016-03-25 00:42:09 UTC
2.4.6 pact-jvm-consumer-junit_2.10 2016-02-19 23:21:59 UTC
2.4.5 pact-jvm-consumer-junit_2.10 2016-02-11 04:32:22 UTC
2.4.4 pact-jvm-consumer-junit_2.10 2016-01-20 23:41:45 UTC
2.4.3 pact-jvm-consumer-junit_2.10 2016-01-17 02:53:30 UTC
2.4.2 pact-jvm-consumer-junit_2.10 2015-12-12 22:03:29 UTC
2.4.1 pact-jvm-consumer-junit_2.10 2015-11-28 06:30:56 UTC
2.4.0 pact-jvm-consumer-junit_2.10 2015-11-22 04:02:19 UTC
2.3.3 pact-jvm-consumer-junit_2.10 2015-11-14 06:33:00 UTC
2.3.2 pact-jvm-consumer-junit_2.10 2015-10-24 01:10:58 UTC
2.3.1 pact-jvm-consumer-junit_2.10 2015-10-20 08:55:45 UTC
2.3.0 pact-jvm-consumer-junit_2.10 2015-10-06 10:16:21 UTC
2.2.15 pact-jvm-consumer-junit_2.10 2015-09-17 10:06:28 UTC
2.2.14 pact-jvm-consumer-junit_2.10 2015-09-07 10:07:31 UTC
2.2.13 pact-jvm-consumer-junit_2.10 2015-08-29 05:21:27 UTC
2.2.12 pact-jvm-consumer-junit_2.10 2015-08-09 07:15:10 UTC
2.2.11 pact-jvm-consumer-junit_2.10 2015-08-02 04:45:34 UTC
2.2.10 pact-jvm-consumer-junit_2.10 2015-07-25 06:09:17 UTC
2.2.9 pact-jvm-consumer-junit_2.10 2015-07-13 09:10:28 UTC