au.com.dius:pact-jvm-consumer-junit_2.11:3.4.0

Group / Artifact / Version au.com.dius / pact-jvm-consumer-junit_2.11 / 3.4.0
Namepact-jvm-consumer-junit_2.11
Descriptionpact-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 ConsumerPactTestMk2 { @Override protected RequestResponsePact createFragment(PactDslWithProvider builder) { Map headers = new HashMap(); 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 from the pact provider rule. #### 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 RequestResponsePact createPact(PactDslWithProvider builder) { return bu
Last modified2017-05-18 05:35:36 UTC
URL https://github.com/DiUS/pact-jvm
Repository URL http://repo1.maven.org/maven2/au/com/dius/pact-jvm-consumer-junit_2.11/3.4.0/
Packaging jar
POM File View
Effective POM File View
Dependency tag
<dependency>
  <groupId>au.com.dius</groupId>
  <artifactId>pact-jvm-consumer-junit_2.11</artifactId>
  <version>3.4.0</version>
</dependency>
'au.com.dius:pact-jvm-consumer-junit_2.11:jar:3.4.0'
<dependency org="au.com.dius" name="pact-jvm-consumer-junit_2.11" rev="3.4.0" />
@Grapes(@Grab(group='au.com.dius', module='pact-jvm-consumer-junit_2.11', version='3.4.0'))
compile 'au.com.dius:pact-jvm-consumer-junit_2.11:3.4.0'
libraryDependencies += "au.com.dius" % "pact-jvm-consumer-junit_2.11" % "3.4.0"
Repository tag
  <repository>
    <id>central</id>
    <url>http://repo1.maven.org/maven2/</url>
  </repository>
Packages

au.com.dius.pact.consumer

SCM
  Urlhttps://github.com/DiUS/pact-jvm
  Connectionhttps://github.com/DiUS/pact-jvm.git
Dependencies
GroupArtifactVersion
org.jetbrains.kotlinkotlin-stdlib-jre81.1.2
org.jetbrains.kotlinkotlin-reflect1.1.2
org.slf4jslf4j-api1.7.21
org.codehaus.groovygroovy-all2.4.7
org.scala-langscala-library2.11.8
org.scala-langscala-compiler2.11.8
com.typesafe.scala-loggingscala-logging_2.113.4.0
au.com.diuspact-jvm-consumer_2.113.4.0
junitjunit4.12
org.jsonjson20160212
org.apache.commonscommons-lang33.4
com.google.guavaguava19.0
org.specs2specs2-core_2.113.8.4
org.specs2specs2-junit_2.113.8.4
org.hamcresthamcrest-all1.3
org.mockitomockito-core1.10.19
org.spockframeworkspock-core1.1-groovy-2.4-rc-4
cglibcglib3.2.4
org.objenesisobjenesis2.4
ch.qos.logbacklogback-core1.1.7
ch.qos.logbacklogback-classic1.1.7
org.apache.commonscommons-collections44.1
com.google.code.gsongson2.7
org.apache.httpcomponentsfluent-hc4.5.2
org.apache.httpcomponentshttpclient4.5.2
com.jayway.restassuredrest-assured2.9.0
org.clojureclojure1.8.0
http-kithttp-kit2.1.19
Plugins
GroupArtifactVersion
org.apache.maven.pluginsmaven-clean-plugin2.5
org.apache.maven.pluginsmaven-resources-plugin2.6
org.apache.maven.pluginsmaven-jar-plugin2.4
org.apache.maven.pluginsmaven-compiler-plugin3.1
org.apache.maven.pluginsmaven-surefire-plugin2.12.4
org.apache.maven.pluginsmaven-install-plugin2.4
org.apache.maven.pluginsmaven-deploy-plugin2.7
org.apache.maven.pluginsmaven-site-plugin3.3
Licenses
  NameApache 2
  Urlhttp://www.apache.org/licenses/LICENSE-2.0.txt
  Distributionrepo