Updated docs

This commit is contained in:
Marcin Grzejszczak
2016-09-02 12:02:35 +02:00
parent 70013138e1
commit 4d401df5c3
5 changed files with 113 additions and 67 deletions

26
_includes/build.gradle Normal file
View File

@@ -0,0 +1,26 @@
buildscript {
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE"
// if using Stub Runner (consumer side) only remove this dependency
classpath "{@= groupId @}:spring-cloud-contract-gradle-plugin:{@= version @}"
}
}
apply plugin: "io.spring.dependency-management"
apply plugin: 'contract-verifier'
dependencyManagement {
imports {
mavenBom '{@= groupId @}:spring-cloud-contract-dependencies:{@= version @}'
}
}
dependencies {
testCompile '{@= groupId @}:spring-cloud-starter-contract-verifier'
}
// In this section you define all Spring Cloud Contract Verifier Gradle Plugin properties
contractVerifier {
baseClassForTests = 'com.example.MvcTest'
// fully qualified name to a class that will be the base class for your generated test classes
}

View File

@@ -11,7 +11,12 @@ Download
your project is with a dependency management system – the snippet below can
be copied and pasted into your build. Need help? See our getting started guides
on building with <a href="http://spring.io/guides/gs/maven/">Maven</a> and
<a href="http://spring.io/guides/gs/gradle/">Gradle</a>.
<a href="http://spring.io/guides/gs/gradle/">Gradle</a>. The example below is
showing how to use the Spring Cloud Contract plugin. In order to use
Spring Cloud Contract Stub Runner you just have to use different libraries
as presented in the later part of this guide. Of course instead of adding the
BOM of the concrete dependency you can add the release train BOM and you won't
have to take care of versioning manually.
</p>
<div class="js-download-maven-widget"></div>
</div>

32
_includes/pom.xml Normal file
View File

@@ -0,0 +1,32 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>{@= groupId @}</groupId>
<artifactId>spring-cloud-contract-dependencies</artifactId>
<version>{@= version @}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>{@= groupId @}</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugin>
<groupId>{@= groupId @}</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>{@= version @}</version>
<!-- Don't forget about this value !! -->
<extensions>true</extensions>
<configuration>
<!-- Provide the base class for your auto-generated tests -->
<baseClassForTests>com.example.MvcTest</baseClassForTests>
</configuration>
</plugin>
</build>

View File

@@ -100,6 +100,17 @@
</snapshots>
</repository>
</repositories>
<!-- Unnecessary if you're using Spring Cloud Stub Runner only -->
<pluginRepositories>
<repository>
<id>{@= repository.id @}</id>
<name>{@= repository.name @}</name>
<url>{@= repository.url @}</url>
<snapshots>
<enabled>{@= repository.snapshotsEnabled @}</enabled>
</snapshots>
</repository>
</pluginRepositories>
{% endhighlight %}
</script>
@@ -123,6 +134,16 @@ dependencies {
<script type="text/html" id="project-repository-gradle-widget-template">
{% highlight groovy %}
// Unnecessary if you're using Spring Cloud Stub Runner only
buildscript {
repositories {
maven {
url '{@= repository.url @}'
}
}
}
repositories {
maven {
url '{@= repository.url @}'

View File

@@ -106,78 +106,36 @@ Spring Cloud Contract Verifier features:
## Quick Start
<script type="text/javascript">{% include custom.js %}</script>
{% include download_widget.md %}
[For a very detailed step by step guide check out the docs](https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_step_by_step_guide_to_cdc). Below you can find a simplified verstion.
### Server / Producer side
On the server (HTTP) / producer (Messaging) side add the Spring Cloud Contract Verifier Maven / Gradle plugin. Let us assume that our project's group id is `com.example` and artifact id is `http-server`.
Gradle Setup
Gradle Setup of the Plugin
```groovy
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.cloud:spring-cloud-contract-verifier-gradle-plugin:${verifier_version}'
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootPlugin}
}
}
apply plugin: 'spring-boot'
apply plugin: 'contract-verifier'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${verifierVersion}"
}
}
contractVerifier {
baseClassForTests = 'com.example.MvcTest'
// fully qualified name to a class that will be the base class for your generated test classes
}
dependencies {
testCompile 'org.springframework.cloud:spring-cloud-starter-contract-verifier'
}
```
Maven Setup
Maven Setup of the Plugin
```xml
<plugin>
<groupId>org.springframework.cloud.contract.verifier</groupId>
<artifactId>spring-cloud-contract-verifier-maven-plugin</artifactId>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<configuration>
<baseClassForTests>com.example.MvcTest</baseClassForTests> <!-- fully qualified name to a class that will be the base class for your generated test classes -->
</configuration>
</plugin>
```
and the required test dependencies
```xml
<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>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<scope>test</scope>
</dependency>
```
where the `com.example.MvcTest` could look like this (we're assuming that we're using [Rest Assured](http://rest-assured.io/) and we want to do CDC for
a `FraudDetectionController` that you're writing)
@@ -311,8 +269,8 @@ Maven
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-dependencies</artifactId>
<version>${spring-cloud-contract.version}</version>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -337,33 +295,37 @@ Gradle
```groovy
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootPluginVersion}"
}
repositories {
mavenCentral()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootPluginVersion}"
}
}
apply plugin: 'spring-boot'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${verifierVersion}"
}
imports {
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${springCloudDependencies}"
}
}
dependencies {
testCompile "org.springframework.cloud:spring-cloud-contract-wiremock"
testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"
testCompile "org.springframework.cloud:spring-cloud-contract-wiremock"
testCompile "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"
}
```
The last step is to provide the property for the Stub Runner to automatically download the required stubs. If you're using Spring Boot it's enough to add the following section to your project test properties:
The last step is to setup Stub Runner in your tests to automatically download the required stubs. To achieve that
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.
```yaml
stubrunner:
stubs.ids: 'com.example:http-server:+:stubs:8080'
```java
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureStubRunner(ids = {"com.example:http-server:+:stubs:8080"}, workOffline = true)
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`. 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.