// Do not edit this file (e.g. go instead to src/main/asciidoc)

image::https://badges.gitter.im/Join%20Chat.svg[Gitter, link="https://gitter.im/spring-cloud/spring-cloud-contract?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
image::https://codecov.io/gh/spring-cloud/spring-cloud-contract/branch/master/graph/badge.svg["codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-contract"]
image::https://circleci.com/gh/spring-cloud/spring-cloud-contract.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-contract"]

== Spring Cloud Contract

What you always need it confidence in pushing new features into a new application or service in a distributed system.
This project provides support for Consumer Driven Contracts and service schemas in Spring applications, covering a
range of options for writing tests, publishing them as assets, asserting that a contract is kept by producers
and consumers, for HTTP and message-based interactions.

=== Spring Cloud Contract WireMock

Modules giving you the possibility to use http://wiremock.org[WireMock] with different servers. Check out the
https://github.com/spring-cloud/spring-cloud-contract/tree/master/samples[samples] for more information.

Currently we support Jetty, Native WireMock server, Tomcat and Undertow.

=== Spring Cloud Contract Verifier

:introduction_url: https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master

=== Introduction

IMPORTANT: http://codearte.github.io/accurest[The documentation to the deprecated Accurest project in version 1.1.0 is available here.]

TIP: The Accurest project was initially started by Marcin Grzejszczak and Jakub Kubrynski (http://codearte.io[codearte.io])

Just to make long story short - Spring Cloud Contract Verifier is a tool that enables Consumer Driven Contract (CDC) development of JVM-based applications. It is shipped
with __Contract Definition Language__ (DSL). Contract definitions are used to produce following resources:

* JSON stub definitions to be used by Wiremock when doing integration testing on the client code (__client tests__).
Test code must still be written by hand, test data is produced by Spring Cloud Contract Verifier.
* Messaging routes if you're using one. We're integrating with Spring Integration, Spring Cloud Stream and Apache Camel. You can however set your own integrations if you want to
* Acceptance tests (in JUnit or Spock) used to verify if server-side implementation of the API is compliant with the contract (__server tests__).
Full test is generated by Spring Cloud Contract Verifier.

Spring Cloud Contract Verifier moves TDD to the level of software architecture.

==== Why?

Let us assume that we have a system comprising of multiple microservices:

image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/docs/src/main/asciidoc/images/Deps.png[Microservices Architecture]

===== Testing issues

If we wanted to test the application in top left corner if it can communicate with other services then we could do one of two things:

- deploy all microservices and perform end to end tests
- mock other microservices in unit / integration tests

Both have their advantages but also a lot of disadvantages. Let's focus on the latter.

*Deploy all microservices and perform end to end tests*

Advantages:

- simulates production
- tests real communication between services

Disadvantages:

- to test one microservice we would have to deploy 6 microservices, a couple of databases etc.
- the environment where the tests would be conducted would be locked for a single suite of tests (i.e. nobody else would be able to run the tests in the meantime).
- long to run
- very late feedback
- extremely hard to debug

*Mock other microservices in unit / integration tests*

Advantages:

- very fast feedback
- no infrastructure requirements

Disadvantages:

- the implementor of the service creates stubs thus they might have nothing to do with the reality
- you can go to production with passing tests and failing production

To solve the aforementioned issues Spring Cloud Contract Verifier with Stub Runner were created. Their main idea is to give you very fast feedback, without the need
to set up the whole world of microservices.

image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/docs/src/main/asciidoc/images/Stubs1.png[Stubbed Services]

If you work on stubs then the only applications you need are those that your application is using directly.

image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/docs/src/main/asciidoc/images/Stubs2.png[Stubbed Services]

Spring Cloud Contract Verifier gives you the certainty that the stubs that you're using were created by the service that you're calling. Also if you can use them it means that they were
tested against the producer's side. In other words - you can trust those stubs.


==== Purposes

The main purposes of Spring Cloud Contract Verifier with Stub Runner are:

  - to ensure that WireMock / Messaging stubs (used when developing the client) are doing exactly what actual server-side implementation will do,
  - to promote ATDD method and Microservices architectural style,
  - to provide a way to publish changes in contracts that are immediately visible on both sides,
  - to generate boilerplate test code used on the server side.

==== Client Side

During the tests you want to have a Wiremock instance / Messaging route up and running that simulates the service Y.
You would like to feed that instance with a proper stub definition. That stub definition would need
to be valid and should also be reusable on the server side.

__Summing it up:__ On this side, in the stub definition, you can use patterns for request stubbing and you need exact
values for responses.

==== Server Side

Being a service Y since you are developing your stub, you need to be sure that it's actually resembling your
concrete implementation. You can't have a situation where your stub acts in one way and your application on
production behaves in a different way.

That's why from the provided stub acceptance tests will be generated that will ensure
that your application behaves in the same way as you define in your stub.

__Summing it up:__ On this side, in the stub definition, you need exact values as request and can use patterns/methods
for response verification.

==== Step by step guide to CDC

Let's take an example of Fraud Detection and Loan Issuance process. The business scenario is such that we want to issue loans to people but don't want them to steal the money from us. The current implementation of our system grants loans to everybody.

Let's assume that the `Loan Issuance` is a client to the
`Fraud Detection` server. In the current sprint we are required to develop a new feature - if a client wants to borrow too much money then we mark him as fraud.

Technical remark - Fraud Detection will have artifact id `http-server`, Loan Issuance `http-client` and both have group id `com.example`.

Social remark - both client and server development teams need to communicate directly and discuss changes while
going through the process. CDC is all about communication.

The https://github.com/spring-cloud/spring-cloud-contract/tree/master/samples/standalone/http-server[server side code is available here] and https://github.com/spring-cloud/spring-cloud-contract/tree/master/samples/standalone/http-client[the client side code here].

===== Consumer side (Loan Issuance)

As a developer of the Loan Issuance service (a consumer of the Fraud Detection server):

*start doing TDD by writing a test to your feature*

[source,groovy,indent=0]
----
@Test
public void shouldBeRejectedDueToAbnormalLoanAmount() {
    // given:
    LoanApplication application = new LoanApplication(new Client("1234567890"),
            99999);
    // when:
    LoanApplicationResult loanApplication = sut.loanApplication(application);
    // then:
    assertThat(loanApplication.getLoanApplicationStatus())
            .isEqualTo(LoanApplicationStatus.LOAN_APPLICATION_REJECTED);
    assertThat(loanApplication.getRejectionReason()).isEqualTo("Amount too high");
}
----

We've just written a test of our new feature. If a loan application for a big amount is received we should reject that loan application with some description.

*write the missing implementation*

At some point in time you need to send a request to the Fraud Detection service. Let's assume that we'd like to send the request containing the id of the client and the amount he wants to borrow from us. We'd like to send it to the `/fraudcheck` url via the `PUT` method.

[source,groovy,indent=0]
----
ResponseEntity<FraudServiceResponse> response =
        restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT,
                new HttpEntity<>(request, httpHeaders),
                FraudServiceResponse.class);
