Polished index.html

- updated content with 2.0.0 change (for stub runner)
- added missing plugin setup for producer part
- removed info about customization (that's completely irrelevant for quick start)
- added info about polyglot

fixes gh-553
This commit is contained in:
Marcin Grzejszczak
2018-03-22 12:21:41 +01:00
parent ccedac27f3
commit fb61c55350

View File

@@ -32,17 +32,18 @@ badges:
Spring Cloud Contract is an umbrella project holding solutions that help users in successfully implementing the [Consumer Driven Contracts](http://martinfowler.com/articles/consumerDrivenContracts.html) approach. Currently
Spring Cloud Contract consists of the Spring Cloud Contract Verifier project.
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) written in Groovy. Stating with version 1.1.0 you can define your own way of defining contracts - the only thing you have to provide is a converter. Contract definitions are used to produce following resources:
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) written in Groovy or YAML. Contract definitions are used to produce following resources:
* by default JSON stub definitions to be used by [WireMock](http://wiremock.org) (HTTP Server Stub) 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. Starting with version 1.1.0 you can
provide your own implementation of the HTTP Server Stub.
* by default JSON stub definitions to be used by [WireMock](http://wiremock.org) (HTTP Server Stub) 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 youre using one. Were integrating with Spring Integration, Spring Cloud Stream and Apache Camel. You can however set your own integrations if you want to.
* Acceptance tests (by default 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. Starting with version 1.1.0 you can provide your own way of generating tests (e.g. in a different language).
* Acceptance tests (by default 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.
To see how Spring Cloud Contract supports other languages just check out this [blog post](https://spring.io/blog/2018/02/13/spring-cloud-contract-in-a-polyglot-world).
{% endcapture %}
{% capture main_content %}
@@ -122,7 +123,7 @@ a `FraudDetectionController` that you're writing)
```java
package com.example;
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc;
// imports
public class MvcTest {
@@ -134,7 +135,7 @@ public class MvcTest {
}
```
In the `src/test/resources/contracts` add a Stub definition. For example named `shouldMarkClientAsFraud.groovy`
In the `src/test/resources/contracts` add a Contract definition. For example named `shouldMarkClientAsFraud.groovy`
```groovy
org.springframework.cloud.contract.spec.Contract.make {
@@ -166,21 +167,63 @@ response {
}
```
If you have to add a plugin that will generate tests and stubs for you.
Maven
```xml
<build>
<plugins>
<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.MvcTest</baseClassForTests>
</configuration>
</plugin>
</plugins>
</build>
```
Gradle
```groovy
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootPluginVersion}"
classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:${springCloudContractVersion}"
}
}
apply plugin: 'spring-boot'
apply plugin: 'spring-cloud-contract'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${springCloudDependencies}"
}
}
dependencies {
testCompile "org.springframework.cloud:spring-cloud-starter-contract-verifier"
}
contracts {
baseClassForTests = 'com.example.MvcTest'
}
```
Once you try to build your application from your contracts tests will be generated in the output folder under `/generated-test-sources/contracts`.
```java
package org.springframework.cloud.contract.verifier.tests;
import com.example.MvcTest;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.restassured.module.mockmvc.specification.MockMvcRequestSpecification;
import com.jayway.restassured.response.ResponseOptions;
import org.junit.Test;
import static com.jayway.restassured.module.mockmvc.RestAssuredMockMvc.*;
import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;
import static org.assertj.core.api.Assertions.assertThat;
// imports
public class ContractVerifierTest extends MvcTest {
@@ -258,11 +301,6 @@ Maven
</dependencyManagement>
<dependencies>
<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>
@@ -292,7 +330,6 @@ dependencyManagement {
}
dependencies {
testCompile "org.springframework.cloud:spring-cloud-contract-wiremock"
testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"
}
```
@@ -301,6 +338,8 @@ The last step is to setup Stub Runner in your tests to automatically download th
you have to pass the `@AutoConfigureStubRunner` annotation. That annotation has a bunch of properties that you can
set. If you don't like such an approach you can set those values in your test properties too.
For Spring Cloud Contract 1.2.x
```java
@RunWith(SpringRunner.class)
@SpringBootTest
@@ -308,6 +347,15 @@ set. If you don't like such an approach you can set those values in your test pr
public class LoanApplicationServiceTests {
```
For Spring Cloud Contract starting from 2.0.x
```java
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureStubRunner(ids = {"com.example:http-server:+:stubs:8080"}, stubsMode = StubRunnerProperties.StubsMode.LOCAL)
public class LoanApplicationServiceTests {
```
That way an artifact with group id `com.example`, artifact id `http-server`, in `latest` version, with `stubs` classifier will be registered at port `8080`. Since the `workOffline` flag was passed then the stubs will not be downloaded from a remote repository - it will be searched for in the local Maven repo. Once your test context got booted up, executing the following code will not lead to a 404 because the Spring Cloud Contract Stub Runner will automatically start a WireMock server inside your test and feed it with the stubs generated from the server side.
```java