Arquillian Pact Provider Core

Arquillian Pact Extension to run consumer-driven contracts with Pact

License

License

Categories

Categories

IDE Development Tools Arquillian Application Testing & Monitoring
GroupId

GroupId

org.arquillian.pact
ArtifactId

ArtifactId

arquillian-pact-provider-core
Last Version

Last Version

1.0.0.Alpha4
Release Date

Release Date

Type

Type

jar
Description

Description

Arquillian Pact Provider Core
Arquillian Pact Extension to run consumer-driven contracts with Pact
Project Organization

Project Organization

JBoss by Red Hat

Download arquillian-pact-provider-core

How to add to project

<!-- https://jarcasting.com/artifacts/org.arquillian.pact/arquillian-pact-provider-core/ -->
<dependency>
    <groupId>org.arquillian.pact</groupId>
    <artifactId>arquillian-pact-provider-core</artifactId>
    <version>1.0.0.Alpha4</version>
</dependency>
// https://jarcasting.com/artifacts/org.arquillian.pact/arquillian-pact-provider-core/
implementation 'org.arquillian.pact:arquillian-pact-provider-core:1.0.0.Alpha4'
// https://jarcasting.com/artifacts/org.arquillian.pact/arquillian-pact-provider-core/
implementation ("org.arquillian.pact:arquillian-pact-provider-core:1.0.0.Alpha4")
'org.arquillian.pact:arquillian-pact-provider-core:jar:1.0.0.Alpha4'
<dependency org="org.arquillian.pact" name="arquillian-pact-provider-core" rev="1.0.0.Alpha4">
  <artifact name="arquillian-pact-provider-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.arquillian.pact', module='arquillian-pact-provider-core', version='1.0.0.Alpha4')
)
libraryDependencies += "org.arquillian.pact" % "arquillian-pact-provider-core" % "1.0.0.Alpha4"
[org.arquillian.pact/arquillian-pact-provider-core "1.0.0.Alpha4"]

Dependencies

compile (7)

Group / Artifact Type Version
org.arquillian.pact : arquillian-pact-provider-api jar 1.0.0.Alpha4
org.jboss.arquillian.config : arquillian-config-api jar
org.jboss.arquillian.test : arquillian-test-impl-base jar
org.arquillian.pact : arquillian-pact-provider-spi jar 1.0.0.Alpha4
org.arquillian.pact : arquillian-pact-configuration jar 1.0.0.Alpha4
org.jboss.arquillian.core : arquillian-core-spi jar
org.jboss.arquillian.test : arquillian-test-spi jar

provided (4)

Group / Artifact Type Version
org.jboss.arquillian.container : arquillian-container-spi jar
org.jboss.arquillian.container : arquillian-container-test-impl-base jar
au.com.dius : pact-jvm-provider_2.11 jar 3.5.0-beta.2
au.com.dius : pact-jvm-model jar 3.5.0-beta.2

test (3)

Group / Artifact Type Version
junit : junit jar 4.11
org.assertj : assertj-core jar 3.5.2
org.mockito : mockito-core jar 1.10.19

Project Modules

There are no modules declared in this project.

Arquillian Algeron

Build Status

Important
Using Arquillian Algeron Pact Provider requires at least Arquillian Core 1.1.12.Final or above.
Important
Arquillian Algeron Pact 1.X works with versions of Pact previous to 3.5.0. Arquillian Algeron Pact 2.X works with Pact 3.5.0.

To read complete documentation visit http://arquillian.org/arquillian-algeron/

1. Migration from Arquillan Algeron Pact 1.X to 2.X

With the release of Pact 3.5.0, toFragment method has been deprecated in favor of toPact(). Also this method instead of returning PactFragment now returns RequestResponsePact.

Because of this change your contract definition should be adapted accordingly:

Algeron Pact 1.X
@Pact(provider = "test_provider", consumer = "test_consumer")
public PactFragment createFragment(PactDslWithProvider builder) {

    Map<String, String> header = new HashMap<>();
    header.put("Content-Type", "application/json");

    return builder
        .given("test state")
        .uponReceiving("ConsumerTest test interaction")
        .path("/")
        .method("GET")
        .willRespondWith()
        .status(200)
        .headers(header)
        .bodyWithSingleQuotes(("{'responsetest': true, 'name': 'harry'}"))
        .toFragment();
}

to:

Algeron Pact 2.X
@Pact(provider = "test_provider", consumer = "test_consumer")
public RequestResponsePact createFragment(PactDslWithProvider builder) {

    Map<String, String> header = new HashMap<>();
    header.put("Content-Type", "application/json");

    return builder
        .given("test state")
        .uponReceiving("ConsumerTest test interaction")
        .path("/")
        .method("GET")
        .willRespondWith()
        .status(200)
        .headers(header)
        .bodyWithSingleQuotes(("{'responsetest': true, 'name': 'harry'}"))
        .toPact();
}

2. What is Arquillian Algeron?

In microservices architecture you typically have one or more services that make remote calls to one or more services to get information from them.

For example you might have one service called BeerService that returns information of a beer. But this service needs to call another service CommentsService which returns the comments that users has done for given beer. After BeerService receives all the comments for that beer, everything is packed and sent to the client.

So as you can see there is a communication between both services where one needs to know what and how to send data such as name of fields, type of data or status code (CommentsService) and another one that needs to know how to interpret what is received (BeerService).

It seems obvious that it must exist some kind of agreement between them so they can understand each other correctly in all of their communications.

3. Consumer Driven Contracts

A Contract is a collection of agreements between a client ( or Consumer which in previous example is BeerService) and an API (or Provider which in previous example is CommentsService) that describes the interactions that can take place between them.

In summary Consumer Driven Contracts is a pattern that drives the development of the Provider from its Consumers point of view. This means that consumer describes what and how he wants to receive the information, describing in form of contract and then provider implements its service following that contract. When the client validates that can consume what it is been defined in the contract and provider validates that what he produces meets the contract, then you can be sure that contract expectations are met and they will be able to communicate each other.

Also notice that thanks of these tests, if anyone changes the client or the server side to not meet the contract, you’ll detect before it is deployed to production.

You can read more about Consumer-Driven contracts here or at book Testing Java Microservices chapter 6.

org.arquillian.pact

An Innovative Testing Platform for the JVM

Versions

Version
1.0.0.Alpha4
1.0.0.Alpha3
1.0.0.Alpha2
1.0.0.Alpha1