Skip to content
Samples for Spring Cloud Contract project
Java Groovy Shell JavaScript Kotlin HTML
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci KIlling gradle daemons when on CI Aug 28, 2019
.mvn/wrapper Bumped libs Jun 20, 2017
beer_contracts Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
common Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
consumer Added JAXRS with Spring example Nov 13, 2019
consumer_pact Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
consumer_pact_stubrunner Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
consumer_proto Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
consumer_security Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
consumer_with_discovery Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
consumer_with_junit5 Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
consumer_with_restdocs Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
consumer_with_stubs_per_consumer Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
contract_empty_git Allow fetching contract definitions from file system and pushing them… Jan 1, 2019
contract_git Fixed different version in git Nov 18, 2018
docker URL Cleanup Mar 20, 2019
docs Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
gradle/wrapper Updated docs Jul 23, 2019
producer Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_advanced Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_jaxrs Added jaxrs example Nov 8, 2019
producer_jaxrs_spring Fixed invalid removals Nov 15, 2019
producer_kotlin Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_pact Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_proto Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_security Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_webflux Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_webflux_webtestclient Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_dsl_restdocs Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_empty_git Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_external_contracts Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_git Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_junit5 Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_restdocs Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_spock Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_stubs_per_consumer Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_webtestclient_restdocs Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_with_xml Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
producer_yaml Bumped Boot to 2.1.10.RELEASE Nov 8, 2019
scripts Added JAXRS with Spring example Nov 13, 2019
.editorconfig Polish Feb 19, 2019
.gitignore Polish Feb 19, 2019
.springformat Polish Feb 19, 2019
LICENSE.txt URL Cleanup Mar 21, 2019
README.adoc URL Cleanup Mar 20, 2019
build.gradle Bumped version Jul 23, 2019
gradlew Updated docs Jul 23, 2019
gradlew.bat Updated docs Jul 23, 2019
mvnw URL Cleanup Mar 12, 2019
mvnw.cmd URL Cleanup Mar 12, 2019
pom.xml Added JAXRS with Spring example Nov 13, 2019

README.adoc

CircleCI

Spring Cloud Contract samples

This repository contains the consumer and the producer applications to use with Spring Cloud Contract project.

It contains several important branches. master where we test against the latest versions of Spring Cloud Contract, and x.x.x where we test against x.x.x version of Spring Cloud Contract.

This repository shows examples of

  • storing contracts on the producer side

  • storing contracts in a common repo

  • passing stubs via Rest docs

  • integration with Pact and Pact Broker

Both for REST and Messaging. Built with Maven and Gradle. Also some additional Spring Cloud Contract plugin configuration is present.

These samples were used in the following presentation. It might help to use the samples.

You can also go through the Spring Cloud Contract Workshops to learn how to use the tool by example.

Projects

Common

Contains the JAR with common classes used in the contracts on the producer side.

Beer_contracts

Contains the repo with all contracts for all applications. It can be used when you want to store all contracts in a single place.

Producer

The producer application contains contracts for both REST and messaging communication. From these contracts tests and stubs will be generated.

The producer in the contract also uses features like usage of common libraries, different combination of dynamic properties.

It also uses scenario based contracts. That means that the produced stubs are stateful.

Producer_yaml

The same as Producer but uses YAML

Producer_advanced

Contains more advanced examples of Spring Cloud Contract usage.

Producer_with_external_contracts

The producer application that downloads its contracts for both REST and messaging communication, from the Beer-contracts JAR. From these contracts tests and stubs will be generated.

Producer_with_restdocs

The producer application that uses both contracts and Spring Cloud Contract WireMock with RESTDocs. Contracts are used for messaging but the HTTP stubs are created via REST Docs tests.

Producer_with_stubs_per_consumer

The producer application stores the contracts in such way that every consumer has its own, delegated folder. Then on the consumer side by turning on the stubs per consumer feature only respective stubs for the given consumer will be used.

Consumer

The consumer application is using the stubs of the producer for both rest and messaging.

It also contains the consumer side of the stateful scenario case. By calling the same endpoint a couple of times we get different responses due to changing state.

Consumer_with_discovery

The consumer application is using the stubs of the producer for rest. It sends requests via a load balanced rest template. In the tests Spring Cloud Contract stubs out any discovery service infrastructure.

Consumer_with_restdocs

The consumer application is using the stubs of the producer for both rest and messaging. The stubs come from the test compile dependency of the producer.

Consumer_with_stubs_per_consumer

The consumer application that has the stub of the HTTP server get fed with stubs that lay under proper folder in the reused JAR.

Docker

Contains docker setup for Pact Broker

Consumer_pact

Since Pact works around the idea of consumer contract, the contract definitions (the Pact files), are defined and set up on the consumer side. Then the Pact files get uploaded to the Pact Broker

Producer_pact

This project connects to the Pact Broker to retrieve the list of Pact files. From the files tests and WireMock stubs are generated.

Consumer_pact_stubrunner

If one wants to do producer contracts with Pact Broker, one can upload the pacts from a consumer (which actually can be the producer) and then all the other consumers, can use Spring Cloud Contract Stub Runner to run stubs of the producer.

Producer_proto

Project that uses Protocol Buffers to communicate.

Consumer_proto

Project that uses Protocol Buffers to communicate.

Producer_kotlin

Producer application written in Kotlin.

How to build it?

You can run Maven from the root folder once the "common" module has been installed. So from a clean checkout:

(cd common; ../mvnw clean install)
./mvnw clean install -Ptest

(or ./scripts/runMavenBuild.sh). Then you can build normally

./mvnw clean install

The order should be as follows

  • common

  • beer-contracts

  • producer

  • producer_advanced

  • producer_with_external_contracts

  • producer_with_stubs_per_consumer

  • consumer

  • consumer_with_discovery

  • producer_with_restdocs

  • consumer_with_restdocs

  • consumer_with_stubs_per_consumer

If the order is different then your apps will blow up most likely due to missing stubs.

You can also go to each of the projects and run Gradle wrapper:

./gradlew clean build publishToMavenLocal

How to test it?

You can run the script

./scripts/runAcceptanceTests.sh
You can’t perform that action at this time.