Download pact-jvm-provider_2.12 JAR file with all dependencies
pact-jvm-provider_2.12 from group au.com.dius (version 3.6.8)
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
}
}
```
Artifact pact-jvm-provider_2.12
Group au.com.dius
Version 3.6.8
Last update 15. June 2019
Tags: they cleanup using test verifier getdescription initialisereporters expect assertthat dropwizard file empty config only feature setpath dropwizardconfiguration quot services host groovy static setport under possibly again number interaction spock startup grabs cleanupspec many project setupverifier verification http will each automate resourcefilepath providerinfo port yaml parameterized before serviceprovider data truncatealltables resourcehelpers readmeexamplepactjvmproviderjunittest build instances providerstate running private executed setupspec could reportinteractiondescription runconsumerpacts displayfailures urlsource https failures post responsible return loadpact true void reportverificationforconsumer sethost framework should fire process sending getpactsource string consumerinfo library assert statename getname runs public warning pactsource beforeclass libraries client dropwizardapprule tool filesource good getproviderstates where consumer localhost setname tools providerclient authored instruct testdropwizardapplication apos basic required requestresponseinteraction test_consumer shared verifyconsumerpact solved pactreader extends classrule consumers class haspactwith enter that pact hamcrest usable isempty against reportstateforinteraction getresource example this setprotocol grab fixture adheres verifying testrule specific have providerverifier bindings matchers state from testconsumerpact tostring object readmeexamplepactjvmproviderspockspec mocking startservicerule json generally setupprovider setup verifyresponsefromprovider path interactions setpactsource httpclientfactory functionality application with separate protocol provides provider 8080 junit spocks zoo_app opportunity statechangeurl runverificationforconsumer maps there service specification provided uses server core animal_service hashmap their first github pacts dius unroll clients
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 9
Dependencies pact-jvm-model, pact-jvm-pact-broker, pact-jvm-matchers_2.12, commons-io, jansi, httpclient, reflections, pact-jvm-support, scala-java8-compat_2.12,
There are maybe transitive dependencies!
Group au.com.dius
Version 3.6.8
Last update 15. June 2019
Tags: they cleanup using test verifier getdescription initialisereporters expect assertthat dropwizard file empty config only feature setpath dropwizardconfiguration quot services host groovy static setport under possibly again number interaction spock startup grabs cleanupspec many project setupverifier verification http will each automate resourcefilepath providerinfo port yaml parameterized before serviceprovider data truncatealltables resourcehelpers readmeexamplepactjvmproviderjunittest build instances providerstate running private executed setupspec could reportinteractiondescription runconsumerpacts displayfailures urlsource https failures post responsible return loadpact true void reportverificationforconsumer sethost framework should fire process sending getpactsource string consumerinfo library assert statename getname runs public warning pactsource beforeclass libraries client dropwizardapprule tool filesource good getproviderstates where consumer localhost setname tools providerclient authored instruct testdropwizardapplication apos basic required requestresponseinteraction test_consumer shared verifyconsumerpact solved pactreader extends classrule consumers class haspactwith enter that pact hamcrest usable isempty against reportstateforinteraction getresource example this setprotocol grab fixture adheres verifying testrule specific have providerverifier bindings matchers state from testconsumerpact tostring object readmeexamplepactjvmproviderspockspec mocking startservicerule json generally setupprovider setup verifyresponsefromprovider path interactions setpactsource httpclientfactory functionality application with separate protocol provides provider 8080 junit spocks zoo_app opportunity statechangeurl runverificationforconsumer maps there service specification provided uses server core animal_service hashmap their first github pacts dius unroll clients
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 9
Dependencies pact-jvm-model, pact-jvm-pact-broker, pact-jvm-matchers_2.12, commons-io, jansi, httpclient, reflections, pact-jvm-support, scala-java8-compat_2.12,
There are maybe transitive dependencies!
Page 1 from 1 (items total 1)