----

For simplicity we've hardcoded the port of the Fraud Detection service at `8080` and our application is running on `8090`.

If we'd start the written test it would obviously break since we have no service running on port `8080`.

*clone the Fraud Detection service repository locally*

We'll start playing around with the server side contract. That's why we need to first clone it.

[source,bash,indent=0]
----
git clone https://your-git-server.com/server-side.git local-http-server-repo
----

*define the contract locally in the repo of Fraud Detection service*

As consumers we need to define what exactly we want to achieve. We need to formulate our expectations. That's why we write the following contract.

[source,groovy,indent=0]
----
package contracts

org.springframework.cloud.contract.spec.Contract.make {
				request {
				method 'PUT'
				url '/fraudcheck'
				body("""
					{
					"clientId":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
					"loanAmount":99999}
				"""
				)
				headers {
					header('Content-Type', 'application/vnd.fraud.v1+json')
				}

			}
			response {
				status 200
				body( """{
	"fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}",
	"rejectionReason": "Amount too high"
}""")
				headers {
					 header('Content-Type': value(server(regex('application/vnd.fraud.v1.json.*')), client('application/vnd.fraud.v1+json')))
					}
			}

}
----

The Contract is written using a statically typed Groovy DSL. You might be wondering what are those `${value(client(...), server(...))}` parts. So the `${}` is a String interpolation in Groovy. You can resolve a variable inside a String. In other words `"concat ${foo} and ${bar}"` is the same as `"concat " + foo + " and " + bar`. The `value(client(...), server(...))` allows you to define parts of a JSON which are dynamic. In case of an identifier or a timestamp you don't want to hardcode a value. You want to allow some different ranges of values. That's why for the consumer side you can set regular expressions matching those values. You can provide the body either by means of String with interpolations or with a map notation. https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_contract_dsl[Consult the docs for more information.]

