jar

au.com.dius : pact-jvm-provider

Maven & Gradle

Apr 18, 2020
9 usages
1k stars

pact-jvm-provider · 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 final TestRule startServiceRule = new DropwizardAppRule<DropwizardConfiguration>( TestDropwizardApplication, 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 = DefaultPactReader.INSTANCE.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) // normally assert all good, but in this example it will fail assertThat(failures, is(not(empty()))) verifier.displayFailures(failures) } private ProviderVerifier setupVerifier(Interaction interaction, ProviderInfo provider, ConsumerInfo consumer) { ProviderVerifier verifier = new ProviderVerifier() verifier.initialiseReporters(provider) verifier.reportVerificationForConsumer(consumer, provider, new UrlSource('http://example.example')) 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') { consumer -> consumer.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 } } ```

Table Of Contents

Latest Version

Download au.com.dius : pact-jvm-provider JAR file - Latest Versions:

All Versions

Download au.com.dius : pact-jvm-provider JAR file - All Versions:

Version Vulnerabilities Size Updated
4.0.x

View Java Class Source Code in JAR file

  1. Download JD-GUI to open JAR file and explore Java source code file (.class .java)
  2. Click menu "File → Open File..." or just drag-and-drop the JAR file in the JD-GUI window pact-jvm-provider-4.0.10.jar file.
    Once you open a JAR file, all the java classes in the JAR file will be displayed.

au.com.dius.pact.provider.reporters

├─ au.com.dius.pact.provider.reporters.AnsiConsoleReporter.class - [JAR]

├─ au.com.dius.pact.provider.reporters.JsonReporter.class - [JAR]

├─ au.com.dius.pact.provider.reporters.MarkdownReporter.class - [JAR]

├─ au.com.dius.pact.provider.reporters.ReporterManager.class - [JAR]

├─ au.com.dius.pact.provider.reporters.VerifierReporter.class - [JAR]

au.com.dius.pact.provider.junit.filter

├─ au.com.dius.pact.provider.junit.filter.InteractionFilter.class - [JAR]

au.com.dius.pact.provider.junit.target

├─ au.com.dius.pact.provider.junit.target.Target.class - [JAR]

├─ au.com.dius.pact.provider.junit.target.TestTarget.class - [JAR]

au.com.dius.pact.provider.junit

├─ au.com.dius.pact.provider.junit.AllowOverridePactUrl.class - [JAR]

├─ au.com.dius.pact.provider.junit.Consumer.class - [JAR]

├─ au.com.dius.pact.provider.junit.IgnoreNoPactsToVerify.class - [JAR]

├─ au.com.dius.pact.provider.junit.JUnitProviderTestSupport.class - [JAR]

├─ au.com.dius.pact.provider.junit.MissingStateChangeMethod.class - [JAR]

├─ au.com.dius.pact.provider.junit.Provider.class - [JAR]

├─ au.com.dius.pact.provider.junit.State.class - [JAR]

├─ au.com.dius.pact.provider.junit.StateChangeAction.class - [JAR]

├─ au.com.dius.pact.provider.junit.TargetRequestFilter.class - [JAR]

├─ au.com.dius.pact.provider.junit.VerificationReports.class - [JAR]

au.com.dius.pact.provider

├─ au.com.dius.pact.provider.BodyComparisonResult.class - [JAR]

├─ au.com.dius.pact.provider.ComparisonResult.class - [JAR]

├─ au.com.dius.pact.provider.ConsumerInfo.class - [JAR]

├─ au.com.dius.pact.provider.ConsumersGroup.class - [JAR]

├─ au.com.dius.pact.provider.DefaultStateChange.class - [JAR]

├─ au.com.dius.pact.provider.DefaultTestResultAccumulator.class - [JAR]

├─ au.com.dius.pact.provider.DefaultVerificationReporter.class - [JAR]

├─ au.com.dius.pact.provider.HttpClientFactory.class - [JAR]

├─ au.com.dius.pact.provider.IConsumerInfo.class - [JAR]

├─ au.com.dius.pact.provider.IHttpClientFactory.class - [JAR]

├─ au.com.dius.pact.provider.IProviderInfo.class - [JAR]

├─ au.com.dius.pact.provider.IProviderVerifier.class - [JAR]

├─ au.com.dius.pact.provider.MessageAndMetadata.class - [JAR]

├─ au.com.dius.pact.provider.PactVerification.class - [JAR]

├─ au.com.dius.pact.provider.PactVerifierException.class - [JAR]

├─ au.com.dius.pact.provider.PactVerifyProvider.class - [JAR]

├─ au.com.dius.pact.provider.ProviderClient.class - [JAR]

├─ au.com.dius.pact.provider.ProviderInfo.class - [JAR]

├─ au.com.dius.pact.provider.ProviderUtils.class - [JAR]

├─ au.com.dius.pact.provider.ProviderVerifier.class - [JAR]

├─ au.com.dius.pact.provider.ResponseComparison.class - [JAR]

├─ au.com.dius.pact.provider.StateChange.class - [JAR]

├─ au.com.dius.pact.provider.StateChangeResult.class - [JAR]

├─ au.com.dius.pact.provider.TestResultAccumulator.class - [JAR]

├─ au.com.dius.pact.provider.VerificationReporter.class - [JAR]

au.com.dius.pact.provider.junit.loader

├─ au.com.dius.pact.provider.junit.loader.NoPactsFoundException.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.OverrideablePactLoader.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactBroker.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactBrokerAuth.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactBrokerLoader.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactFilter.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactFolder.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactFolderLoader.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactLoader.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactSource.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactUrl.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.PactUrlLoader.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.VersionedPactUrl.class - [JAR]

├─ au.com.dius.pact.provider.junit.loader.VersionedPactUrlLoader.class - [JAR]

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

orm
Apr 06, 2019
3 usages
0 stars
Apr 03, 2023
2 usages
4.8k stars
Aug 23, 2023
8 usages
20 stars
Aug 23, 2023
2 usages
20 stars
Aug 23, 2023
4 usages
20 stars
Jul 14, 2023
943 stars
Jan 24, 2023
270 stars
Feb 21, 2020
1 usages
May 22, 2019
44 stars