MVN

au.com.dius : pact-jvm-provider_2.11

Maven & Gradle

Nov 04, 2018
27 usages
1k stars

pact-jvm-provider_2.11 · Pact provider ============= sub project of https://github.com/DiUS/pact-jvm The pact provider is responsible for verifying that an API provider adheres to a number of pacts authored by its clients This library provides the basic tools required to automate the process, and should be usable on its own in many instances. Framework and build tool specific bindings will be provided in separate libraries that build on top of this core functionality. ### Provider State Before each interaction is executed, the provider under test will have the opportunity to enter a state. Generally the state maps to a set of fixture data for mocking out services that the provider is a consumer of (they will have their own pacts) The pact framework will instruct the test server to enter that state by sending: POST "${config.stateChangeUrl.url}/setup" { "state" : "${interaction.stateName}" } ### An example of running provider verification with junit This example uses Groovy, JUnit 4 and Hamcrest matchers to run the provider verification. As the provider service is a DropWizard application, it uses the DropwizardAppRule to startup the service before running any test. **Warning:** It only grabs the first interaction from the pact file with the consumer, where there could be many. (This could possibly be solved with a parameterized test) ```groovy class ReadmeExamplePactJVMProviderJUnitTest { @ClassRule public static TestRule startServiceRule = new DropwizardAppRule<DropwizardConfiguration>( TestDropwizardApplication.class, ResourceHelpers.resourceFilePath("dropwizard/test-config.yaml")) private static ProviderInfo serviceProvider private static Pact<RequestResponseInteraction> testConsumerPact private static ConsumerInfo consumer @BeforeClass static void setupProvider() { serviceProvider = new ProviderInfo("Dropwizard App") serviceProvider.setProtocol("http") serviceProvider.setHost("localhost") serviceProvider.setPort(8080) serviceProvider.setPath("/") consumer = new ConsumerInfo() consumer.setName("test_consumer") consumer.setPactSource(new UrlSource( ReadmeExamplePactJVMProviderJUnitTest.getResource("/pacts/zoo_app-animal_service.json").toString())) testConsumerPact = PactReader.loadPact(consumer.getPactSource()) as Pact<RequestResponseInteraction> } @Test void runConsumerPacts() { // grab the first interaction from the pact with consumer Interaction interaction = testConsumerPact.interactions.get(0) // setup the verifier ProviderVerifier verifier = setupVerifier(interaction, serviceProvider, consumer) // setup any provider state // setup the client and interaction to fire against the provider ProviderClient client = new ProviderClient(serviceProvider, new HttpClientFactory()) Map<String, Object> failures = new HashMap<>() verifier.verifyResponseFromProvider(serviceProvider, interaction, interaction.getDescription(), failures, client) if (!failures.isEmpty()) { verifier.displayFailures(failures) } // Assert all good assertThat(failures, is(empty())) } private ProviderVerifier setupVerifier(Interaction interaction, ProviderInfo provider, ConsumerInfo consumer) { ProviderVerifier verifier = new ProviderVerifier() verifier.initialiseReporters(provider) verifier.reportVerificationForConsumer(consumer, provider) if (!interaction.getProviderStates().isEmpty()) { for (ProviderState providerState: interaction.getProviderStates()) { verifier.reportStateForInteraction(providerState.getName(), provider, consumer, true) } } verifier.reportInteractionDescription(interaction) return verifier } } ``` ### An example of running provider verification with spock This example uses groovy and spock to run the provider verification. Again the provider service is a DropWizard application, and is using the DropwizardAppRule to startup the service. This example runs all interactions using spocks Unroll feature ```groovy class ReadmeExamplePactJVMProviderSpockSpec extends Specification { @ClassRule @Shared TestRule startServiceRule = new DropwizardAppRule<DropwizardConfiguration>(TestDropwizardApplication, ResourceHelpers.resourceFilePath('dropwizard/test-config.yaml')) @Shared ProviderInfo serviceProvider ProviderVerifier verifier def setupSpec() { serviceProvider = new ProviderInfo('Dropwizard App') serviceProvider.protocol = 'http' serviceProvider.host = 'localhost' serviceProvider.port = 8080 serviceProvider.path = '/' serviceProvider.hasPactWith('zoo_app') { pactSource = new FileSource(new File(ResourceHelpers.resourceFilePath('pacts/zoo_app-animal_service.json'))) } } def setup() { verifier = new ProviderVerifier() } def cleanup() { // cleanup provider state // ie. db.truncateAllTables() } def cleanupSpec() { // cleanup provider } @Unroll def "Provider Pact - With Consumer #consumer"() { expect: verifyConsumerPact(consumer).empty where: consumer << serviceProvider.consumers } private Map verifyConsumerPact(ConsumerInfo consumer) { Map failures = [:] verifier.initialiseReporters(serviceProvider) verifier.runVerificationForConsumer(failures, serviceProvider, consumer) if (!failures.empty) { verifier.displayFailures(failures) } failures } } ```

