Updated docs with a fast intro

This commit is contained in:
Marcin Grzejszczak
2016-07-15 14:27:03 +02:00
parent bc22227fe3
commit a8a1bc1f2e
16 changed files with 253 additions and 106 deletions

View File

@@ -1,32 +1,24 @@
// Do not edit this file (e.g. go instead to src/main/asciidoc)
:core_path: ../../../..
:verifier_root_path: {core_path}/spring-cloud-contract-verifier
:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core
:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner
:documentation_url: http://cloud.spring.io/spring-cloud-contract/
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"]
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
== 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
=== 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
:images_url: https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/docs/src/main/asciidoc/images
=== Spring Cloud Contract Verifier
== Introduction
@@ -130,6 +122,104 @@ 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. Let's assume that the Loan Issuance is a client to the
Fraud Detection server. Let's assume that we have to write a new feature (if a client wants too borrow too much money then
we mark him as fraud). The current implementation grants loan to everybody.
Of course both client and server development teams need to communicate directly and discuss changes while
going through the process. CDC is all about communication.
The code is available under the `samples/samples-standalone/http-server` and `samples/samples-standalone/http-client` folders.
As a developer of the Loan Issuance service (a consumer to the Fraud Detection server):
- start doing TDD by writing a test to your feature
- at some point in time you need to send a request to the Fraud Detection service
- you clone the Fraud Detection service repository locally
- you define the contract locally in the repo of Fraud Detection service
- provide the group id and artifact id for the Spring Cloud Contract Stub Runner to download stubs of your collaborators
- also provide the offline work switch since you don't want to work offline
- when you need to install the stubs of the server side you execute e.g. `./mvnw clean install -DskipTests` in their repo
- when you're happy with the contract and your test passes publish a PR to the server side
As a developer of the Fraud Detection server (a server to the Loan Issuance service):
- take over the PR (if you try to build it your app will break cause you have a missing implementation)
- write the missing implementation
- deploy your app with the stubs e.g. `./mvnw clean deploy` you'll publish both the application fat jar and the stub jar
As a developer of the Loan Issuance service (a consumer to the Fraud Detection server):
- since the server side work was done you can merge the branch to master
- disable the offline work for Spring Cloud Contract Stub Runner
- at this moment the stubs of the server side will be automatically downloaded from Nexus / Artifactory
Code examples:
*CLIENT*
*start doing TDD*
[source,groovy,indent=0]
----
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-client/src/test/groovy/com/example/loan/LoanApplicationServiceSpec.groovy[tags=client_tdd,indent=0]
----
*at some point in time you need to send a request to the Fraud Detection service*
[source,groovy,indent=0]
----
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-client/src/main/java/com/example/loan/LoanApplicationService.java[tags=client_call_server,indent=0]
----
*you define the contract locally in the repo of Fraud Detection service*
[source,groovy,indent=0]
----
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-server/src/test/resources/contracts/shouldMarkClientAsFraud.groovy[]
----
*provide the group id and artifact id for the Spring Cloud Contract Stub Runner to download stubs of your collaborators*
*also provide the offline work switch since you don't want to work offline*
[source,groovy,indent=0]
----
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-client/src/test/resources/application.yaml[]
----
*SERVER*
*take over the PR (if you try to build it your app will break cause you have a missing implementation)*
the API
[source,java,indent=0]
----
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=server_api,indent=0]
}
----
the initial impl
[source,java,indent=0]
----
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=server_api,indent=0]
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=initial_impl,indent=0]
}
----
*write the missing implementation*
[source,java,indent=0]
----
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=server_api,indent=0]
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=new_impl,indent=0]
Unresolved directive in verifier/introduction.adoc - include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=initial_impl,indent=0]
}
----
=== Dependencies
Spring Cloud Contract Verifier and Stub Runner are using the following libraries

View File

@@ -1,25 +1,19 @@
:core_path: ../../../..
:verifier_root_path: {core_path}/spring-cloud-contract-verifier
:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core
:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner
:documentation_url: http://cloud.spring.io/spring-cloud-contract/
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"]
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
== 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
=== Spring Cloud Contract WireMock
include::spring-cloud-wiremock.adoc[]
== Spring Cloud Contract Verifier
=== Spring Cloud Contract Verifier
include::verifier/introduction.adoc[]

