Example Java Spring Boot + RestAssured Provider
Source Code​
https://github.com/pactflow/example-provider-restassured
This is an example of a Spring boot API provider that uses RestAssured, PactFlow and its Bi-Directional Contract Testing feature to ensure that it is compatible with the expectations its consumers have of it.
The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.
It is using a public tenant on PactFlow, which you can access here using the credentials dXfltyFMgNOFZAxr8io9wJ37iUpY42M
/O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1
. The latest version of the Example Consumer/Example Provider pact is published here.
Pre-requisites​
Software:
- Tools listed at: https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci/prerequisites/
- A pactflow.io account with an valid API token
Environment variables​
To be able to run some of the commands locally, you will need to export the following environment variables into your shell:
PACT_BROKER_TOKEN
: a valid API token for PactFlowPACT_BROKER_BASE_URL
: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.io
Usage​
make test
- run the tests locallymake fake_ci
- run the CI process locally
Other examples of how to do this form of testing​
- https://hazelcast.com/blog/contract-first-development-using-restassured-and-openapi/
- https://www.openapi4j.org/operation-validator-adapters/spring.html
- https://springframework.guru/should-i-use-spring-rest-docs-or-openapi/
- https://github.com/OpenAPITools/openapi-generator (generate rest assured tests from spec)