<dependency>
    <groupId>au.com.dius</groupId>
    <artifactId>pact-jvm-provider_2.11</artifactId>
    <version>3.5.24</version>
</dependency>
Copy
pom.xml
Table Of Contents

Latest Version

Choose a version of au.com.dius : pact-jvm-provider_2.11 to add to Maven or Gradle - Latest Versions:

  • Latest Stable: 3.5.24
  • Latest Release Candidate: 3.5.0-rc.3
  • Latest Beta: 3.5.0-beta.4

All Versions

Choose a version of au.com.dius : pact-jvm-provider_2.11 to add to Maven or Gradle - All Versions:

Version Vulnerabilities Updated
3.5.x
pact-jvm-provider_2.11-3.5.24
pact-jvm-provider_2.11-3.5.23
pact-jvm-provider_2.11-3.5.22
pact-jvm-provider_2.11-3.5.21
pact-jvm-provider_2.11-3.5.20
pact-jvm-provider_2.11-3.5.19
pact-jvm-provider_2.11-3.5.18
pact-jvm-provider_2.11-3.5.17
pact-jvm-provider_2.11-3.5.16
pact-jvm-provider_2.11-3.5.15
pact-jvm-provider_2.11-3.5.14
pact-jvm-provider_2.11-3.5.13
pact-jvm-provider_2.11-3.5.12
pact-jvm-provider_2.11-3.5.11
pact-jvm-provider_2.11-3.5.10
pact-jvm-provider_2.11-3.5.9
pact-jvm-provider_2.11-3.5.8
pact-jvm-provider_2.11-3.5.7-jre7.0
pact-jvm-provider_2.11-3.5.7
pact-jvm-provider_2.11-3.5.6-jre7.0
pact-jvm-provider_2.11-3.5.6
pact-jvm-provider_2.11-3.5.5-jre7.0
pact-jvm-provider_2.11-3.5.5
pact-jvm-provider_2.11-3.5.4-jre7.0
pact-jvm-provider_2.11-3.5.4
pact-jvm-provider_2.11-3.5.3-jre7.0
pact-jvm-provider_2.11-3.5.3
pact-jvm-provider_2.11-3.5.2
pact-jvm-provider_2.11-3.5.2-jre7.0
pact-jvm-provider_2.11-3.5.1
pact-jvm-provider_2.11-3.5.1-jre7.1
pact-jvm-provider_2.11-3.5.0-jre7.1
pact-jvm-provider_2.11-3.5.0-jre7
pact-jvm-provider_2.11-3.5.0
pact-jvm-provider_2.11-3.5.0-rc.3
pact-jvm-provider_2.11-3.5.0-rc.2
pact-jvm-provider_2.11-3.5.0-rc.1
pact-jvm-provider_2.11-3.5.0-beta.4
pact-jvm-provider_2.11-3.5.0-beta.3
pact-jvm-provider_2.11-3.5.0-beta.2
pact-jvm-provider_2.11-3.5.0-beta.1
3.4.x
pact-jvm-provider_2.11-3.4.1
pact-jvm-provider_2.11-3.4.0
3.3.x
pact-jvm-provider_2.11-3.3.10
pact-jvm-provider_2.11-3.3.9
pact-jvm-provider_2.11-3.3.8
pact-jvm-provider_2.11-3.3.7
pact-jvm-provider_2.11-3.3.6
pact-jvm-provider_2.11-3.3.5
pact-jvm-provider_2.11-3.3.4
pact-jvm-provider_2.11-3.3.3
pact-jvm-provider_2.11-3.3.2
pact-jvm-provider_2.11-3.3.1
pact-jvm-provider_2.11-3.3.0
pact-jvm-provider_2.11-3.3.0-beta.0
3.2.x
pact-jvm-provider_2.11-3.2.13
pact-jvm-provider_2.11-3.2.12
pact-jvm-provider_2.11-3.2.11
pact-jvm-provider_2.11-3.2.10
pact-jvm-provider_2.11-3.2.9
pact-jvm-provider_2.11-3.2.8
pact-jvm-provider_2.11-3.2.7
pact-jvm-provider_2.11-3.2.6
pact-jvm-provider_2.11-3.2.5
pact-jvm-provider_2.11-3.2.4
pact-jvm-provider_2.11-3.2.3
pact-jvm-provider_2.11-3.2.2
pact-jvm-provider_2.11-3.2.1
pact-jvm-provider_2.11-3.2.0
3.1.x
pact-jvm-provider_2.11-3.1.3
pact-jvm-provider_2.11-3.1.2
pact-jvm-provider_2.11-3.1.1
pact-jvm-provider_2.11-3.1.0
3.0.x
pact-jvm-provider_2.11-3.0.4
pact-jvm-provider_2.11-3.0.3
pact-jvm-provider_2.11-3.0.2
pact-jvm-provider_2.11-3.0.1
pact-jvm-provider_2.11-3.0.0
2.5.x
pact-jvm-provider_2.11-2.5.0-beta.0
2.4.x
pact-jvm-provider_2.11-2.4.20
pact-jvm-provider_2.11-2.4.19
pact-jvm-provider_2.11-2.4.18
pact-jvm-provider_2.11-2.4.17
pact-jvm-provider_2.11-2.4.16
pact-jvm-provider_2.11-2.4.15
pact-jvm-provider_2.11-2.4.14
pact-jvm-provider_2.11-2.4.13
pact-jvm-provider_2.11-2.4.12
pact-jvm-provider_2.11-2.4.11
pact-jvm-provider_2.11-2.4.10
pact-jvm-provider_2.11-2.4.9
pact-jvm-provider_2.11-2.4.8
pact-jvm-provider_2.11-2.4.7
pact-jvm-provider_2.11-2.4.6
pact-jvm-provider_2.11-2.4.5
pact-jvm-provider_2.11-2.4.4
pact-jvm-provider_2.11-2.4.3
pact-jvm-provider_2.11-2.4.2
pact-jvm-provider_2.11-2.4.1
pact-jvm-provider_2.11-2.4.0
2.3.x
pact-jvm-provider_2.11-2.3.3
pact-jvm-provider_2.11-2.3.2
pact-jvm-provider_2.11-2.3.1
pact-jvm-provider_2.11-2.3.0
2.2.x
pact-jvm-provider_2.11-2.2.15
pact-jvm-provider_2.11-2.2.14
pact-jvm-provider_2.11-2.2.13
pact-jvm-provider_2.11-2.2.12
pact-jvm-provider_2.11-2.2.11
pact-jvm-provider_2.11-2.2.10
pact-jvm-provider_2.11-2.2.9
pact-jvm-provider_2.11-2.2.8
pact-jvm-provider_2.11-2.2.7
pact-jvm-provider_2.11-2.2.6
pact-jvm-provider_2.11-2.2.5
pact-jvm-provider_2.11-2.2.4
pact-jvm-provider_2.11-2.2.3
pact-jvm-provider_2.11-2.2.2
pact-jvm-provider_2.11-2.2.1
pact-jvm-provider_2.11-2.2.0
2.1.x
pact-jvm-provider_2.11-2.1.13
pact-jvm-provider_2.11-2.1.12
pact-jvm-provider_2.11-2.1.11
pact-jvm-provider_2.11-2.1.10
pact-jvm-provider_2.11-2.1.9
pact-jvm-provider_2.11-2.1.8
pact-jvm-provider_2.11-2.1.7
pact-jvm-provider_2.11-2.1.6
pact-jvm-provider_2.11-2.1.5
pact-jvm-provider_2.11-2.1.4
pact-jvm-provider_2.11-2.1.3
pact-jvm-provider_2.11-2.1.2
pact-jvm-provider_2.11-2.1.1
pact-jvm-provider_2.11-2.1.0
2.0.x
pact-jvm-provider_2.11-2.0.9
pact-jvm-provider_2.11-2.0.8
pact-jvm-provider_2.11-2.0.7
pact-jvm-provider_2.11-2.0.6
pact-jvm-provider_2.11-2.0.5
pact-jvm-provider_2.11-2.0.4
pact-jvm-provider_2.11-2.0.3
pact-jvm-provider_2.11-2.0.2
pact-jvm-provider_2.11-2.0.1
pact-jvm-provider_2.11-2.0.0

How to add a dependency to Maven

Add the following au.com.dius : pact-jvm-provider_2.11 maven dependency to the pom.xml file with your favorite IDE (IntelliJ / Eclipse / Netbeans):

<dependency>
    <groupId>au.com.dius</groupId>
    <artifactId>pact-jvm-provider_2.11</artifactId>
    <version>3.5.24</version>
</dependency>

How to add a dependency to Gradle

Gradle Groovy DSL: Add the following au.com.dius : pact-jvm-provider_2.11 gradle dependency to your build.gradle file:

implementation 'au.com.dius:pact-jvm-provider_2.11:3.5.24'

Gradle Kotlin DSL: Add the following au.com.dius : pact-jvm-provider_2.11 gradle kotlin dependency to your build.gradle.kts file:

implementation("au.com.dius:pact-jvm-provider_2.11:3.5.24")

How to add a dependency to SBT Scala

SBT Scala: Add the following au.com.dius : pact-jvm-provider_2.11 sbt scala dependency to your build.sbt file:

libraryDependencies += "au.com.dius" % "pact-jvm-provider_2.11" % "3.5.24"

Advertisement