View File

@@ -1,23 +1,11 @@
:core_path: ../../../../..
:verifier_root_path: {core_path}/spring-cloud-contract-verifier
:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core
:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner
:toc: left
= Spring Cloud Contract
_Documentation Authors: Adam Dudczak, Marcin Grzejszczak, Jakub Kubryński, Karol Lassak, Olga Maciaszek-Sharma, Mariusz Smykuła_
include::verifier/introduction.adoc[]
== Spring Cloud Contract Verifier
include::verifier/contract.adoc[]
include::verifier/spring-cloud-contract-verifier.adoc[]
include::verifier/rest.adoc[]
== Spring Cloud Contract WireMock
include::verifier/messaging.adoc[]
include::verifier/stubrunner.adoc[]
include::verifier/stubrunner_msg.adoc[]
include::verifier/links.adoc[]
include::spring-cloud-wiremock.adoc[]

View File

@@ -1,7 +1,3 @@
:core_path: ../../../../..
:verifier_root_path: {core_path}/spring-cloud-contract-verifier
:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core
== Contract DSL
IMPORTANT: Remember that inside the contract file you have to provide the fully qualified name to
@@ -201,7 +197,7 @@ The output message can be triggered by calling a method (e.g. a Scheduler was st
[source,groovy]
----
include::../../../../samples/samples-messaging-integration/src/test/groovy/com/example/IntegrationMessagingApplicationSpec.groovy[tags=method_trigger,indent=0]
include::{samples_path}/samples-messaging-integration/src/test/groovy/com/example/IntegrationMessagingApplicationSpec.groovy[tags=method_trigger,indent=0]
----
In this case the output message will be sent to `output` if a method called `bookReturnedTriggered` will be executed. In the message *publisher's* side
@@ -213,7 +209,7 @@ The output message can be triggered by receiving a message.
[source,groovy]
----
include::../../../../samples/samples-messaging-integration/src/test/groovy/com/example/IntegrationMessagingApplicationSpec.groovy[tags=message_trigger,indent=0]
include::{samples_path}/samples-messaging-integration/src/test/groovy/com/example/IntegrationMessagingApplicationSpec.groovy[tags=message_trigger,indent=0]
----
In this case the output message will be sent to `output` if a proper message will be received on the `input` destination. In the message *publisher's* side

View File

@@ -1,5 +1,3 @@
:images_url: https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/docs/src/main/asciidoc/images
== Introduction
IMPORTANT: http://codearte.github.io/accurest[The documentation to the deprecated Accurest project in version 1.1.0 is available here.]
@@ -102,6 +100,104 @@ 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. Let's assume that the Loan Issuance is a client to the
Fraud Detection server. Let's assume that we have to write a new feature (if a client wants too borrow too much money then
we mark him as fraud). The current implementation grants loan to everybody.
Of course both client and server development teams need to communicate directly and discuss changes while
going through the process. CDC is all about communication.
The code is available under the `samples/samples-standalone/http-server` and `samples/samples-standalone/http-client` folders.
As a developer of the Loan Issuance service (a consumer to the Fraud Detection server):
- start doing TDD by writing a test to your feature
- at some point in time you need to send a request to the Fraud Detection service
- you clone the Fraud Detection service repository locally
- you define the contract locally in the repo of Fraud Detection service
- provide the group id and artifact id for the Spring Cloud Contract Stub Runner to download stubs of your collaborators
- also provide the offline work switch since you don't want to work offline
- when you need to install the stubs of the server side you execute e.g. `./mvnw clean install -DskipTests` in their repo
- when you're happy with the contract and your test passes publish a PR to the server side
As a developer of the Fraud Detection server (a server to the Loan Issuance service):
- take over the PR (if you try to build it your app will break cause you have a missing implementation)
- write the missing implementation
- deploy your app with the stubs e.g. `./mvnw clean deploy` you'll publish both the application fat jar and the stub jar
As a developer of the Loan Issuance service (a consumer to the Fraud Detection server):
- since the server side work was done you can merge the branch to master
- disable the offline work for Spring Cloud Contract Stub Runner
- at this moment the stubs of the server side will be automatically downloaded from Nexus / Artifactory
Code examples:
*CLIENT*
*start doing TDD*
[source,groovy,indent=0]
----
include::{standalone_samples_path}/http-client/src/test/groovy/com/example/loan/LoanApplicationServiceSpec.groovy[tags=client_tdd,indent=0]
----
*at some point in time you need to send a request to the Fraud Detection service*
[source,groovy,indent=0]
----
include::{standalone_samples_path}/http-client/src/main/java/com/example/loan/LoanApplicationService.java[tags=client_call_server,indent=0]
----
*you define the contract locally in the repo of Fraud Detection service*
[source,groovy,indent=0]
----
include::{standalone_samples_path}/http-server/src/test/resources/contracts/shouldMarkClientAsFraud.groovy[]
----
*provide the group id and artifact id for the Spring Cloud Contract Stub Runner to download stubs of your collaborators*
*also provide the offline work switch since you don't want to work offline*
[source,groovy,indent=0]
----
include::{standalone_samples_path}/http-client/src/test/resources/application.yaml[]
----
*SERVER*
*take over the PR (if you try to build it your app will break cause you have a missing implementation)*
the API
[source,java,indent=0]
----
include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=server_api,indent=0]
}
----
the initial impl
[source,java,indent=0]
----
include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=server_api,indent=0]
include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=initial_impl,indent=0]
}
----
*write the missing implementation*
[source,java,indent=0]
----
include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=server_api,indent=0]
include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=new_impl,indent=0]
include::{standalone_samples_path}/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=initial_impl,indent=0]
}
----
=== Dependencies
Spring Cloud Contract Verifier and Stub Runner are using the following libraries

