Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arquillian/arquillian-algeron
https://github.com/arquillian/arquillian-algeron
arquillian java
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/arquillian/arquillian-algeron
- Owner: arquillian
- Created: 2016-08-31T11:06:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-14T20:58:44.000Z (almost 2 years ago)
- Last Synced: 2024-03-31T19:32:40.714Z (8 months ago)
- Topics: arquillian, java
- Language: Java
- Size: 662 KB
- Stars: 12
- Watchers: 10
- Forks: 8
- Open Issues: 24
-
Metadata Files:
- Readme: README.adoc
- License: license-asl-2.0.txt
Awesome Lists containing this project
README
= Arquillian Algeron
:asciidoctor-source: https://raw.githubusercontent.com/arquillian/arquillian-algeron/master/docs
:numbered:
:sectlink:
:sectanchors:
:sectid:
:source-language: java
:source-highlighter: coderay
:sectnums:
:icons: font
:toc: left
:toclevels: 3image:https://travis-ci.org/arquillian/arquillian-algeron.svg?branch=master["Build Status", link="https://travis-ci.org/arquillian/arquillian-algeron"]
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.
ifndef::generated-doc[]
To read complete documentation visit http://arquillian.org/arquillian-algeron/
endif::generated-doc[]== 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:
[source, java]
.Algeron Pact 1.X
----
@Pact(provider = "test_provider", consumer = "test_consumer")
public PactFragment createFragment(PactDslWithProvider builder) {Map 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:
[source, java]
.Algeron Pact 2.X
----
@Pact(provider = "test_provider", consumer = "test_consumer")
public RequestResponsePact createFragment(PactDslWithProvider builder) {Map 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();
}
----== 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.
== 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 http://martinfowler.com/articles/consumerDrivenContracts.html[here] or at book https://www.manning.com/books/testing-java-microservices[Testing Java Microservices] chapter 6.
ifdef::generated-doc[]
== Pactinclude::{asciidoctor-source}/pact.adoc[leveloffset=+2]
== Arquillian Algeron Consumer
include::{asciidoctor-source}/consumer.adoc[leveloffset=+2]
include::{asciidoctor-source}/publishers.adoc[leveloffset=+2]
== Arquillian Algeron Provider
include::{asciidoctor-source}/retrievers.adoc[leveloffset=+2]
include::{asciidoctor-source}/provider.adoc[leveloffset=+2]
include::{asciidoctor-source}/skipDeployment.adoc[leveloffset=+2]
endif::generated-doc[]