From 936f1b558274baa7b60fb80a5e193ebf54dff498 Mon Sep 17 00:00:00 2001
From: buildmaster
Maven. // your tests go here // in this config class you define all controllers and mocked services - include::{samples_url}/producer_webflux/src/test/java/com/example/BeerRestBase.java[tags=config,indent=0] +@Configuration +@EnableAutoConfiguration +static class Config { + + @Bean + PersonCheckingService personCheckingService() { + return personToCheck -> personToCheck.age >= 20; + } + + @Bean + ProducerController producerController() { + return new ProducerController(personCheckingService()); + } +} }
The DSL for messaging looks a little bit different than the one that focuses on HTTP. The following sections explain the differences:
The output message can be triggered by calling a method (such as a Scheduler when a was
diff --git a/multi/multi__spring_cloud_contract_faq.html b/multi/multi__spring_cloud_contract_faq.html
index fcb948a7bf..806a1eb2e2 100644
--- a/multi/multi__spring_cloud_contract_faq.html
+++ b/multi/multi__spring_cloud_contract_faq.html
@@ -123,7 +123,7 @@ one to one to the contents of the repo.
Example of a <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-cloud-contract.version>2.1.0.BUILD-SNAPSHOT</spring-cloud-contract.version>
- <spring-cloud-dependencies.version>Finchley.BUILD-SNAPSHOT</spring-cloud-dependencies.version>
+ <spring-cloud-release.version>Finchley.BUILD-SNAPSHOT</spring-cloud-release.version>
<excludeBuildFolders>true</excludeBuildFolders>
</properties>
@@ -132,7 +132,7 @@ one to one to the contents of the repo.
Example of a The Accurest project was initially started by Marcin Grzejszczak and Jakub Kubrynski
-(codearte.io) Spring Cloud Contract Verifier enables Consumer Driven Contract (CDC) development of
+ Spring Cloud Contract Verifier enables Consumer Driven Contract (CDC) development of
JVM-based applications. It moves TDD to the level of software architecture. Spring Cloud Contract Verifier ships with Contract Definition Language (CDL). Contract
definitions are used to produce the following resources: Assume that we have a system consisting of multiple microservices: If we wanted to test the application in top left corner to determine whether it can
+Spring Cloud Contract Verifier. Before becoming Spring Cloud Contract, this project was called Accurest.
+It was created by Marcin Grzejszczak and Jakub Kubrynski
+from (codearte.io. The Assume that we have a system consisting of multiple microservices: If we wanted to test the application in top left corner to determine whether it can
communicate with other services, we could do one of two things: Both have their advantages but also a lot of disadvantages. Deploy all microservices and perform end to end tests Advantages: Disadvantages: Mock other microservices in unit/integration tests Advantages: Disadvantages: Spring Cloud Contract Verifier gives you the certainty that the stubs that you use 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 short, you can trust those stubs. The main purposes of Spring Cloud Contract Verifier with Stub Runner are: The main purposes of Spring Cloud Contract Verifier with Stub Runner are: Spring Cloud Contract Verifier’s purpose is NOT to start writing business
features in the contracts. Assume that we have a business use case of fraud check. If a
user can be a fraud for 100 different reasons, we would assume that you would create 2
contracts, one for the positive case and one for the negative case. Contract tests are
-used to test contracts between applications and not to simulate full behavior. This section explores how Spring Cloud Contract Verifier with Stub Runner works. This very brief tour walks through using Spring Cloud Contract: You can find a somewhat longer tour
-here. This section explores how Spring Cloud Contract Verifier with Stub Runner works. This very brief tour walks through using Spring Cloud Contract: You can find a somewhat longer tour
+here. To start working with Spring Cloud Contract, add files with Then add the Spring Cloud Contract Verifier dependency and plugin to your build file, as
shown in the following example: Use the Now, in your integration test, you can receive stubbed versions of HTTP responses or
-messages that are expected to be emitted by the collaborator service. This brief tour walks through using Spring Cloud Contract: You can find an even more brief tour
-here. This brief tour walks through using Spring Cloud Contract: You can find an even more brief tour
+here. To start working with For the HTTP stubs, a contract defines what kind of response should be returned for a
given request (taking into account the HTTP methods, URLs, headers, status codes, and so
@@ -240,7 +241,7 @@ to the following in the build logs: As consumers of services, we need to define what exactly we want to achieve. We need to
+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}] As consumers of services, we need to define what exactly we want to achieve. We need to
formulate our expectations. That is why we write contracts. Assume that you want to send a request containing the ID of a client company and the
amount it wants to borrow from us. You also want to send it to the /fraudcheck url via
the PUT method. Groovy DSL.
@@ -354,7 +355,7 @@ response: # (7)
#(9) - and JSON body equal to
# { "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" }
#(10) - with header `Content-Type` equal to `application/json;charset=UTF-8`
- Spring Cloud Contract generates stubs, which you can use during client-side testing.
+ Spring Cloud Contract generates stubs, which you can use during client-side testing.
You get a running WireMock instance/Messaging route that simulates the service.
You would like to feed that instance with a proper stub definition. At some point in time, you need to send a request to the Fraud Detection service. At som
@DirtiesContext
public class LoanApplicationServiceTests { After that, during the tests, Spring Cloud Contract automatically finds the stubs
(simulating the real service) in the Maven repository and exposes them on a configured
-(or random) port. Since you are developing your stub, you need to be sure that it actually resembles your
+(or random) port. Since you are developing your stub, you need to be sure that it actually resembles your
concrete implementation. You cannot have a situation where your stub acts in one way and
your application behaves in a different way, especially in production. To ensure that your application behaves the way you define in your stub, tests are
generated from the stub you provide. The autogenerated test looks, more or less, like this: The autogenerated test looks, more or
DocumentContext parsedJson = JsonPath.parse(response.getBody().asString());
assertThatJson(parsedJson).field("['fraudCheckStatus']").matches("[A-Z]{5}");
assertThatJson(parsedJson).field("['rejection.reason']").isEqualTo("Amount too high");
-} Consider an example of Fraud Detection and the Loan Issuance process. The business
scenario is such that we want to issue loans to people but do not want them to steal from
us. The current implementation of our system grants loans to everybody. Assume that The server
side code is available here and the
client code here. In this case, the producer owns the contracts. Physically, all the contract are
-in the producer’s repository. If using the SNAPSHOT / Milestone / Release Candidate versions please add the
+in the producer’s repository. If using the SNAPSHOT / Milestone / Release Candidate versions please add the
following section to your build: Maven.
Maven.
maven { url "http://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/release" }
}
- As a developer of the Loan Issuance service (a consumer of the Fraud Detection server), you might do the following steps: Start doing TDD by writing a test for your feature. As a developer of the Loan Issuance service (a consumer of the Fraud Detection server), you might do the following steps: Start doing TDD by writing a test for your feature. Add the File a pull request. What you have done until now is an iterative process. You can play around with the
contract, install it locally, and work on the consumer side until the contract works as
you wish. Once you are satisfied with the results and the test passes, publish a pull request to
-the server side. Currently, the consumer side work is done. As a developer of the Fraud Detection server (a server to the Loan Issuance service): Create an initial implementation. As a reminder, you can see the initial implementation here: As a developer of the Fraud Detection server (a server to the Loan Issuance service): Create an initial implementation. As a reminder, you can see the initial implementation here: Take over the pull request. Deploy your app. Once you finish your work, you can deploy your change. First, merge the branch: Your CI might run something like As a developer of the Loan Issuance service (a consumer of the Fraud Detection server): Merge branch to master. As a developer of the Loan Issuance service (a consumer of the Fraud Detection server): Merge branch to master. Work online. Now you can disable the offline work for Spring Cloud Contract Stub Runner and indicate
where the repository with your stubs is located. At this moment the stubs of the server
side are automatically downloaded from Nexus/Artifactory. You can set the value of
That’s it! The best way to add dependencies is to use the proper For The best way to add dependencies is to use the proper For Here are some resources related to Spring Cloud Contract Verifier and Stub Runner. Note
that some may be outdated, because the Spring Cloud Contract Verifier project is under
-constant development. You can check out the video from the Warsaw JUG about Spring Cloud Contract: You can find some samples at
+constant development. You can check out the video from the Warsaw JUG about Spring Cloud Contract: You can find some samples at
samples. Either via environment variables, system properties, properties set
inside the plugin or contracts repository configuration you can
tweak the downloader’s behaviour. Below you can find the list of
-properties Table 10.1. SCM Stub Downloader properties<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
- <version>${spring-cloud-dependencies.version}</version>
+ <version>${spring-cloud-release.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
diff --git a/multi/multi__spring_cloud_contract_verifier_introduction.html b/multi/multi__spring_cloud_contract_verifier_introduction.html
index b65c5fea4f..8ea3b9169c 100644
--- a/multi/multi__spring_cloud_contract_verifier_introduction.html
+++ b/multi/multi__spring_cloud_contract_verifier_introduction.html
@@ -1,7 +1,6 @@
- ![[Tip]](images/tip.png)
Tip 
0.1.0 release took place on 26 Jan 2015 and it became stable with 1.0.0 release on 29 Feb 2016.

![[Important]](images/important.png)
Important REST/ messaging contracts
expressed in either Groovy DSL or YAML to the contracts directory, which is set by the
contractsDslDir property. By default, it is $rootDir/src/test/resources/contracts.<dependency>
@@ -71,8 +72,8 @@ run the collaborators' stubs for you, as shown in the following example:
@DirtiesContext
public class LoanApplicationServiceTests {
![[Tip]](images/tip.png)
Tip REMOTE stubsMode when downloading stubs from an online repository and
LOCAL for offline work.Spring Cloud Contract, add files with REST/ messaging contracts
expressed in either Groovy DSL or YAML to the contracts directory, which is set by the
contractsDslDir property. By default, it is $rootDir/src/test/resources/contracts.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}]
ResponseEntity<FraudServiceResponse> response =
restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT,
@@ -366,7 +367,7 @@ You would like to feed that instance with a proper stub definition.
@Test
@@ -387,7 +388,7 @@ generated from the stub you provide.
Loan Issuance is a client to the Fraud Detection server. In the current
sprint, we must develop a new feature: if a client wants to borrow too much money, then
@@ -396,7 +397,7 @@ Issuance has an artifact-id of http-client, and bot
discuss changes while going through the process. CDC is all about communication.![[Tip]](images/tip.png)
Tip <repositories>
<repository>
@@ -458,7 +459,7 @@ following section to your build:
@Test
+@Test
public void shouldBeRejectedDueToAbnormalLoanAmount() {
// given:
LoanApplication application = new LoanApplication(new Client("1234567890"),
@@ -644,7 +645,7 @@ Application service):
Spring Cloud Co
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
- <version>${spring-cloud-dependencies.version}</version>
+ <version>${spring-cloud-release-train.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -672,7 +673,7 @@ with group id com.example, artifact id stubs classifier on port 8080.@RequestMapping(value = "/fraudcheck", method = PUT)
+the server side. Currently, the consumer side work is done.@RequestMapping(value = "/fraudcheck", method = PUT)
public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) {
return new FraudCheckResult(FraudCheckStatus.OK, NO_REASON);
}
$ git checkout -b contract-change-pr master
@@ -764,15 +765,15 @@ Contract Verifier plugin adds the tests to the
gene
actually run those tests from your IDE.$ git checkout master
$ git merge --no-ff contract-change-pr
$ git push origin master
./mvnw clean deploy, which would publish both the
-application and the stub artifacts.$ git checkout master
+application and the stub artifacts.
$ git checkout master
$ git merge --no-ff contract-change-pr
stubsMode to REMOTE. The following code shows an example of
achieving the same thing by changing the properties.stubrunner:
ids: 'com.example:http-server-dsl:+:stubs:8080'
- repositoryRoot: http://repo.spring.io/libs-snapshot
starter dependency.stub-runner, use spring-cloud-starter-stub-runner. When you use a plugin, add
-spring-cloud-starter-contract-verifier.starter dependency.stub-runner, use spring-cloud-starter-stub-runner. When you use a plugin, add
+spring-cloud-starter-contract-verifier.