View File

@@ -1,7 +1,3 @@
:core_path: ../../../../..
:verifier_root_path: {core_path}/spring-cloud-contract-verifier
:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core
== Spring Cloud Contract Verifier Messaging
Spring Cloud Contract Verifier allows you to verify your application that uses messaging as means of communication.

View File

@@ -1,14 +1,10 @@
:core_path: ../../../../..
:verifier_root_path: {core_path}/spring-cloud-contract-verifier
:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core
== Spring Cloud Contract Verifier HTTP
=== Gradle Project
==== Prerequisites
In order to use Spring Cloud Contract Verifier with Wiremock you have to use gradle or maven plugin.
In order to use Spring Cloud Contract Verifier with WireMock you have to use gradle or maven plugin.
===== Add gradle plugin

View File

@@ -0,0 +1,21 @@
:core_path: ../../../../..
:verifier_root_path: {core_path}/spring-cloud-contract-verifier
:samples_path: {core_path}/samples
:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core
:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner
:standalone_samples_path: {samples_path}/samples-standalone
:images_url: https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/docs/src/main/asciidoc/images
include::introduction.adoc[]
include::contract.adoc[]
include::rest.adoc[]
include::messaging.adoc[]
include::stubrunner.adoc[]
include::stubrunner_msg.adoc[]
include::links.adoc[]

View File

@@ -1,7 +1,3 @@
:core_path: ../../../../..
:verifier_root_path: {core_path}/spring-cloud-contract-verifier
:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core
== Spring Cloud Contract Stub Runner
One of the issues that you could have encountered while using Spring Cloud Contract Verifier was to pass the generated WireMock JSON stubs from the server side to the client side (or various clients).
@@ -53,15 +49,17 @@ Spring Cloud Contract Stub Runner comes with a new structure of modules
└── spring-cloud-contract-stub-runner-spring-cloud
----
include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/README.adoc[]
include::{stubrunner_core_path}/spring-cloud-contract-stub-runner/README.adoc[]
include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-boot/README.adoc[]
include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-boot/README.adoc[]
include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-junit/README.adoc[]
include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-jetty/README.adoc[]
include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring/README.adoc[]
include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-junit/README.adoc[]
include::../../../../spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-spring-cloud/README.adoc[]
include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-spring/README.adoc[]
include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-spring-cloud/README.adoc[]
=== Common properties for JUnit and Spring