The aforementioned contract is an agreement between two sides that:

- if an HTTP request is sent with
** a method `PUT` on an endpoint `/fraudcheck`
** JSON body with `clientId` matching the regular expression `[0-9]{10}` and `loanAmount` equal to `99999`
** and with a header `Content-Type` equal to `application/vnd.fraud.v1+json`
- then an HTTP response would be sent to the consumer that
** has status `200`
** contains JSON body with the `fraudCheckStatus` field containing a value `FRAUD` and the `rejectionReason` field having value `Amount too high`
** and a `Content-Type` header with a value of `application/vnd.fraud.v1+json`

Once we're ready to check the API in practice in the integration tests we need to just install the stubs locally

*add the Spring Cloud Contract Verifier plugin*

We can add either Maven or Gradle plugin - in this example we'll show how to add Maven. First we need to add the `Spring Cloud Contract` BOM.

[source,xml,indent=0]
----
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-contract-dependencies</artifactId>
            <version>${spring-cloud-contract.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
----

Next, the `Spring Cloud Contract Verifier` Maven plugin

[source,xml,indent=0]
----
<plugin>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-contract-maven-plugin</artifactId>
    <version>${spring-cloud-contract.version}</version>
    <extensions>true</extensions>
    <configuration>
        <baseClassForTests>com.example.fraud.MvcTest</baseClassForTests>
    </configuration>
</plugin>
----

Since the plugin was added we get the `Spring Cloud Contract Verifier` features which from the provided contracts:

- generate and run tests
- produce and install stubs

We don't want to generate tests since we, as consumers, want only to play with the stubs. That's why we need to skip the tests generation and execution. When we execute:

[source,bash,indent=0]
----
cd local-http-server-repo
./mvnw clean install -DskipTests
----

In the logs we'll see something like this:

[source,bash,indent=0]
----
[INFO] --- spring-cloud-contract-maven-plugin:1.0.0.BUILD-SNAPSHOT:generateStubs (default-generateStubs) @ http-server ---
[INFO] Building jar: /some/path/http-server/target/http-server-0.0.1-SNAPSHOT-stubs.jar
[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ http-server ---
[INFO] Building jar: /some/path/http-server/target/http-server-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.4.0.BUILD-SNAPSHOT:repackage (default) @ http-server ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ http-server ---
[INFO] Installing /some/path/http-server/target/http-server-0.0.1-SNAPSHOT.jar to /path/to/your/.m2/repository/com/example/http-server/0.0.1-SNAPSHOT/http-server-0.0.1-SNAPSHOT.jar
[INFO] Installing /some/path/http-server/pom.xml to /path/to/your/.m2/repository/com/example/http-server/0.0.1-SNAPSHOT/http-server-0.0.1-SNAPSHOT.pom
[INFO] Installing /some/path/http-server/target/http-server-0.0.1-SNAPSHOT-stubs.jar to /path/to/your/.m2/repository/com/example/http-server/0.0.1-SNAPSHOT/http-server-0.0.1-SNAPSHOT-stubs.jar
----

This line is extremely important

[source,bash,indent=0]
----
[INFO] Installing /some/path/http-server/target/http-server-0.0.1-SNAPSHOT-stubs.jar to /path/to/your/.m2/repository/com/example/http-server/0.0.1-SNAPSHOT/http-server-0.0.1-SNAPSHOT-stubs.jar
----

It's confirming that the stubs of the `http-server` have been installed in the local repository.

*run the integration tests*

In order to profit from the Spring Cloud Contract Stub Runner functionality of automatic stub downloading you have to do the following in our consumer side project (`Loan Application service`).

Add the `Spring Cloud Contract` BOM

[source,xml,indent=0]
----
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-contract-dependencies</artifactId>
            <version>${spring-cloud-contract.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
----

Add the dependency to `Spring Cloud Contract Stub Runner`

[source,xml,indent=0]
----
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-contract-wiremock</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
    <scope>test</scope>
</dependency>
----

Provide the group id and artifact id for the Stub Runner to download stubs of your collaborators. Also provide the offline work switch since you're playing with the collaborators offline (optional step).

[source,yaml,indent=0]
----
stubrunner:
  work-offline: true
  stubs.ids: 'com.example:http-server:+:stubs:8080'
----

Annotate your test class with `@AutoConfigureStubRunner`

[source,groovy,indent=0]
----
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureStubRunner
public class LoanApplicationServiceTests {
----

Now if you run your tests you'll see sth like this:

[source,bash,indent=0]
----
2016-07-19 14:22:25.403  INFO 41050 --- [           main] o.s.c.c.stubrunner.AetherStubDownloader  : Desired version is + - will try to resolve the latest version
2016-07-19 14:22:25.438  INFO 41050 --- [           main] o.s.c.c.stubrunner.AetherStubDownloader  : Resolved version is 0.0.1-SNAPSHOT
2016-07-19 14:22:25.439  INFO 41050 --- [           main] o.s.c.c.stubrunner.AetherStubDownloader  : Resolving artifact com.example:http-server:jar:stubs:0.0.1-SNAPSHOT using remote repositories []
2016-07-19 14:22:25.451  INFO 41050 --- [           main] o.s.c.c.stubrunner.AetherStubDownloader  : Resolved artifact com.example:http-server:jar:stubs:0.0.1-SNAPSHOT to /path/to/your/.m2/repository/com/example/http-server/0.0.1-SNAPSHOT/http-server-0.0.1-SNAPSHOT-stubs.jar
2016-07-19 14:22:25.465  INFO 41050 --- [           main] o.s.c.c.stubrunner.AetherStubDownloader  : Unpacking stub from JAR [URI: file:/path/to/your/.m2/repository/com/example/http-server/0.0.1-SNAPSHOT/http-server-0.0.1-SNAPSHOT-stubs.jar]
2016-07-19 14:22:25.475  INFO 41050 --- [           main] o.s.c.c.stubrunner.AetherStubDownloader  : Unpacked file to [/var/folders/0p/xwq47sq106x1_g3dtv6qfm940000gq/T/contracts100276532569594265]
2016-07-19 14:22:27.737  INFO 41050 --- [           main] o.s.c.c.stubrunner.StubRunnerExecutor    : All stubs are now running RunningStubs [namesAndPorts={com.example:http-server:0.0.1-SNAPSHOT:stubs=8080}]
----

Which means that Stub Runner has found your stubs and started a server for app with group id `com.example`, artifact id `http-server` with version `0.0.1-SNAPSHOT` of the stubs and with `stubs` classifier on port `8080`.

*file a PR*

What we did until now is an iterative process. We can play around with the contract, install it locally and work on the consumer side until we're happy with the contract.

Once we're satisfied with the results and the test passes publish a PR to the server side. Currently the consumer side work is done.

===== Producer side (Fraud Detection server)

As a developer of the Fraud Detection server (a server to the Loan Issuance service):

*initial implementation*

As a reminder here you can see the initial implementation

[source,java,indent=0]
----
@RequestMapping(
        value = "/fraudcheck",
        method = PUT,
        consumes = FRAUD_SERVICE_JSON_VERSION_1,
        produces = FRAUD_SERVICE_JSON_VERSION_1)
public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) {
return new FraudCheckResult(FraudCheckStatus.OK, NO_REASON);
}
----

*take over the PR*

[source,bash,indent=0]
----
git checkout -b contract-change-pr master
git pull https://your-git-server.com/server-side-fork.git contract-change-pr
----

You have to add the dependencies needed by the autogenerated tests

[source,xml,indent=0]
----
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-contract-verifier</artifactId>
    <scope>test</scope>
</dependency>
----

In the configuration of the Maven plugin we passed the `baseClassForTests` property

[source,xml,indent=0]
----
<plugin>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-contract-maven-plugin</artifactId>
    <version>${spring-cloud-contract.version}</version>
    <extensions>true</extensions>
    <configuration>
        <baseClassForTests>com.example.fraud.MvcTest</baseClassForTests>
    </configuration>
</plugin>
----

That's because all the generated tests will extend that class. Over there you can set up your Spring Context or whatever is necessary. In our case we're using http://rest-assured.io/[Rest Assured MVC] to start the server side `FraudDetectionController`.

[source,java,indent=0]
----
package com.example.fraud;

import com.example.fraud.FraudDetectionController;
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc;

import org.junit.Before;

public class MvcTest {

	@Before
	public void setup() {
		RestAssuredMockMvc.standaloneSetup(new FraudDetectionController());
	}

	public void assertThatRejectionReasonIsNull(Object rejectionReason) {
		assert rejectionReason == null;
	}
}
----

Now, if you run the `./mvnw clean install` you would get sth like this:

[source,bash,indent=0]
----
Results :

Tests in error:
  ContractVerifierTest.validate_shouldMarkClientAsFraud:32 » IllegalState Parsed...
----

That's because you have a new contract from which a test was generated and it failed since you haven't implemented the feature. The autogenerated test would look like this:

[source,java,indent=0]
----
@Test
public void validate_shouldMarkClientAsFraud() throws Exception {
    // given:
        MockMvcRequestSpecification request = given()
                .header("Content-Type", "application/vnd.fraud.v1+json")
                .body("{\"clientId\":\"1234567890\",\"loanAmount\":99999}");

    // when:
        ResponseOptions response = given().spec(request)
                .put("/fraudcheck");

    // then:
        assertThat(response.statusCode()).isEqualTo(200);
        assertThat(response.header("Content-Type")).matches("application/vnd.fraud.v1.json.*");
    // and:
        DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
        assertThatJson(parsedJson).field("fraudCheckStatus").matches("[A-Z]{5}");
        assertThatJson(parsedJson).field("rejectionReason").isEqualTo("Amount too high");
}
----

As you can see all the `server()` parts of the Contract that were present in the `value(client(...), server(...))` blocks got injected into the test.

What's important here to note is that on the producer side we also are doing TDD. We have expectations in form of a test. This test is shooting a request to our own application to an URL, headers and body defined in the contract. It also is expecting very precisely defined values in the response. In other words you have is your `red` part of `red`, `green` and `refactor`. Time to convert the `red` into the `green`.

*write the missing implementation*

Now since we now what is the expected input and expected output let's write the missing implementation.

[source,java,indent=0]
----
@RequestMapping(
        value = "/fraudcheck",
        method = PUT,
        consumes = FRAUD_SERVICE_JSON_VERSION_1,
        produces = FRAUD_SERVICE_JSON_VERSION_1)
public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) {
if (amountGreaterThanThreshold(fraudCheck)) {
    return new FraudCheckResult(FraudCheckStatus.FRAUD, AMOUNT_TOO_HIGH);
}
return new FraudCheckResult(FraudCheckStatus.OK, NO_REASON);
}
----

If we execute `./mvnw clean install` again the tests will pass. Since the `Spring Cloud Contract Verifier` plugin adds the tests to the `generated-test-sources` you can actually run those tests from your IDE.

*deploy your app*

Once you've finished your work it's time to deploy your change. First merge the branch

[source,bash,indent=0]
----
git checkout master
git merge --no-ff contract-change-pr
git push origin master
----

Then we assume that your CI would run sth like `./mvnw clean deploy` which would publish both the application and the stub artifcats.

===== Consumer side (Loan Issuance) final step

As a developer of the Loan Issuance service (a consumer of the Fraud Detection server):

*merge branch to master*

[source,bash,indent=0]
----
git checkout master
git merge --no-ff contract-change-pr
----

*work online*

Now you can disable the offline work for Spring Cloud Contract Stub Runner ad provide where the repository with your stubs is placed. At this moment the stubs of the server side will be automatically downloaded from Nexus / Artifactory.

[source,yaml,indent=0]
----
stubrunner.stubs:
  ids: 'com.example:http-server:+:stubs:8080'
  repositoryRoot: http://repo.spring.io/libs-snapshot
----

And that's it!

==== Dependencies

Spring Cloud Contract Verifier and Stub Runner are using the following libraries

- http://wiremock.org/[WireMock]
- https://github.com/jayway/JsonPath[Jayway JSONPath]
- https://github.com/marcingrzejszczak/jsonassert[JSONAssert from Marcin Grzejszczak]

==== Additional links

Below you can find some resources related to Spring Cloud Contract Verifier and Stub Runner. Note that some can be outdated since the Spring Cloud Contract Verifier project
is under constant development.

===== Videos

*Marcin Grzejszczak and Jakub Kubryński talking about Spring Cloud Contract Verifier*

video::msRFcQM07-Y[youtube]

https://www.youtube.com/watch?v=msRFcQM07-Y[click here to see the video]

*Olga Maciaszek-Sharma talking about Accurest (Spring Cloud Contract Verifier predecessor)*

video::daafmTYFoDU[youtube]

https://www.youtube.com/watch?v=daafmTYFoDU[click here to see the video]

*Marcin Grzejszczak and Jakub Kubryński talking about Accurest (Spring Cloud Contract Verifier predecessor)*

video::130779882[vimeo]

https://vimeo.com/130779882[click here to see the video]

===== Readings

- http://www.slideshare.net/MarcinGrzejszczak/stick-to-the-rules-consumer-driven-contracts-201507-confitura[Slides from Marcin Grzejszczak's talk about Accurest]
- http://toomuchcoding.com/blog/categories/accurest/[Accurest related articles from Marcin Grzejszczak's blog]
- http://toomuchcoding.com/blog/categories/spring-cloud-contract/[Spring Cloud Contract related articles from Marcin Grzejszczak's blog]

==== Samples

Here you can find some https://github.com/spring-cloud/spring-cloud-contract/tree/master/samples/[samples].

==== Why use Spring Cloud Contract Verifier and not X ?

For the time being Spring Cloud Contract Verifier is a JVM based tool. So it could be your first pick when you're already creating
software for the JVM. This project has a lot of really interesting features but especially quite a few of them definitely make
Spring Cloud Contract Verifier stand out on the "market" of Consumer Driven Contract (CDC) tooling. Out of many the most interesting are:

- Possibility to do CDC with messaging
- Clear and easy to use, statically typed DSL
- Possibility to copy paste your current JSON file to the contract and only edit its elements
- Automatic generation of tests from the defined Contract
- Stub Runner functionality - the stubs are automatically downloaded at runtime from Nexus / Artifactory
- Spring Cloud integration - no discovery service is needed for integration tests

=== Links

Here you can find interesting links related to Spring Cloud Contract Verifier:

- https://github.com/spring-cloud/spring-cloud-contract/[Spring Cloud Contract Verifier Github Repository]
- https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html[Spring Cloud Contract Verifier Documentation]
- https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html/deprecated[Accurest Legacy Documentation]
- https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html/#spring-cloud-contract-stub-runner[Spring Cloud Contract Stub Runner Documentation]
- https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html/#stub-runner-for-messaging[Spring Cloud Contract Stub Runner Messaging Documentation]
- https://gitter.im/spring-cloud/spring-cloud-contract[Spring Cloud Contract Verifier Gitter]
- https://github.com/spring-cloud/spring-cloud-contract[Spring Cloud Contract Verifier Maven Plugin]

== Documentation

You can read more about Spring Cloud Contract Verifier by reading the {documentation_url}[docs]

== Contributing

Spring Cloud is released under the non-restrictive Apache 2.0 license,
and follows a very standard Github development process, using Github
tracker for issues and merging pull requests into master. If you want
to contribute even something trivial please do not hesitate, but
follow the guidelines below.

=== Sign the Contributor License Agreement
Before we accept a non-trivial patch or pull request we will need you to sign the
https://cla.pivotal.io/sign/spring[Contributor License Agreement].
Signing the contributor's agreement does not grant anyone commit rights to the main
repository, but it does mean that we can accept your contributions, and you will get an
author credit if we do.  Active contributors might be asked to join the core team, and
given the ability to merge pull requests.

=== Code of Conduct
This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc[code of
conduct]. By participating, you  are expected to uphold this code. Please report
unacceptable behavior to spring-code-of-conduct@pivotal.io.

=== Code Conventions and Housekeeping
None of these is essential for a pull request, but they will all help.  They can also be
added after the original pull request but before a merge.

* Use the Spring Framework code format conventions. If you use Eclipse
  you can import formatter settings using the
  `eclipse-code-formatter.xml` file from the
  https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring
  Cloud Build] project. If using IntelliJ, you can use the
  http://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter
  Plugin] to import the same file.
