This repository contains the consumer and the producer applications to use with Spring Cloud Contract project.
It contains 2 important branches. master
where we test against the latest versions of
Spring Cloud Contract, and 1.0.x
where we test against 1.0.x
versions 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
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.
Contains the repo with all contracts for all applications. It can be used when you want to store all contracts in a single place.
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.
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.
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.
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.
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.
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.
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.
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