MVN

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

Maven & Gradle

Apr 29, 2020
12 usages
1k stars

pact-jvm-provider_2.12 · 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.12</artifactId>
    <version>3.6.15</version>
</dependency>
Copy
pom.xml
Table Of Contents

Latest Version

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

  • Latest Stable: 3.6.15
  • Latest Release Candidate: 3.6.0-rc.1

All Versions

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

Version Vulnerabilities Updated
3.6.x
pact-jvm-provider_2.12-3.6.15
pact-jvm-provider_2.12-3.6.14
pact-jvm-provider_2.12-3.6.13
pact-jvm-provider_2.12-3.6.12
pact-jvm-provider_2.12-3.6.11
pact-jvm-provider_2.12-3.6.10
pact-jvm-provider_2.12-3.6.9
pact-jvm-provider_2.12-3.6.8
pact-jvm-provider_2.12-3.6.7
pact-jvm-provider_2.12-3.6.6
pact-jvm-provider_2.12-3.6.5
pact-jvm-provider_2.12-3.6.4
pact-jvm-provider_2.12-3.6.3
pact-jvm-provider_2.12-3.6.2
pact-jvm-provider_2.12-3.6.1
pact-jvm-provider_2.12-3.6.0
pact-jvm-provider_2.12-3.6.0-rc.1
pact-jvm-provider_2.12-3.6.0-rc.0
3.5.x
pact-jvm-provider_2.12-3.5.25
pact-jvm-provider_2.12-3.5.24
pact-jvm-provider_2.12-3.5.23
pact-jvm-provider_2.12-3.5.22
pact-jvm-provider_2.12-3.5.21
pact-jvm-provider_2.12-3.5.20
pact-jvm-provider_2.12-3.5.19
pact-jvm-provider_2.12-3.5.18
pact-jvm-provider_2.12-3.5.17
pact-jvm-provider_2.12-3.5.16
pact-jvm-provider_2.12-3.5.15
pact-jvm-provider_2.12-3.5.14
pact-jvm-provider_2.12-3.5.13
pact-jvm-provider_2.12-3.5.12
pact-jvm-provider_2.12-3.5.11
pact-jvm-provider_2.12-3.5.10
pact-jvm-provider_2.12-3.5.9
pact-jvm-provider_2.12-3.5.8
pact-jvm-provider_2.12-3.5.7
pact-jvm-provider_2.12-3.5.6
pact-jvm-provider_2.12-3.5.5
pact-jvm-provider_2.12-3.5.4-rc.1
pact-jvm-provider_2.12-3.5.4-rc.0

How to add a dependency to Maven

Add the following au.com.dius : pact-jvm-provider_2.12 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.12</artifactId>
    <version>3.6.15</version>
</dependency>

How to add a dependency to Gradle

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

implementation 'au.com.dius:pact-jvm-provider_2.12:3.6.15'

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

implementation("au.com.dius:pact-jvm-provider_2.12:3.6.15")

How to add a dependency to SBT Scala

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

libraryDependencies += "au.com.dius" % "pact-jvm-provider_2.12" % "3.6.15"

Advertisement

Dependencies from Group

Apr 29, 2020
31 usages
1k stars
Nov 04, 2018
27 usages
1k stars
Nov 04, 2018
18 usages
1k stars
Apr 29, 2020
13 usages
1k stars
Apr 29, 2020
12 usages
1k stars

Discover Dependencies

Sep 07, 2017
1 usages
0 stars
Mar 04, 2020
0 stars
Dec 01, 2022
1 usages
11.6k stars
Sep 06, 2017
2k stars
Sep 04, 2017
1 usages
173 stars
Sep 14, 2017
1 usages
0 stars
Sep 07, 2017
1k stars
Mar 07, 2018
1 usages
5 stars