View File

@@ -1,8 +1,3 @@
:core_path: ../../../../..
:verifier_root_path: {core_path}/spring-cloud-contract-verifier
:verifier_core_path: {verifier_root_path}/spring-cloud-contract-verifier-core
:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner
== Stub Runner for Messaging
Stub Runner has the functionality to run the published stubs in memory. It can integrate with the following frameworks out of the box

View File

@@ -43,10 +43,12 @@ public class LoanApplicationService {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1);
// tag::client_call_server[]
ResponseEntity<FraudServiceResponse> response =
restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT,
new HttpEntity<>(request, httpHeaders),
FraudServiceResponse.class);
// end::client_call_server[]
return response.getBody();
}

View File

@@ -30,6 +30,7 @@ class LoanApplicationServiceSpec extends Specification {
loanApplication.rejectionReason == null
}
// tag::client_tdd[]
def 'should be rejected due to abnormal loan amount'() {
given:
LoanApplication application =
@@ -40,5 +41,6 @@ class LoanApplicationServiceSpec extends Specification {
loanApplication.loanApplicationStatus == LoanApplicationStatus.LOAN_APPLICATION_REJECTED
loanApplication.rejectionReason == 'Amount too high'
}
// end::client_tdd[]
}

View File

@@ -20,16 +20,22 @@ public class FraudDetectionController {
private static final String AMOUNT_TOO_HIGH = "Amount too high";
private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000");
// tag::server_api[]
@RequestMapping(
value = "/fraudcheck",
method = PUT,
consumes = FRAUD_SERVICE_JSON_VERSION_1,
produces = FRAUD_SERVICE_JSON_VERSION_1)
public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) {
// end::server_api[]
// tag::new_impl[]
if (amountGreaterThanThreshold(fraudCheck)) {
return new FraudCheckResult(FraudCheckStatus.FRAUD, AMOUNT_TOO_HIGH);
}
// end::new_impl[]
// tag::initial_impl[]
return new FraudCheckResult(FraudCheckStatus.OK, NO_REASON);
// end::initial_impl[]
}
private boolean amountGreaterThanThreshold(FraudCheck fraudCheck) {

View File

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

View File

@@ -1,3 +1,3 @@
=== Stub Runner Jetty
Convenience module that pulls together the dependencies needed to run the Stub Runner with wiremock, but without Spring Boot.
Convenience module that pulls together the dependencies needed to run the Stub Runner with WireMock, but without Spring Boot.

View File

@@ -34,39 +34,6 @@ You can set the following options to the main class:
(default: false)
----
===== Building a Fat Jar
Just call the following command:
[source,groovy,indent=0]
----
./gradlew spring-cloud-contract-stub-runner-root:spring-cloud-contract-stub-runner:shadowJar -PfatJar
----
and inside the `build/lib` there will be a Fat Jar with classifier `fatJar` waiting for you to execute. E.g.
[source,groovy,indent=0]
----
java -jar spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/build/libs/spring-cloud-contract-stub-runner-1.0.0-SNAPSHOT-fatJar.jar -sr http://a.b.com -s a:b:c,d:e,f:g:h:i
----
==== Stub runner configuration
You can configure the stub runner by either passing the full arguments list with the `-Pargs` like this:
[source,groovy,indent=0]
----
./gradlew spring-cloud-contract-stub-runner-root:spring-cloud-contract-stub-runner:run -Pargs="-c pl -minp 10000 -maxp 10005 -s a:b:c,d:e,f:g:h"
----
or each parameter separately with a `-P` prefix and without the hyphen `-` in the name of the param
[source,groovy,indent=0]
----
./gradlew spring-cloud-contract-stub-runner-root:spring-cloud-contract-stub-runner:run -Pc=pl -Pminp=10000 -Pmaxp=10005 -Ps=a:b:c,d:e,f:g:h
----
===== HTTP Stubs
Stubs are defined in JSON documents, whose syntax is defined in http://wiremock.org/stubbing.html[WireMock documentation]