* Make sure all new `.java` files to have a simple Javadoc class comment with at least an
  `@author` tag identifying you, and preferably at least a paragraph on what the class is
  for.
* Add the ASF license header comment to all new `.java` files (copy from existing files
  in the project)
* Add yourself as an `@author` to the .java files that you modify substantially (more
  than cosmetic changes).
* Add some Javadocs and, if you change the namespace, some XSD doc elements.
* A few unit tests would help a lot as well -- someone has to do it.
* If no-one else is using your branch, please rebase it against the current master (or
  other target branch in the main project).
* When writing a commit message please follow http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions],
  if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit
  message (where XXXX is the issue number).

== How to build it

=== Project structure

Here you can find the Spring Cloud Contract folder structure

```
├── samples
├── scripts
├── spring-cloud-contract-spec
├── spring-cloud-contract-stub-runner
├── spring-cloud-contract-tools
└── spring-cloud-contract-verifier
```

 - `samples` - folder contains test samples together with standalone ones used also to build documentation
 - `scripts` - contains scripts to build and test `Spring Cloud Contract` with Maven, Gradle and standalone projects
 - `spring-cloud-contract-spec` - contains specification modules (contains concept of a Contract)
 - `spring-cloud-contract-stub-runner` - contains Stub Runner related modules
 - `spring-cloud-contract-tools` - Gradle and Maven plugin for `Spring Cloud Contract Verifier`
 - `spring-cloud-contract-verifier` - core of the `Spring Cloud Contract Verifier` functionality

=== Commands

To build the core functionality together with Maven Plugin you can run

```
./mvnw clean install
```

To build the Gradle Plugin

```
cd spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin
./gradlew clean build
```

=== Scripts

For your convenience we have created a bunch of scripts to build and test the whole functionality.

Build both Maven and Gradle project

```
./scripts/build.sh
```

Run tests on the standalone projects

```
./scripts/runTests.sh
```

Build both Maven and Gradle projects and run tests on standalone projects

```
./scripts/buildAndTest.sh
```

Generate documentation

```
./scripts/generateDocs.sh
```

Publish documentation to `gh-pages`

```
./docs/src/main/asciidoc/ghpages.sh
```