diff --git a/multi/multi__spring_cloud_contract_faq.html b/multi/multi__spring_cloud_contract_faq.html index 1056df527e..8f4463c629 100644 --- a/multi/multi__spring_cloud_contract_faq.html +++ b/multi/multi__spring_cloud_contract_faq.html @@ -291,7 +291,112 @@ of the JAR containing the contracts:
http://link/to/your/nexus/or/artifactory/or/sth. It will be then unpacked in a local temporary folder
and contracts present under the com/example/server will be picked as the ones used to generate the
tests and the stubs. Due to this convention the producer team will know which consumer teams will be broken
-when some incompatible changes are done.The rest of the flow looks the same.
Yes! Check out the Different base classes for contracts sections
+when some incompatible changes are done.
The rest of the flow looks the same.
To avoid messaging contracts duplication in the common repo, when few producers writing messages to one topic,
+we could create the structure when the rest contracts would be placed in a folder per producer and messaging
+contracts in the folder per topic.
To make it possible to work on the producer side we could do the following things (all via Maven plugins):
- Add common repo dependency to your classpath:
<dependency>
+ <groupId>com.example</groupId>
+ <artifactId>common-repo</artifactId>
+ <version>${common-repo.version}</version>
+</dependency>
- Download the JAR with the contracts and unpack the JAR to target:
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>3.0.0</version>
+ <executions>
+ <execution>
+ <id>unpack-dependencies</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>com.example</groupId>
+ <artifactId>common-repo</artifactId>
+ <type>jar</type>
+ <overWrite>false</overWrite>
+ <outputDirectory>${project.build.directory}/contracts</outputDirectory>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+</plugin>
- Rip out all the folders we’re not interested in:
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.8</version>
+ <executions>
+ <execution>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <delete includeemptydirs="true">
+ <fileset dir="${project.build.directory}/contracts">
+ <include name="**/*" />
+ <!--Producer artifactId-->
+ <exclude name="**/${project.artifactId}/**" />
+ <!--List of the supported topics-->
+ <exclude name="**/${first-topic}/**" />
+ <exclude name="**/${second-topic}/**" />
+ </fileset>
+ </delete>
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+</plugin>
- Run the contract plugin by pointing to the contracts to the folder under target:
<plugin>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-contract-maven-plugin</artifactId>
+ <version>${spring-cloud-contract.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <packageWithBaseClasses>com.example</packageWithBaseClasses>
+ <baseClassMappings>
+ <baseClassMapping>
+ <contractPackageRegex>.*intoxication.*</contractPackageRegex>
+ <baseClassFQN>com.example.intoxication.BeerIntoxicationBase</baseClassFQN>
+ </baseClassMapping>
+ </baseClassMappings>
+ <contractsDirectory>${project.build.directory}/contracts</contractsDirectory>
+ </configuration>
+</plugin>
- Add a custom configuration for the common-repo dependency:
ext {
+ conractsGroupId = "com.example"
+ contractsArtifactId = "common-repo"
+ contractsVersion = "1.2.3"
+}
+
+configurations {
+ contracts {
+ transitive = false
+ }
+}- Add the common-repo dependency to your classpath:
dependencies {
+ contracts "${conractsGroupId}:${contractsArtifactId}:${contractsVersion}"
+ testCompile "${conractsGroupId}:${contractsArtifactId}:${contractsVersion}"
+}- Download the dependency to an appropriate folder:
task getContracts(type: Copy) {
+ from configurations.contracts
+ into new File(project.buildDir, "downloadedContracts")
+}- Unzip JAR:
task unzipContracts(type: Copy) {
+ def zipFile = new File(project.buildDir, "downloadedContracts/${contractsArtifactId}-${contractsVersion}.jar")
+ def outputDir = file("${buildDir}/unpackedContracts")
+
+ from zipTree(zipFile)
+ into outputDir
+}- Cleanup unused contracts:
task deleteUnwantedContracts(type: Delete) {
+ delete fileTree(dir: "${buildDir}/unpackedContracts",
+ include: "**/*",
+ excludes: [
+ "**/${project.name}/**"",
+ **/${first-topic}/**",
+ **/${second-topic}/**])
+}- Create task dependencies:
unzipContracts.dependsOn("getContracts")
+deleteUnwantedContracts.dependsOn("unzipContracts")
+build.dependsOn("deleteUnwantedContracts")
- Configure plugin by specifying the directory containing contracts using
contractsDslDir property
contracts {
+
+ contractsDslDir = new File("${buildDir}/unpackedContracts")
+}Yes! Check out the Different base classes for contracts sections
of either Gradle or Maven plugins.
The generated tests all boil down to RestAssured in some form or fashion which relies on Apache HttpClient. HttpClient has a facility called wire logging which logs the entire request and response to HttpClient. Spring Boot has a logging common application property for doing this sort of thing, just add this to your application properties
logging.level.org.apache.http.wire=DEBUGStarting from version 1.2.0 we turn on WireMock logging to
info and the WireMock notifier to being verbose. Now you will
exactly know what request was received by WireMock server and which
diff --git a/multi/multi_spring-cloud-contract.html b/multi/multi_spring-cloud-contract.html
index ab857d4848..78cf04e0a8 100644
--- a/multi/multi_spring-cloud-contract.html
+++ b/multi/multi_spring-cloud-contract.html
@@ -1,3 +1,3 @@
- Spring Cloud Contract Table of Contents
- 1. Spring Cloud Contract
- 2. Spring Cloud Contract Verifier Introduction
- 3. Spring Cloud Contract FAQ
- 3.1. Why use Spring Cloud Contract Verifier and not X ?
- 3.2. I don’t want to write a contract in Groovy!
- 3.3. What is this value(consumer(), producer()) ?
- 3.4. How to do Stubs versioning?
- 3.5. Common repo with contracts
- 3.6. Can I have multiple base classes for tests?
- 3.7. How can I debug the request/response being sent by the generated tests client?
- 4. Spring Cloud Contract Verifier Setup
- 4.1. Gradle Project
- 4.1.1. Prerequisites
- 4.1.2. Add Gradle Plugin with Dependencies
- 4.1.3. Gradle and Rest Assured 2.0
- 4.1.4. Snapshot Versions for Gradle
- 4.1.5. Add stubs
- 4.1.6. Run the Plugin
- 4.1.7. Default Setup
- 4.1.8. Configure Plugin
- 4.1.9. Configuration Options
- 4.1.10. Single Base Class for All Tests
- 4.1.11. Different Base Classes for Contracts
- 4.1.12. Invoking Generated Tests
- 4.1.13. Spring Cloud Contract Verifier on the Consumer Side
- 4.2. Maven Project
- 4.2.1. Add maven plugin
- 4.2.2. Maven and Rest Assured 2.0
- 4.2.3. Snapshot versions for Maven
- 4.2.4. Add stubs
- 4.2.5. Run plugin
- 4.2.6. Configure plugin
- 4.2.7. Configuration Options
- 4.2.8. Single Base Class for All Tests
- 4.2.9. Different base classes for contracts
- 4.2.10. Invoking generated tests
- 4.2.11. Maven Plugin and STS
- 4.3. Stubs and Transitive Dependencies
- 4.4. CI Server setup
- 4.5. Scenarios
- 4.6. Docker Project
- 5. Spring Cloud Contract Verifier Messaging
- 6. Spring Cloud Contract Stub Runner
- 7. Stub Runner for Messaging
- 8. Contract DSL
- 9. Customization
- 10. Using the Pluggable Architecture
- 11. Spring Cloud Contract WireMock
- 11.1. Registering Stubs Automatically
- 11.2. Using Files to Specify the Stub Bodies
- 11.3. Alternative: Using JUnit Rules
- 11.4. Relaxed SSL Validation for Rest Template
- 11.5. WireMock and Spring MVC Mocks
- 11.6. Customization of WireMock configuration
- 11.7. Generating Stubs using REST Docs
- 11.8. Generating Contracts by Using REST Docs
- 12. Migrations
- 13. Links
\ No newline at end of file
+ Spring Cloud Contract Table of Contents
- 1. Spring Cloud Contract
- 2. Spring Cloud Contract Verifier Introduction
- 3. Spring Cloud Contract FAQ
- 3.1. Why use Spring Cloud Contract Verifier and not X ?
- 3.2. I don’t want to write a contract in Groovy!
- 3.3. What is this value(consumer(), producer()) ?
- 3.4. How to do Stubs versioning?
- 3.5. Common repo with contracts
- 3.6. Can I have multiple base classes for tests?
- 3.7. How can I debug the request/response being sent by the generated tests client?
- 4. Spring Cloud Contract Verifier Setup
- 4.1. Gradle Project
- 4.1.1. Prerequisites
- 4.1.2. Add Gradle Plugin with Dependencies
- 4.1.3. Gradle and Rest Assured 2.0
- 4.1.4. Snapshot Versions for Gradle
- 4.1.5. Add stubs
- 4.1.6. Run the Plugin
- 4.1.7. Default Setup
- 4.1.8. Configure Plugin
- 4.1.9. Configuration Options
- 4.1.10. Single Base Class for All Tests
- 4.1.11. Different Base Classes for Contracts
- 4.1.12. Invoking Generated Tests
- 4.1.13. Spring Cloud Contract Verifier on the Consumer Side
- 4.2. Maven Project
- 4.2.1. Add maven plugin
- 4.2.2. Maven and Rest Assured 2.0
- 4.2.3. Snapshot versions for Maven
- 4.2.4. Add stubs
- 4.2.5. Run plugin
- 4.2.6. Configure plugin
- 4.2.7. Configuration Options
- 4.2.8. Single Base Class for All Tests
- 4.2.9. Different base classes for contracts
- 4.2.10. Invoking generated tests
- 4.2.11. Maven Plugin and STS
- 4.3. Stubs and Transitive Dependencies
- 4.4. CI Server setup
- 4.5. Scenarios
- 4.6. Docker Project
- 5. Spring Cloud Contract Verifier Messaging
- 6. Spring Cloud Contract Stub Runner
- 7. Stub Runner for Messaging
- 8. Contract DSL
- 9. Customization
- 10. Using the Pluggable Architecture
- 11. Spring Cloud Contract WireMock
- 11.1. Registering Stubs Automatically
- 11.2. Using Files to Specify the Stub Bodies
- 11.3. Alternative: Using JUnit Rules
- 11.4. Relaxed SSL Validation for Rest Template
- 11.5. WireMock and Spring MVC Mocks
- 11.6. Customization of WireMock configuration
- 11.7. Generating Stubs using REST Docs
- 11.8. Generating Contracts by Using REST Docs
- 12. Migrations
- 13. Links