diff --git a/README.adoc b/README.adoc
index 74b7d142a0..93969959e0 100644
--- a/README.adoc
+++ b/README.adoc
@@ -535,70 +535,13 @@ If using the *SNAPSHOT* / *Milestone* / *Release Candidate* versions please add
[source,xml,indent=0,subs="verbatim,attributes",role="primary"]
.Maven
----
-
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- true
-
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
- spring-releases
- Spring Releases
- https://repo.spring.io/release
-
- false
-
-
-
-
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- true
-
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
- spring-releases
- Spring Releases
- https://repo.spring.io/release
-
- false
-
-
-
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/pom.xml[tags=repos,indent=0]
----
[source,groovy,indent=0,subs="verbatim,attributes",role="secondary"]
.Gradle
----
-repositories {
- mavenCentral()
- mavenLocal()
- maven { url "http://repo.spring.io/snapshot" }
- maven { url "http://repo.spring.io/milestone" }
- maven { url "http://repo.spring.io/release" }
-}
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/build.gradle[tags=deps_repos,indent=0]
----
===== Consumer side (Loan Issuance)
@@ -609,18 +552,7 @@ As a developer of the Loan Issuance service (a consumer of the Fraud Detection s
[source,groovy,indent=0]
----
-@Test
-public void shouldBeRejectedDueToAbnormalLoanAmount() {
- // given:
- LoanApplication application = new LoanApplication(new Client("1234567890"),
- 99999);
- // when:
- LoanApplicationResult loanApplication = service.loanApplication(application);
- // then:
- assertThat(loanApplication.getLoanApplicationStatus())
- .isEqualTo(LoanApplicationStatus.LOAN_APPLICATION_REJECTED);
- assertThat(loanApplication.getRejectionReason()).isEqualTo("Amount too high");
-}
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java[tags=client_tdd,indent=0]
----
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.
@@ -631,10 +563,7 @@ At some point in time you need to send a request to the Fraud Detection service.
[source,groovy,indent=0]
----
-ResponseEntity response =
- restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT,
- new HttpEntity<>(request, httpHeaders),
- FraudServiceResponse.class);
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-client/src/main/java/com/example/loan/LoanApplicationService.java[tags=client_call_server,indent=0]
----
For simplicity we've hardcoded the port of the Fraud Detection service at `8080` and our application is running on `8090`.
@@ -659,73 +588,7 @@ is important cause we'll reference that folder in the producer's test base class
[source,groovy,indent=0]
----
-package contracts
-
-org.springframework.cloud.contract.spec.Contract.make {
- request { // (1)
- method 'PUT' // (2)
- url '/fraudcheck' // (3)
- body([ // (4)
- clientId: $(regex('[0-9]{10}')),
- loanAmount: 99999
- ])
- headers { // (5)
- contentType('application/vnd.fraud.v1+json')
- }
- }
- response { // (6)
- status 200 // (7)
- body([ // (8)
- fraudCheckStatus: "FRAUD",
- rejectionReason: "Amount too high"
- ])
- headers { // (9)
- contentType('application/vnd.fraud.v1+json')
- }
- }
-}
-
-/*
-Since we don't want to force on the user to hardcode values of fields that are dynamic
-(timestamps, database ids etc.), one can parametrize those entries. If you wrap your field's
- value in a `$(...)` or `value(...)` and provide a dynamic value of a field then
- the concrete value will be generated for you. If you want to be really explicit about
- which side gets which value you can do that by using the `value(consumer(...), producer(...))` notation.
- That way what's present in the `consumer` section will end up in the produced stub. What's
- there in the `producer` will end up in the autogenerated test. If you provide only the
- regular expression side without the concrete value then Spring Cloud Contract will generate one for you.
-
-From the Consumer perspective, when shooting a request in the integration test:
-
-(1) - If the consumer sends a request
-(2) - With the "PUT" method
-(3) - to the URL "/fraudcheck"
-(4) - with the JSON body that
- * has a field `clientId` that matches a regular expression `[0-9]{10}`
- * has a field `loanAmount` that is equal to `99999`
-(5) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
-(6) - then the response will be sent with
-(7) - status equal `200`
-(8) - and JSON body equal to
- { "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" }
-(9) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
-
-From the Producer perspective, in the autogenerated producer-side test:
-
-(1) - A request will be sent to the producer
-(2) - With the "PUT" method
-(3) - to the URL "/fraudcheck"
-(4) - with the JSON body that
- * has a field `clientId` that will have a generated value that matches a regular expression `[0-9]{10}`
- * has a field `loanAmount` that is equal to `99999`
-(5) - with header `Content-Type` equal to `application/vnd.fraud.v1+json`
-(6) - then the test will assert if the response has been sent with
-(7) - status equal `200`
-(8) - and JSON body equal to
- { "fraudCheckStatus": "FRAUD", "rejectionReason": "Amount too high" }
-(9) - with header `Content-Type` matching `application/vnd.fraud.v1+json.*`
- */
-----
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/src/test/resources/contracts/fraud/shouldMarkClientAsFraud.groovy[]
The Contract is written using a statically typed Groovy DSL. You might be wondering what are those
`value(client(...), server(...))` parts. By using this notation Spring Cloud Contract allows you to
@@ -758,32 +621,14 @@ We can add either Maven or Gradle plugin - in this example we'll show how to add
[source,xml,indent=0]
----
-
-
-
- org.springframework.cloud
- spring-cloud-dependencies
- ${spring-cloud-dependencies.version}
- pom
- import
-
-
-
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/pom.xml[tags=contract_bom,indent=0]
----
Next, the `Spring Cloud Contract Verifier` Maven plugin
[source,xml,indent=0]
----
-
- org.springframework.cloud
- spring-cloud-contract-maven-plugin
- ${spring-cloud-contract.version}
- true
-
- com.example.fraud
-
-
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/pom.xml[tags=contract_maven_plugin,indent=0]
----
Since the plugin was added we get the `Spring Cloud Contract Verifier` features which from the provided contracts:
@@ -834,39 +679,21 @@ Add the `Spring Cloud Contract` BOM
[source,xml,indent=0]
----
-
-
-
- org.springframework.cloud
- spring-cloud-dependencies
- ${spring-cloud-dependencies.version}
- pom
- import
-
-
-
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-client/pom.xml[tags=contract_bom,indent=0]
----
Add the dependency to `Spring Cloud Contract Stub Runner`
[source,xml,indent=0]
----
-
- org.springframework.cloud
- spring-cloud-starter-contract-stub-runner
- test
-
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-client/pom.xml[tags=stub_runner,indent=0]
----
Annotate your test class with `@AutoConfigureStubRunner`. In the annotation 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,groovy,indent=0]
----
-@RunWith(SpringRunner.class)
-@SpringBootTest(webEnvironment=WebEnvironment.NONE)
-@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"}, workOffline = true)
-@DirtiesContext
-public class LoanApplicationServiceTests {
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java[tags=autoconfigure_stubrunner,indent=0]
----
Now if you run your tests you'll see sth like this:
@@ -900,13 +727,8 @@ 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);
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=server_api,indent=0]
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=initial_impl,indent=0]
}
----
@@ -922,26 +744,14 @@ You have to add the dependencies needed by the autogenerated tests
[source,xml,indent=0]
----
-
- org.springframework.cloud
- spring-cloud-starter-contract-verifier
- test
-
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/pom.xml[tags=verifier_test_dependencies,indent=0]
----
In the configuration of the Maven plugin we passed the `packageWithBaseClasses` property
[source,xml,indent=0]
----
-
- org.springframework.cloud
- spring-cloud-contract-maven-plugin
- ${spring-cloud-contract.version}
- true
-
- com.example.fraud
-
-
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/pom.xml[tags=contract_maven_plugin,indent=0]
----
IMPORTANT: We've decided to use the "convention based" naming by setting the `packageWithBaseClasses` property.
@@ -955,25 +765,7 @@ whatever is necessary. In our case we're using http://rest-assured.io/[Rest Assu
[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 FraudBase {
-
- @Before
- public void setup() {
- RestAssuredMockMvc.standaloneSetup(new FraudDetectionController());
- }
-
- public void assertThatRejectionReasonIsNull(Object rejectionReason) {
- assert rejectionReason == null;
- }
-}
-----
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudBase.java[]
Now, if you run the `./mvnw clean install` you would get sth like this:
@@ -1020,16 +812,9 @@ Now since we now what is the expected input and expected output let's write the
[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);
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=server_api,indent=0]
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=new_impl,indent=0]
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-server/src/main/java/com/example/fraud/FraudDetectionController.java[tags=initial_impl,indent=0]
}
----
@@ -1068,10 +853,7 @@ example of achieving the same by changing the properties.
[source,yaml,indent=0]
----
-stubrunner:
- ids: 'com.example:http-server-dsl:+:stubs:8080'
- repositoryRoot: http://repo.spring.io/libs-snapshot
-----
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[]
And that's it!
@@ -1374,115 +1156,7 @@ Example of a `pom.xml` inside the `server` folder.
[source,xml,indent=0]
----
-
-
- 4.0.0
-
- com.example
- server
- 0.0.1-SNAPSHOT
-
- Server Stubs
- POM used to install locally stubs for consumer side
-
-
- org.springframework.boot
- spring-boot-starter-parent
- 1.4.2.BUILD-SNAPSHOT
-
-
-
-
- UTF-8
- 1.8
- 1.0.5.BUILD-SNAPSHOT
- Camden.BUILD-SNAPSHOT
- true
-
-
-
-
-
- org.springframework.cloud
- spring-cloud-dependencies
- ${spring-cloud-dependencies.version}
- pom
- import
-
-
-
-
-
-
-
- org.springframework.cloud
- spring-cloud-contract-maven-plugin
- ${spring-cloud-contract.version}
- true
-
-
- ${project.basedir}
-
-
-
-
-
-
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- true
-
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
- spring-releases
- Spring Releases
- https://repo.spring.io/release
-
- false
-
-
-
-
-
- spring-snapshots
- Spring Snapshots
- https://repo.spring.io/snapshot
-
- true
-
-
-
- spring-milestones
- Spring Milestones
- https://repo.spring.io/milestone
-
- false
-
-
-
- spring-releases
- Spring Releases
- https://repo.spring.io/release
-
- false
-
-
-
-
-
-----
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/contracts/com/example/server/pom.xml[indent=0]
As you can see there are no dependencies other than the Spring Cloud Contract Maven Plugin.
Those poms are necessary for the consumer side to run `mvn clean install -DskipTests` to locally install
@@ -1492,77 +1166,13 @@ The `pom.xml` in the root folder can look like this:
[source,xml,indent=0]
----
-
-
- 4.0.0
-
- com.example.standalone
- contracts
- 0.0.1-SNAPSHOT
-
- Contracts
- Contains all the Spring Cloud Contracts, well, contracts. JAR used by the producers to generate tests and stubs
-
-
- UTF-8
-
-
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
-
-
- contracts
- prepare-package
-
- single
-
-
- true
- ${basedir}/src/assembly/contracts.xml
-
- false
-
-
-
-
-
-
-
-
-----
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/contracts/pom.xml[indent=0]
It's using the assembly plugin in order to build the JAR with all the contracts. Example of such setup is here:
[source,xml,indent=0]
----
-
- project
-
- jar
-
- false
-
-
- ${project.basedir}
- /
- true
-
- **/${project.build.directory}/**
- mvnw
- mvnw.cmd
- .mvn/**
- src/**
-
-
-
-
-----
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/samples/standalone/contracts/src/assembly/contracts.xml[indent=0]
===== Workflow
@@ -1585,17 +1195,7 @@ of the JAR containing the contracts:
[source,xml,indent=0]
----
-
- org.springframework.cloud
- spring-cloud-contract-maven-plugin
-
- http://link/to/your/nexus/or/artifactory/or/sth
-
- com.example.standalone
- contracts
-
-
-
+Unresolved directive in verifier/introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic-remote-contracts/pom-with-repo.xml[tags=remote_config,indent=0]
----
With this setup the JAR with groupid `com.example.standalone` and artifactid `contracts` will be downloaded
@@ -1638,46 +1238,7 @@ You can read more about Spring Cloud Contract Verifier by reading the {documenta
== 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://support.springsource.com/spring_committer_signup[contributor's 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 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://github.com/spring-cloud/build/tree/master/eclipse-coding-conventions.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).
-
+Unresolved directive in README.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/1.0.x/docs/src/main/asciidoc/contributing.adoc[]
== How to build it
IMPORTANT: You need to have all the necessary Groovy plugins
diff --git a/docs/src/main/asciidoc/verifier/rest.adoc b/docs/src/main/asciidoc/verifier/rest.adoc
index 8779c14e84..31052102d0 100644
--- a/docs/src/main/asciidoc/verifier/rest.adoc
+++ b/docs/src/main/asciidoc/verifier/rest.adoc
@@ -41,6 +41,36 @@ dependencies {
}
----
+====== Gradle and Rest Assured 3.0
+
+By default Rest Assured 2.x is added to the classpath. However in order to give the users the
+opportunity to use Rest Assured 3.x it's enough to add it to the plugins classpath.
+
+[source,groovy,indent=0]
+----
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath "org.springframework.boot:spring-boot-gradle-plugin:${springboot_version}"
+ classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:${verifier_version}"
+ classpath "io.rest-assured:rest-assured:3.0.2"
+ classpath "io.rest-assured:spring-mock-mvc:3.0.2"
+ }
+}
+
+depenendencies {
+ // all dependencies
+ // you can exclude rest-assured from spring-cloud-contract-verifier
+ testCompile "io.rest-assured:rest-assured:3.0.2"
+ testCompile "io.rest-assured:spring-mock-mvc:3.0.2"
+}
+----
+
+That way the plugin will automatically see that Rest Assured 3.x is present on the classpath
+and will modify the imports accordingly.
+
====== Snapshot versions for Gradle
Add the additional snapshot repository to your build.gradle to use snapshot versions which are automatically uploaded after every successful build:
@@ -277,6 +307,63 @@ include::{standalone_samples_path}/http-server/pom.xml[tags=contract_maven_plugi
You can read more in the https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract-maven-plugin/[Spring Cloud Contract Maven Plugin Docs]
+====== Maven and Rest Assured 3.0
+
+By default Rest Assured 2.x is added to the classpath. However in order to give the users the
+opportunity to use Rest Assured 3.x it's enough to add it to the plugins classpath.
+
+[source,groovy,indent=0]
+----
+
+ org.springframework.cloud
+ spring-cloud-contract-maven-plugin
+ ${spring-cloud-contract.version}
+ true
+
+ com.example
+
+
+
+ org.springframework.cloud
+ spring-cloud-contract-verifier
+ ${spring-cloud-contract.version}
+
+
+ io.rest-assured
+ rest-assured
+ 3.0.2
+ compile
+
+
+ io.rest-assured
+ spring-mock-mvc
+ 3.0.2
+ compile
+
+
+
+
+
+
+
+
+ io.rest-assured
+ rest-assured
+ 3.0.2
+ test
+
+
+ io.rest-assured
+ spring-mock-mvc
+ 3.0.2
+ test
+
+
+----
+
+That way the plugin will automatically see that Rest Assured 3.x is present on the classpath
+and will modify the imports accordingly.
+
====== Snapshot versions for Maven
For Snapshot / Milestone versions you have to add the following section to your `pom.xml`
diff --git a/samples/standalone/dsl/http-server/pom.xml b/samples/standalone/dsl/http-server/pom.xml
index 0c1a74ab3e..821224b28d 100644
--- a/samples/standalone/dsl/http-server/pom.xml
+++ b/samples/standalone/dsl/http-server/pom.xml
@@ -42,10 +42,10 @@
- org.springframework.cloud
- spring-cloud-starter-contract-verifier
- test
-
+ org.springframework.cloud
+ spring-cloud-starter-contract-verifier
+ test
+
diff --git a/samples/standalone/messaging/stream-source/build.gradle b/samples/standalone/messaging/stream-source/build.gradle
index 7c9856f0de..d3bed2569a 100644
--- a/samples/standalone/messaging/stream-source/build.gradle
+++ b/samples/standalone/messaging/stream-source/build.gradle
@@ -9,6 +9,8 @@ buildscript {
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.0.BUILD-SNAPSHOT"
classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:${findProperty('verifierVersion') ?: verifierVersion}"
+ classpath "io.rest-assured:rest-assured:3.0.2"
+ classpath "io.rest-assured:spring-mock-mvc:3.0.2"
}
}
@@ -51,7 +53,9 @@ dependencies {
compile("org.springframework.cloud:spring-cloud-starter-stream-rabbit")
testCompile 'org.springframework.cloud:spring-cloud-starter-contract-verifier'
- testCompile("org.springframework.cloud:spring-cloud-stream-test-support")
+ testCompile "org.springframework.cloud:spring-cloud-stream-test-support"
+ testCompile "io.rest-assured:rest-assured:3.0.2"
+ testCompile "io.rest-assured:spring-mock-mvc:3.0.2"
}
task stubsJar(type: Jar, dependsOn: "generateWireMockClientStubs") {
diff --git a/samples/standalone/messaging/stream-source/pom.xml b/samples/standalone/messaging/stream-source/pom.xml
index d91b46e6ea..b54a8a0828 100644
--- a/samples/standalone/messaging/stream-source/pom.xml
+++ b/samples/standalone/messaging/stream-source/pom.xml
@@ -43,6 +43,30 @@
org.springframework.cloud
spring-cloud-contract-verifier
test
+
+
+ com.jayway.restassured
+ rest-assured
+
+
+ com.jayway.restassured
+ spring-mock-mvc
+
+
+
+
+
+
+ io.rest-assured
+ rest-assured
+ 3.0.2
+ test
+
+
+ io.rest-assured
+ spring-mock-mvc
+ 3.0.2
+ test
@@ -77,6 +101,22 @@
+
+
+
+
+ io.rest-assured
+ rest-assured
+ 3.0.2
+ compile
+
+
+ io.rest-assured
+ spring-mock-mvc
+ 3.0.2
+ compile
+
+
diff --git a/samples/standalone/messaging/stream-source/src/test/java/com/example/source/SensorSourceTestBase.java b/samples/standalone/messaging/stream-source/src/test/java/com/example/source/SensorSourceTestBase.java
index fb775bbf83..63d504e5f8 100644
--- a/samples/standalone/messaging/stream-source/src/test/java/com/example/source/SensorSourceTestBase.java
+++ b/samples/standalone/messaging/stream-source/src/test/java/com/example/source/SensorSourceTestBase.java
@@ -16,11 +16,14 @@
package com.example.source;
+import io.restassured.module.mockmvc.RestAssuredMockMvc;
+import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.context.WebApplicationContext;
/**
* Base class for sensor autogenerated tests (used by Spring Cloud Contract).
@@ -37,6 +40,14 @@ public abstract class SensorSourceTestBase {
@Autowired
ContractVerifierSampleStreamSourceApplication application;
+ @Autowired
+ WebApplicationContext context;
+
+ @Before
+ public void setup() {
+ RestAssuredMockMvc.webAppContextSetup(this.context);
+ }
+
public void createSensorData() {
application.poll();
}
diff --git a/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldReturnOkWhenServiceIsHealthy.groovy b/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldReturnOkWhenServiceIsHealthy.groovy
new file mode 100644
index 0000000000..781257e6c2
--- /dev/null
+++ b/samples/standalone/messaging/stream-source/src/test/resources/contracts/shouldReturnOkWhenServiceIsHealthy.groovy
@@ -0,0 +1,11 @@
+package contracts
+
+org.springframework.cloud.contract.spec.Contract.make {
+ request {
+ method(GET())
+ url("/health")
+ }
+ response {
+ status(200)
+ }
+}
diff --git a/spring-cloud-contract-dependencies/pom.xml b/spring-cloud-contract-dependencies/pom.xml
index 0e0a1aa179..0759f3c197 100644
--- a/spring-cloud-contract-dependencies/pom.xml
+++ b/spring-cloud-contract-dependencies/pom.xml
@@ -114,6 +114,7 @@
jsonassert
${jsonassert.version}
+
com.jayway.restassured
spring-mock-mvc
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/TestGenerator.groovy b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/TestGenerator.groovy
index f72ae700d4..dce56be93a 100755
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/TestGenerator.groovy
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/TestGenerator.groovy
@@ -63,6 +63,9 @@ class TestGenerator {
}
int generate() {
+ if (!configProperties.basePackageForTests) {
+
+ }
generateTestClasses(configProperties.basePackageForTests)
return counter.get()
}
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGenerator.groovy b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGenerator.groovy
index 1092d5b8e0..08e3024809 100644
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGenerator.groovy
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGenerator.groovy
@@ -20,6 +20,8 @@ import groovy.transform.Canonical
import groovy.transform.EqualsAndHashCode
import groovy.transform.PackageScope
import groovy.util.logging.Slf4j
+import org.apache.commons.logging.Log
+import org.apache.commons.logging.LogFactory
import org.springframework.cloud.contract.spec.Contract
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
import org.springframework.cloud.contract.verifier.config.TestFramework
@@ -27,6 +29,8 @@ import org.springframework.cloud.contract.verifier.config.TestMode
import org.springframework.cloud.contract.verifier.file.ContractMetadata
import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter
+import java.lang.invoke.MethodHandles
+
import static org.springframework.cloud.contract.verifier.util.NamesUtil.capitalize
/**
* Builds a single test for the given {@link ContractVerifierConfigProperties properties}
@@ -38,11 +42,19 @@ class SingleTestGenerator {
private static final String JSON_ASSERT_STATIC_IMPORT = 'com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson'
private static final String JSON_ASSERT_CLASS = 'com.toomuchcoding.jsonassert.JsonAssertion'
+ private static final String REST_ASSURED_3_0_CLASS = 'io.restassured.RestAssured'
private final ContractVerifierConfigProperties configProperties
+ private final ClassPresenceChecker checker
SingleTestGenerator(ContractVerifierConfigProperties configProperties) {
this.configProperties = configProperties
+ this.checker = new ClassPresenceChecker()
+ }
+
+ protected SingleTestGenerator(ContractVerifierConfigProperties configProperties, ClassPresenceChecker checker) {
+ this.configProperties = configProperties
+ this.checker = checker
}
/**
@@ -73,7 +85,8 @@ class SingleTestGenerator {
addJsonPathRelatedImports(clazz)
Map contracts = mapContractsToTheirTestTypes(listOfFiles)
-
+ boolean restAssured3Present = this.checker.isClassPresent(REST_ASSURED_3_0_CLASS)
+ String restAssuredPackage = restAssured3Present ? 'io.restassured' : 'com.jayway.restassured'
boolean conditionalImportsAdded = false
boolean toIgnore = listOfFiles.ignored.find { it }
contracts.each { ParsedDsl key, TestType value ->
@@ -85,18 +98,18 @@ class SingleTestGenerator {
clazz.addImport('javax.ws.rs.core.Response')
}
} else if (configProperties.testMode == TestMode.MOCKMVC) {
- clazz.addStaticImport('com.jayway.restassured.module.mockmvc.RestAssuredMockMvc.*')
+ clazz.addStaticImport("${restAssuredPackage}.module.mockmvc.RestAssuredMockMvc.*")
} else {
- clazz.addStaticImport('com.jayway.restassured.RestAssured.*')
+ clazz.addStaticImport("${restAssuredPackage}.RestAssured.*")
}
}
if (configProperties.targetFramework == TestFramework.JUNIT) {
if (contracts.values().contains(TestType.HTTP) && configProperties.testMode == TestMode.MOCKMVC) {
- clazz.addImport('com.jayway.restassured.module.mockmvc.specification.MockMvcRequestSpecification')
- clazz.addImport('com.jayway.restassured.response.ResponseOptions')
+ clazz.addImport("${restAssuredPackage}.module.mockmvc.specification.MockMvcRequestSpecification")
+ clazz.addImport("${restAssuredPackage}.response.ResponseOptions")
} else if (contracts.values().contains(TestType.HTTP) && configProperties.testMode == TestMode.EXPLICIT) {
- clazz.addImport('com.jayway.restassured.specification.RequestSpecification')
- clazz.addImport('com.jayway.restassured.response.Response')
+ clazz.addImport("${restAssuredPackage}.specification.RequestSpecification")
+ clazz.addImport("${restAssuredPackage}.response.Response")
}
clazz.addImport('org.junit.Test')
clazz.addStaticImport('org.assertj.core.api.Assertions.assertThat')
@@ -152,7 +165,7 @@ class SingleTestGenerator {
clazz.addImport(['com.jayway.jsonpath.DocumentContext',
'com.jayway.jsonpath.JsonPath',
])
- if (jsonAssertPresent()) {
+ if (this.checker.isClassPresent(JSON_ASSERT_CLASS)) {
clazz.addStaticImport(JSON_ASSERT_STATIC_IMPORT)
}
}
@@ -169,16 +182,21 @@ class SingleTestGenerator {
clazz.addStaticImport('org.springframework.cloud.contract.verifier.messaging.util.ContractVerifierMessagingUtil.headers')
}
- private static boolean jsonAssertPresent() {
+}
+
+class ClassPresenceChecker {
+
+ private static final Log log = LogFactory.getLog(MethodHandles.lookup().lookupClass())
+
+ boolean isClassPresent(String className) {
try {
- Class.forName(JSON_ASSERT_CLASS)
+ Class.forName(className)
return true
} catch (ClassNotFoundException e) {
if (log.isDebugEnabled()) {
- log.debug("JsonAssert is not present on classpath. Will not add a static import.")
+ log.debug("[${className}] is not present on classpath. Will not add a static import.")
}
return false
}
}
-
-}
+}
\ No newline at end of file
diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestMode.groovy b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestMode.groovy
index c23da52ae1..ab303b95f4 100644
--- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestMode.groovy
+++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/TestMode.groovy
@@ -25,12 +25,12 @@ package org.springframework.cloud.contract.verifier.config
*/
enum TestMode {
/**
- * Uses Spring's MockMvc
+ * Uses Spring's MockMvc with Rest Assured 2.x
*/
MOCKMVC,
/**
- * Uses direct HTTP invocations
+ * Uses direct HTTP invocations with Rest Assured 2.x
*/
EXPLICIT,
diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy
index aadd7d7ece..2b7e79364b 100644
--- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy
+++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/SingleTestGeneratorSpec.groovy
@@ -35,29 +35,51 @@ class SingleTestGeneratorSpec extends Specification {
TemporaryFolder tmpFolder = new TemporaryFolder()
File file
- private static final List mockMvcJUnitClassStrings = ['package test; ', 'import com.jayway.jsonpath.DocumentContext; ', 'import com.jayway.jsonpath.JsonPath; ',
- 'import org.junit.FixMethodOrder; ', 'import org.junit.Ignore; ', 'import org.junit.Test; ', 'import org.junit.runners.MethodSorters; ',
- 'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson; ', 'import static com.jayway.restassured.module.mockmvc.RestAssuredMockMvc.*; ',
- '@FixMethodOrder(MethodSorters.NAME_ASCENDING); ', '@Test; ', '@Ignore; ', 'import com.jayway.restassured.module.mockmvc.specification.MockMvcRequestSpecification; ',
- 'import com.jayway.restassured.response.ResponseOptions; ', 'import static org.assertj.core.api.Assertions.assertThat']
+ private static final List mockMvcJUnitClassStrings = ['import com.jayway.jsonpath.DocumentContext;', 'import com.jayway.jsonpath.JsonPath;',
+ 'import org.junit.FixMethodOrder;', 'import org.junit.Ignore;', 'import org.junit.Test;', 'import org.junit.runners.MethodSorters;',
+ 'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static com.jayway.restassured.module.mockmvc.RestAssuredMockMvc.*;',
+ '@FixMethodOrder(MethodSorters.NAME_ASCENDING)', '@Test', '@Ignore', 'import com.jayway.restassured.module.mockmvc.specification.MockMvcRequestSpecification;',
+ 'import com.jayway.restassured.response.ResponseOptions;', 'import static org.assertj.core.api.Assertions.assertThat']
+
+ private static final List mockMvcJUnitRestAssured3ClassStrings = ['import com.jayway.jsonpath.DocumentContext;', 'import com.jayway.jsonpath.JsonPath;',
+ 'import org.junit.FixMethodOrder;', 'import org.junit.Ignore;', 'import org.junit.Test;', 'import org.junit.runners.MethodSorters;',
+ 'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static io.restassured.module.mockmvc.RestAssuredMockMvc.*;',
+ '@FixMethodOrder(MethodSorters.NAME_ASCENDING)', '@Test', '@Ignore', 'import io.restassured.module.mockmvc.specification.MockMvcRequestSpecification;',
+ 'import io.restassured.response.ResponseOptions;', 'import static org.assertj.core.api.Assertions.assertThat']
- private static final List explicitJUnitClassStrings = ['package test; ', 'import com.jayway.jsonpath.DocumentContext; ', 'import com.jayway.jsonpath.JsonPath; ',
- 'import org.junit.FixMethodOrder; ', 'import org.junit.Ignore; ', 'import org.junit.Test; ', 'import org.junit.runners.MethodSorters; ',
- 'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson; ', 'import static com.jayway.restassured.RestAssured.*; ',
- '@FixMethodOrder(MethodSorters.NAME_ASCENDING); ', '@Test; ', '@Ignore; ', 'import com.jayway.restassured.specification.RequestSpecification; ',
- 'import com.jayway.restassured.response.Response; ', 'import static org.assertj.core.api.Assertions.assertThat']
+ private static final List explicitJUnitClassStrings = ['import com.jayway.jsonpath.DocumentContext;', 'import com.jayway.jsonpath.JsonPath;',
+ 'import org.junit.FixMethodOrder;', 'import org.junit.Ignore;', 'import org.junit.Test;', 'import org.junit.runners.MethodSorters;',
+ 'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static com.jayway.restassured.RestAssured.*;',
+ '@FixMethodOrder(MethodSorters.NAME_ASCENDING)', '@Test', '@Ignore', 'import com.jayway.restassured.specification.RequestSpecification;',
+ 'import com.jayway.restassured.response.Response;', 'import static org.assertj.core.api.Assertions.assertThat']
- private static final List spockClassStrings = ['package test', 'import com.jayway.jsonpath.DocumentContext', 'import com.jayway.jsonpath.JsonPath',
+ private static final List explicitJUnitRestAssured3ClassStrings = ['import com.jayway.jsonpath.DocumentContext;', 'import com.jayway.jsonpath.JsonPath;',
+ 'import org.junit.FixMethodOrder;', 'import org.junit.Ignore;', 'import org.junit.Test;', 'import org.junit.runners.MethodSorters;',
+ 'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson;', 'import static io.restassured.RestAssured.*;',
+ '@FixMethodOrder(MethodSorters.NAME_ASCENDING)', '@Test', '@Ignore', 'import io.restassured.specification.RequestSpecification;',
+ 'import io.restassured.response.Response;', 'import static org.assertj.core.api.Assertions.assertThat']
+
+ private static final List spockClassStrings = ['import com.jayway.jsonpath.DocumentContext', 'import com.jayway.jsonpath.JsonPath',
'import spock.lang.Ignore', 'import spock.lang.Specification', 'import spock.lang.Stepwise',
'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson', 'import static com.jayway.restassured.module.mockmvc.RestAssuredMockMvc.*',
'@Stepwise', '@Ignore']
- private static final List explicitSpockClassStrings = ['package test', 'import com.jayway.jsonpath.DocumentContext', 'import com.jayway.jsonpath.JsonPath',
+ private static final List spockClassRestAssured3Strings = ['import com.jayway.jsonpath.DocumentContext', 'import com.jayway.jsonpath.JsonPath',
+ 'import spock.lang.Ignore', 'import spock.lang.Specification', 'import spock.lang.Stepwise',
+ 'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson', 'import static io.restassured.module.mockmvc.RestAssuredMockMvc.*',
+ '@Stepwise', '@Ignore']
+
+ private static final List explicitSpockClassStrings = ['import com.jayway.jsonpath.DocumentContext', 'import com.jayway.jsonpath.JsonPath',
'import spock.lang.Ignore', 'import spock.lang.Specification', 'import spock.lang.Stepwise',
'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson', 'import static com.jayway.restassured.RestAssured.*',
'@Stepwise', '@Ignore']
+ private static final List explicitSpockRestAssured3ClassStrings = ['import com.jayway.jsonpath.DocumentContext', 'import com.jayway.jsonpath.JsonPath',
+ 'import spock.lang.Ignore', 'import spock.lang.Specification', 'import spock.lang.Stepwise',
+ 'import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson', 'import static io.restassured.RestAssured.*',
+ '@Stepwise', '@Ignore']
+
public static final Closure JAVA_ASSERTER = { String classToTest ->
String name = Math.abs(new Random().nextInt())
String changedTest = classToTest.replace("public class Test", "public class Test${name}")
@@ -93,6 +115,7 @@ class SingleTestGeneratorSpec extends Specification {
given:
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
properties.targetFramework = testFramework
+ properties.testMode = mode
ContractMetadata contract = new ContractMetadata(file.toPath(), true, 1, 2)
contract.ignored >> true
contract.order >> 2
@@ -102,7 +125,7 @@ class SingleTestGeneratorSpec extends Specification {
String clazz = testGenerator.buildClass([contract], "test", "test", 'com/foo')
then:
- classStrings.each { clazz.contains(it) }
+ classStrings.each { assert clazz.contains(it) }
and:
asserter(clazz)
where:
@@ -113,6 +136,36 @@ class SingleTestGeneratorSpec extends Specification {
SPOCK | TestMode.EXPLICIT | explicitSpockClassStrings | GROOVY_ASSERTER
}
+ def "should build test class for #testFramework with Rest Assured 3.0"() {
+ given:
+ ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
+ properties.targetFramework = testFramework
+ properties.testMode = mode
+ ContractMetadata contract = new ContractMetadata(file.toPath(), true, 1, 2)
+ contract.ignored >> true
+ contract.order >> 2
+ SingleTestGenerator testGenerator = new SingleTestGenerator(properties, new ClassPresenceChecker() {
+ @Override
+ boolean isClassPresent(String className) {
+ return true
+ }
+ })
+
+ when:
+ String clazz = testGenerator.buildClass([contract], "test", "test", 'com/foo')
+
+ then:
+ classStrings.each { assert clazz.contains(it) }
+ !clazz.contains("com.jayway.restassured")
+
+ where:
+ testFramework | mode | classStrings
+ JUNIT | TestMode.MOCKMVC | mockMvcJUnitRestAssured3ClassStrings
+ JUNIT | TestMode.EXPLICIT | explicitJUnitRestAssured3ClassStrings
+ SPOCK | TestMode.MOCKMVC | spockClassRestAssured3Strings
+ SPOCK | TestMode.EXPLICIT | explicitSpockRestAssured3ClassStrings
+ }
+
def "should build test class for #testFramework and mode #mode with two files"() {
given:
File file = tmpFolder.newFile()