458 lines
73 KiB
HTML
458 lines
73 KiB
HTML
<html><head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>80. Spring Cloud Contract Verifier Setup</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud.html" title="Spring Cloud"><link rel="up" href="multi__spring_cloud_contract.html" title="Part XII. Spring Cloud Contract"><link rel="prev" href="multi__spring_cloud_contract_verifier_introduction.html" title="79. Spring Cloud Contract Verifier Introduction"><link rel="next" href="multi__spring_cloud_contract_verifier_messaging.html" title="81. Spring Cloud Contract Verifier Messaging"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">80. Spring Cloud Contract Verifier Setup</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__spring_cloud_contract_verifier_introduction.html">Prev</a> </td><th width="60%" align="center">Part XII. Spring Cloud Contract</th><td width="20%" align="right"> <a accesskey="n" href="multi__spring_cloud_contract_verifier_messaging.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a name="_spring_cloud_contract_verifier_setup" href="#_spring_cloud_contract_verifier_setup"></a>80. Spring Cloud Contract Verifier Setup</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_gradle_project" href="#_gradle_project"></a>80.1 Gradle Project</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_prerequisites" href="#_prerequisites"></a>80.1.1 Prerequisites</h3></div></div></div><p>In order to use Spring Cloud Contract Verifier with WireMock you have to use Gradle or Maven plugin.</p><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="images/warning.png"></td><th align="left">Warning</th></tr><tr><td align="left" valign="top"><p>If you want to use Spock in your projects you have to add separately
|
|
the <code class="literal">spock-core</code> and <code class="literal">spock-spring</code> modules. Check <a class="link" href="http://spockframework.github.io/" target="_top">Spock docs for more information</a></p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_add_gradle_plugin_with_dependencies" href="#_add_gradle_plugin_with_dependencies"></a>80.1.2 Add gradle plugin with dependencies</h3></div></div></div><pre class="programlisting">buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
dependencies {
|
|
classpath <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"org.springframework.boot:spring-boot-gradle-plugin:${springboot_version}"</span>
|
|
classpath <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"org.springframework.cloud:spring-cloud-contract-gradle-plugin:${verifier_version}"</span>
|
|
}
|
|
}
|
|
|
|
apply plugin: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'groovy'</span>
|
|
apply plugin: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'spring-cloud-contract'</span>
|
|
|
|
dependencyManagement {
|
|
imports {
|
|
mavenBom <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"org.springframework.cloud:spring-cloud-contract-dependencies:${verifier_version}"</span>
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
testCompile <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'org.codehaus.groovy:groovy-all:2.4.6'</span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// example with adding Spock core and Spock Spring</span>
|
|
testCompile <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'org.spockframework:spock-core:1.0-groovy-2.4'</span>
|
|
testCompile <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'org.spockframework:spock-spring:1.0-groovy-2.4'</span>
|
|
testCompile <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'org.springframework.cloud:spring-cloud-starter-contract-verifier'</span>
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_gradle_and_rest_assured_3_0" href="#_gradle_and_rest_assured_3_0"></a>80.1.3 Gradle and Rest Assured 3.0</h3></div></div></div><p>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.</p><pre class="programlisting">buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
dependencies {
|
|
classpath <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"org.springframework.boot:spring-boot-gradle-plugin:${springboot_version}"</span>
|
|
classpath <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"org.springframework.cloud:spring-cloud-contract-gradle-plugin:${verifier_version}"</span>
|
|
classpath <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"io.rest-assured:rest-assured:3.0.2"</span>
|
|
classpath <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"io.rest-assured:spring-mock-mvc:3.0.2"</span>
|
|
}
|
|
}
|
|
|
|
depenendencies {
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// all dependencies</span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// you can exclude rest-assured from spring-cloud-contract-verifier</span>
|
|
testCompile <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"io.rest-assured:rest-assured:3.0.2"</span>
|
|
testCompile <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"io.rest-assured:spring-mock-mvc:3.0.2"</span>
|
|
}</pre><p>That way the plugin will automatically see that Rest Assured 3.x is present on the classpath
|
|
and will modify the imports accordingly.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_snapshot_versions_for_gradle" href="#_snapshot_versions_for_gradle"></a>80.1.4 Snapshot versions for Gradle</h3></div></div></div><p>Add the additional snapshot repository to your build.gradle to use snapshot versions which are automatically uploaded after every successful build:</p><pre class="programlisting">buildscript {
|
|
repositories {
|
|
mavenCentral()
|
|
mavenLocal()
|
|
maven { url <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"http://repo.spring.io/snapshot"</span> }
|
|
maven { url <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"http://repo.spring.io/milestone"</span> }
|
|
maven { url <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"http://repo.spring.io/release"</span> }
|
|
}
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_add_stubs" href="#_add_stubs"></a>80.1.5 Add stubs</h3></div></div></div><p>By default Spring Cloud Contract Verifier is looking for stubs in <code class="literal">src/test/resources/contracts</code> directory.</p><p>Directory containing stub definitions is treated as a class name, and each stub definition is treated as a single test.
|
|
We assume that it contains at least one directory which will be used as test class name. If there is more than one level of nested directories all except the last one will be used as package name.
|
|
So with following structure</p><pre class="programlisting">src/test/resources/contracts/myservice/shouldCreateUser.groovy
|
|
src/test/resources/contracts/myservice/shouldReturnUser.groovy</pre><p>Spring Cloud Contract Verifier will create test class <code class="literal">defaultBasePackage.MyService</code> with two methods</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="literal">shouldCreateUser()</code></li><li class="listitem"><code class="literal">shouldReturnUser()</code></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_run_plugin" href="#_run_plugin"></a>80.1.6 Run plugin</h3></div></div></div><p>Plugin registers itself to be invoked before <code class="literal">check</code> task. You have nothing to do as long as you want it to be part of your build process. If you just want to generate tests please invoke <code class="literal">generateContractTests</code> task.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_default_setup" href="#_default_setup"></a>80.1.7 Default setup</h3></div></div></div><p>Default Gradle Plugin setup creates the following Gradle part of the build (it’s a pseudocode)</p><pre class="programlisting">contracts {
|
|
targetFramework = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'JUNIT'</span>
|
|
testMode = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'MockMvc'</span>
|
|
generatedTestSourcesDir = project.file(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"${project.buildDir}/generated-test-sources/contracts"</span>)
|
|
contractsDslDir = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"${project.rootDir}/src/test/resources/contracts"</span>
|
|
basePackageForTests = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'org.springframework.cloud.verifier.tests'</span>
|
|
stubsOutputDir = project.file(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"${project.buildDir}/stubs"</span>)
|
|
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// the following properties are used when you want to provide where the JAR with contract lays</span>
|
|
contractDependency {
|
|
stringNotation = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">''</span>
|
|
}
|
|
contractsPath = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">''</span>
|
|
contractsWorkOffline = false
|
|
contractRepository {
|
|
cacheDownloadedContracts(true)
|
|
}
|
|
}
|
|
|
|
tasks.create(type: Jar, name: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'verifierStubsJar'</span>, dependsOn: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'generateClientStubs'</span>) {
|
|
baseName = project.name
|
|
classifier = contracts.stubsSuffix
|
|
from contractVerifier.stubsOutputDir
|
|
}
|
|
|
|
project.artifacts {
|
|
archives task
|
|
}
|
|
|
|
tasks.create(type: Copy, name: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'copyContracts'</span>) {
|
|
from contracts.contractsDslDir
|
|
into contracts.stubsOutputDir
|
|
}
|
|
|
|
verifierStubsJar.dependsOn <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'copyContracts'</span>
|
|
|
|
publishing {
|
|
publications {
|
|
stubs(MavenPublication) {
|
|
artifactId project.name
|
|
artifact verifierStubsJar
|
|
}
|
|
}
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_configure_plugin" href="#_configure_plugin"></a>80.1.8 Configure plugin</h3></div></div></div><p>To change default configuration just add <code class="literal">contracts</code> snippet to your Gradle config</p><pre class="programlisting">contracts {
|
|
testMode = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'MockMvc'</span>
|
|
baseClassForTests = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'org.mycompany.tests'</span>
|
|
generatedTestSourcesDir = project.file(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'src/generatedContract'</span>)
|
|
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_configuration_options_4" href="#_configuration_options_4"></a>80.1.9 Configuration options</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><span class="strong"><strong>testMode</strong></span> - defines mode for acceptance tests. By default MockMvc which is based on Spring’s MockMvc. It can also be changed to <span class="strong"><strong>JaxRsClient</strong></span> or to <span class="strong"><strong>Explicit</strong></span> for real HTTP calls.</li><li class="listitem"><span class="strong"><strong>imports</strong></span> - array with imports that should be included in generated tests (for example ['org.myorg.Matchers']). By default empty array []</li><li class="listitem"><span class="strong"><strong>staticImports</strong></span> - array with static imports that should be included in generated tests(for example ['org.myorg.Matchers.*']). By default empty array []</li><li class="listitem"><span class="strong"><strong>basePackageForTests</strong></span> - specifies base package for all generated tests. By default set to org.springframework.cloud.verifier.tests</li><li class="listitem"><span class="strong"><strong>baseClassForTests</strong></span> - base class for all generated tests. By default <code class="literal">spock.lang.Specification</code> if using Spock tests.</li><li class="listitem"><span class="strong"><strong>packageWithBaseClasses</strong></span> - instead of providing a fixed value for base class you can provide a package where all the base classes lay. Takes precedence over <span class="strong"><strong>baseClassForTests</strong></span>.</li><li class="listitem"><span class="strong"><strong>baseClassMappings</strong></span> - explicitly map contract package to a FQN of a base class. Takes precedence over <span class="strong"><strong>packageWithBaseClasses</strong></span> and <span class="strong"><strong>baseClassForTests</strong></span>.</li><li class="listitem"><span class="strong"><strong>ruleClassForTests</strong></span> - specifies Rule which should be added to generated test classes.</li><li class="listitem"><span class="strong"><strong>ignoredFiles</strong></span> - Ant matcher allowing defining stub files for which processing should be skipped. By default empty array []</li><li class="listitem"><span class="strong"><strong>contractsDslDir</strong></span> - directory containing contracts written using the GroovyDSL. By default <code class="literal">$rootDir/src/test/resources/contracts</code></li><li class="listitem"><span class="strong"><strong>generatedTestSourcesDir</strong></span> - test source directory where tests generated from Groovy DSL should be placed. By default <code class="literal">$buildDir/generated-test-sources/contractVerifier</code></li><li class="listitem"><span class="strong"><strong>stubsOutputDir</strong></span> - dir where the generated WireMock stubs from Groovy DSL should be placed</li><li class="listitem"><span class="strong"><strong>targetFramework</strong></span> - the target test framework to be used; currently Spock and JUnit are supported with JUnit being the default framework</li></ul></div><p>The following properties are used when you want to provide where the JAR with contract lays</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><span class="strong"><strong>contractDependency</strong></span> - the Dependency that provides <code class="literal">groupid:artifactid:version:classifier</code> coordinates. You can use the <code class="literal">contractDependency</code> closure to set it up</li><li class="listitem"><span class="strong"><strong>contractsPath</strong></span> - if contract deps are downloaded will default to <code class="literal">groupid/artifactid</code> where <code class="literal">groupid</code> will be slash separated. Otherwise will scan contracts under provided directory</li><li class="listitem"><span class="strong"><strong>contractsWorkOffline</strong></span> - in order not to download the dependencies each time you can download them once and work offline afterwards (reuse local Maven repo)</li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_single_base_class_for_all_tests" href="#_single_base_class_for_all_tests"></a>80.1.10 Single base class for all tests</h3></div></div></div><p>When using Spring Cloud Contract Verifier in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">abstract</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> BaseMockMvcSpec <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">extends</span> Specification {
|
|
|
|
def setup() {
|
|
RestAssuredMockMvc.standaloneSetup(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> PairIdController())
|
|
}
|
|
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> isProperCorrelationId(Integer correlationId) {
|
|
assert correlationId == <span class="hl-number">123456</span>
|
|
}
|
|
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> isEmpty(String value) {
|
|
assert value == null
|
|
}
|
|
|
|
}</pre><p>In case of using <code class="literal">Explicit</code> mode, you can use base class to initialize the whole tested app similarly as in regular integration tests. In case of <code class="literal">JAXRSCLIENT</code> mode this base class
|
|
should also contain <code class="literal">protected WebTarget webTarget</code> field, right now the only option to test JAX-RS API is to start a web server.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_different_base_classes_for_contracts" href="#_different_base_classes_for_contracts"></a>80.1.11 Different base classes for contracts</h3></div></div></div><p>If your base classes differ between contracts you can tell the Spring Cloud Contract plugin which class should get
|
|
extended by the autogenerated tests. You have two options:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">follow a convention by providing the <code class="literal">packageWithBaseClasses</code></li><li class="listitem">provide explicit mapping via <code class="literal">baseClassMappings</code></li></ul></div><p><span class="strong"><strong>Convention</strong></span></p><p>The convention is such that if you have a contract under e.g. <code class="literal">src/test/resources/contract/foo/bar/baz/</code> and provide the value of the <code class="literal">packageWithBaseClasses</code> property
|
|
to <code class="literal">com.example.base</code> then we will assume that there is a <code class="literal">BarBazBase</code> class under <code class="literal">com.example.base</code> package. In other words we take last two parts of package
|
|
if they exist and form a class with a <code class="literal">Base</code> suffix. Takes precedence over <span class="strong"><strong>baseClassForTests</strong></span>. Example of usage in the <code class="literal">contracts</code> closure:</p><pre class="programlisting">packageWithBaseClasses = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'com.example.base'</span></pre><p><span class="strong"><strong>Mapping</strong></span></p><p>You can manually map a regular expression of the contract’s package to fully qualified name of the base class for the matched contract.
|
|
Let’s take a look at the following example:</p><pre class="programlisting">baseClassForTests = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"com.example.FooBase"</span>
|
|
baseClassMappings {
|
|
baseClassMapping(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'.*/com/.*'</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'com.example.ComBase'</span>)
|
|
baseClassMapping(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'.*/bar/.*'</span>:<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'com.example.BarBase'</span>)
|
|
}</pre><p>Let’s assume that you have contracts under
|
|
- <code class="literal">src/test/resources/contract/com/</code>
|
|
- <code class="literal">src/test/resources/contract/foo/</code></p><p>By providing the <code class="literal">baseClassForTests</code> we have a fallback in case mapping didn’t succeed (you could also provide
|
|
the <code class="literal">packageWithBaseClasses</code> as fallback). That way the tests generated from <code class="literal">src/test/resources/contract/com/</code> contracts
|
|
will be extending the <code class="literal">com.example.ComBase</code> whereas the rest of tests will extend <code class="literal">com.example.FooBase</code>.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_invoking_generated_tests" href="#_invoking_generated_tests"></a>80.1.12 Invoking generated tests</h3></div></div></div><p>To ensure that provider side is complaint with defined contracts, you need to invoke:</p><pre class="programlisting">./gradlew generateContractTests <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">test</span></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_spring_cloud_contract_verifier_on_consumer_side" href="#_spring_cloud_contract_verifier_on_consumer_side"></a>80.1.13 Spring Cloud Contract Verifier on consumer side</h3></div></div></div><p>In consumer service you need to configure Spring Cloud Contract Verifier plugin in exactly the same way as in case of provider. If you don’t want to use Stub Runner then you need to copy contracts stored in
|
|
<code class="literal">src/test/resources/contracts</code> and generate WireMock json stubs using:</p><pre class="programlisting">./gradlew generateClientStubs</pre><p>Note that <code class="literal">stubsOutputDir</code> option has to be set for stub generation to work.</p><p>When present, json stubs can be used in consumer automated tests.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@ContextConfiguration(loader == SpringApplicationContextLoader, classes == Application)</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> LoanApplicationServiceSpec <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">extends</span> Specification {
|
|
|
|
<em><span class="hl-annotation" style="color: gray">@ClassRule</span></em>
|
|
<em><span class="hl-annotation" style="color: gray">@Shared</span></em>
|
|
WireMockClassRule wireMockRule == <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> WireMockClassRule()
|
|
|
|
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
|
LoanApplicationService sut
|
|
|
|
def <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'should successfully apply for loan'</span>() {
|
|
given:
|
|
LoanApplication application =
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> LoanApplication(client: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> Client(clientPesel: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'12345678901'</span>), amount: <span class="hl-number">123.123</span>)
|
|
when:
|
|
LoanApplicationResult loanApplication == sut.loanApplication(application)
|
|
then:
|
|
loanApplication.loanApplicationStatus == LoanApplicationStatus.LOAN_APPLIED
|
|
loanApplication.rejectionReason == null
|
|
}
|
|
}</pre><p>Underneath LoanApplication makes a call to FraudDetection service. This request is handled by WireMock server configured using stubs generated by Spring Cloud Contract Verifier.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_using_in_your_maven_project" href="#_using_in_your_maven_project"></a>80.2 Using in your Maven project</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_add_maven_plugin" href="#_add_maven_plugin"></a>80.2.1 Add maven plugin</h3></div></div></div><p>Add the Spring Cloud Contract BOM</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependencyManagement></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependencies></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependency></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-dependencies<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>${spring-cloud-dependencies.version}<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><type></span>pom<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></type></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><scope></span>import<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></scope></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependency></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependencies></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependencyManagement></span></pre><p>Next, the <code class="literal">Spring Cloud Contract Verifier</code> Maven plugin</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><plugin></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-contract-maven-plugin<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>${spring-cloud-contract.version}<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><extensions></span>true<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></extensions></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><packageWithBaseClasses></span>com.example.fraud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></packageWithBaseClasses></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></plugin></span></pre><p>You can read more in the <a class="link" href="https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract-maven-plugin/" target="_top">Spring Cloud Contract Maven Plugin Docs</a></p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_maven_and_rest_assured_3_0" href="#_maven_and_rest_assured_3_0"></a>80.2.2 Maven and Rest Assured 3.0</h3></div></div></div><p>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.</p><pre class="programlisting"><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>
|
|
</configuration>
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>org.springframework.cloud</groupId>
|
|
<artifactId>spring-cloud-contract-verifier</artifactId>
|
|
<version>${spring-cloud-contract.version}</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>io.rest-assured</groupId>
|
|
<artifactId>rest-assured</artifactId>
|
|
<version><span class="hl-number">3.0</span>.<span class="hl-number">2</span></version>
|
|
<scope>compile</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>io.rest-assured</groupId>
|
|
<artifactId>spring-mock-mvc</artifactId>
|
|
<version><span class="hl-number">3.0</span>.<span class="hl-number">2</span></version>
|
|
<scope>compile</scope>
|
|
</dependency>
|
|
</dependencies>
|
|
</plugin>
|
|
|
|
<dependencies>
|
|
<!-- all dependencies -->
|
|
<!-- you can exclude rest-assured from spring-cloud-contract-verifier -->
|
|
<dependency>
|
|
<groupId>io.rest-assured</groupId>
|
|
<artifactId>rest-assured</artifactId>
|
|
<version><span class="hl-number">3.0</span>.<span class="hl-number">2</span></version>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>io.rest-assured</groupId>
|
|
<artifactId>spring-mock-mvc</artifactId>
|
|
<version><span class="hl-number">3.0</span>.<span class="hl-number">2</span></version>
|
|
<scope>test</scope>
|
|
</dependency>
|
|
</dependencies></pre><p>That way the plugin will automatically see that Rest Assured 3.x is present on the classpath
|
|
and will modify the imports accordingly.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_snapshot_versions_for_maven" href="#_snapshot_versions_for_maven"></a>80.2.3 Snapshot versions for Maven</h3></div></div></div><p>For Snapshot / Milestone versions you have to add the following section to your <code class="literal">pom.xml</code></p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><repositories></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><repository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><id></span>spring-snapshots<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></id></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><name></span>Spring Snapshots<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></name></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><url></span>https://repo.spring.io/snapshot<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></url></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><enabled></span>true<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></enabled></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></repository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><repository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><id></span>spring-milestones<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></id></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><name></span>Spring Milestones<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></name></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><url></span>https://repo.spring.io/milestone<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></url></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><enabled></span>false<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></enabled></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></repository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><repository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><id></span>spring-releases<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></id></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><name></span>Spring Releases<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></name></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><url></span>https://repo.spring.io/release<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></url></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><enabled></span>false<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></enabled></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></repository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></repositories></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><pluginRepositories></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><pluginRepository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><id></span>spring-snapshots<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></id></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><name></span>Spring Snapshots<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></name></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><url></span>https://repo.spring.io/snapshot<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></url></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><enabled></span>true<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></enabled></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></pluginRepository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><pluginRepository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><id></span>spring-milestones<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></id></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><name></span>Spring Milestones<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></name></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><url></span>https://repo.spring.io/milestone<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></url></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><enabled></span>false<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></enabled></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></pluginRepository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><pluginRepository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><id></span>spring-releases<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></id></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><name></span>Spring Releases<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></name></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><url></span>https://repo.spring.io/release<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></url></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><enabled></span>false<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></enabled></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></snapshots></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></pluginRepository></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></pluginRepositories></span></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_add_stubs_2" href="#_add_stubs_2"></a>80.2.4 Add stubs</h3></div></div></div><p>By default Spring Cloud Contract Verifier is looking for stubs in <code class="literal">src/test/resources/contracts</code> directory.
|
|
Directory containing stub definitions is treated as a class name, and each stub definition is treated as a single test.
|
|
We assume that it contains at least one directory which will be used as test class name. If there is more than one level of nested directories all except the last one will be used as package name.
|
|
So with following structure</p><pre class="programlisting">src/test/resources/contracts/myservice/shouldCreateUser.groovy
|
|
src/test/resources/contracts/myservice/shouldReturnUser.groovy</pre><p>Spring Cloud Contract Verifier will create test class <code class="literal">defaultBasePackage.MyService</code> with two methods
|
|
- <code class="literal">shouldCreateUser()</code>
|
|
- <code class="literal">shouldReturnUser()</code></p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_run_plugin_2" href="#_run_plugin_2"></a>80.2.5 Run plugin</h3></div></div></div><p>Plugin goal <code class="literal">generateTests</code> is assigned to be invoked in phase <code class="literal">generate-test-sources</code>. You have nothing to do as long as you want it to be part of your build process. If you just want to generate tests please invoke <code class="literal">generateTests</code> goal.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_configure_plugin_2" href="#_configure_plugin_2"></a>80.2.6 Configure plugin</h3></div></div></div><p>To change default configuration just add <code class="literal">configuration</code> section to plugin definition or <code class="literal">execution</code> definition.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><plugin></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-contract-maven-plugin<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><executions></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><execution></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goals></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goal></span>convert<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goal></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goal></span>generateStubs<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goal></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goal></span>generateTests<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goal></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goals></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></execution></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></executions></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><basePackageForTests></span>org.springframework.cloud.verifier.twitter.place<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></basePackageForTests></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><baseClassForTests></span>org.springframework.cloud.verifier.twitter.place.BaseMockMvcSpec<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></baseClassForTests></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></plugin></span></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_important_configuration_options" href="#_important_configuration_options"></a>80.2.7 Important configuration options</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><span class="strong"><strong>testMode</strong></span> - defines mode for acceptance tests. By default <code class="literal">MockMvc</code> which is based on Spring’s MockMvc. It can also be changed to <code class="literal">JaxRsClient</code> or to <code class="literal">Explicit</code> for real HTTP calls.</li><li class="listitem"><span class="strong"><strong>basePackageForTests</strong></span> - specifies base package for all generated tests. By default set to <code class="literal">org.springframework.cloud.verifier.tests</code>.</li><li class="listitem"><span class="strong"><strong>ruleClassForTests</strong></span> - specifies Rule which should be added to generated test classes.</li><li class="listitem"><span class="strong"><strong>baseClassForTests</strong></span> - base class for generated tests. By default <code class="literal">spock.lang.Specification</code> if using Spock tests.</li><li class="listitem"><span class="strong"><strong>contractsDirectory</strong></span> - directory containing contracts written using the GroovyDSL. By default <code class="literal">/src/test/resources/contracts</code>.</li><li class="listitem"><span class="strong"><strong>testFramework</strong></span> - the target test framework to be used; currently Spock and JUnit are supported with JUnit being the default framework</li><li class="listitem"><span class="strong"><strong>packageWithBaseClasses</strong></span> - instead of providing a fixed value for base class you can provide a package where all the base classes lay.
|
|
The convention is such that if you have a contract under <code class="literal">src/test/resources/contract/foo/bar/baz/</code> and provide the value of this property
|
|
to <code class="literal">com.example.base</code> then we will assume that there is a <code class="literal">BarBazBase</code> class under <code class="literal">com.example.base</code> package. Takes precedence
|
|
over <span class="strong"><strong>baseClassForTests</strong></span></li><li class="listitem"><span class="strong"><strong>baseClassMappings</strong></span> - list of base class mappings that where you have to provide <code class="literal">contractPackageRegex</code> which is checked
|
|
against the package in which the contract lays and <code class="literal">baseClassFQN</code> that maps to fully qualified name of the base class for the matched
|
|
contract. If you have a contract under <code class="literal">src/test/resources/contract/foo/bar/baz/</code> and map the property <code class="literal">.*</code> → <code class="literal">com.example.base.BaseClass</code> then
|
|
the test class generated from these contracts will extend <code class="literal">com.example.base.BaseClass</code>. Takes precedence over <span class="strong"><strong>packageWithBaseClasses</strong></span>
|
|
and <span class="strong"><strong>baseClassForTests</strong></span>.</li></ul></div><p>If you want to download your contract definitions from a Maven repository you can use</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><span class="strong"><strong>contractDependency</strong></span> - the contract dependency that contains all the packaged contracts</li><li class="listitem"><span class="strong"><strong>contractsPath</strong></span> - path to concrete contracts in the JAR with packaged contracts. Defaults to <code class="literal">groupid/artifactid</code> where <code class="literal">gropuid</code> is slash separated.</li><li class="listitem"><span class="strong"><strong>contractsWorkOffline</strong></span> - if the dependencies should be downloaded or local Maven only should be reused</li><li class="listitem"><span class="strong"><strong>contractsRepositoryUrl</strong></span> - <span class="strong"><strong>DEPRECATED PROPERTY - please use the <code class="literal">contractRepository</code> closure</strong></span> - URL to a repo with the artifacts with contracts, if not provided should use the current Maven ones</li><li class="listitem"><p class="simpara"><span class="strong"><strong>contractRepository</strong></span> - closure where you can define properties related to repository with contracts</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><span class="strong"><strong>username</strong></span> - username to be used to connect to the repo</li><li class="listitem"><span class="strong"><strong>password</strong></span> - username to be used to connect to the repo</li><li class="listitem"><span class="strong"><strong>proxyHost</strong></span> - proxy host to be used to connect to the repo</li><li class="listitem"><span class="strong"><strong>proxyPort</strong></span> - proxy port to be used to connect to the repo</li><li class="listitem"><span class="strong"><strong>cacheDownloadedContracts</strong></span> - if you want to reuse download JARs that contain contract definitions.
|
|
We cache only non-snapshot, explicitly provided versions (e.g. <code class="literal">+</code> or <code class="literal">1.0.0.BUILD-SNAPSHOT</code> won’t get cached).
|
|
By default this feature is turned on.</li></ul></div></li></ul></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_single_base_class_for_all_tests_2" href="#_single_base_class_for_all_tests_2"></a>80.2.8 Single base class for all tests</h3></div></div></div><p>When using Spring Cloud Contract Verifier in default MockMvc you need to create a base specification for all generated acceptance tests.
|
|
In this class you need to point to endpoint which should be verified.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> org.mycompany.tests
|
|
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> org.mycompany.ExampleSpringController
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> com.jayway.restassured.module.mockmvc.RestAssuredMockMvc
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> spock.lang.Specification
|
|
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> MvcSpec <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">extends</span> Specification {
|
|
def setup() {
|
|
RestAssuredMockMvc.standaloneSetup(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> ExampleSpringController())
|
|
}
|
|
}</pre><p>In case of using <code class="literal">Explicit</code> mode, you can use base class to initialize the whole tested app similarly as in regular integration tests. In case of <code class="literal">JAXRSCLIENT</code> mode this base class should also contain <code class="literal">protected WebTarget webTarget</code> field, right now the only option to test JAX-RS API is to start a web server.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_different_base_classes_for_contracts_2" href="#_different_base_classes_for_contracts_2"></a>80.2.9 Different base classes for contracts</h3></div></div></div><p>If your base classes differ between contracts you can tell the Spring Cloud Contract plugin which class should get
|
|
extended by the autogenerated tests. You have two options:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">follow a convention by providing the <code class="literal">packageWithBaseClasses</code></li><li class="listitem">provide explicit mapping via <code class="literal">baseClassMappings</code></li></ul></div><p><span class="strong"><strong>Convention</strong></span></p><p>The convention is such that if you have a contract under e.g. <code class="literal">src/test/resources/contract/hello/v1/</code> and provide the value of the <code class="literal">packageWithBaseClasses</code> property
|
|
to <code class="literal">hello</code> then we will assume that there is a <code class="literal">HelloV1Base</code> class under <code class="literal">hello</code> package. In other words we take last two parts of package
|
|
if they exist and form a class with a <code class="literal">Base</code> suffix. Takes precedence over <span class="strong"><strong>baseClassForTests</strong></span>. Example of usage:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><plugin></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-contract-maven-plugin<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><packageWithBaseClasses></span>hello<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></packageWithBaseClasses></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></plugin></span></pre><p><span class="strong"><strong>Mapping</strong></span></p><p>You can manually map a regular expression of the contract’s package to fully qualified name of the base class for the matched contract.
|
|
You have to provide a list <code class="literal">baseClassMappings</code> of <code class="literal">baseClassMapping</code> that takes a <code class="literal">contractPackageRegex</code> to <code class="literal">baseClassFQN</code> mapping.
|
|
Let’s take a look at the following example:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><plugin></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-contract-maven-plugin<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><baseClassForTests></span>com.example.FooBase<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></baseClassForTests></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><baseClassMappings></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><baseClassMapping></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><contractPackageRegex></span>.*com.*<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></contractPackageRegex></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><baseClassFQN></span>com.example.TestBase<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></baseClassFQN></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></baseClassMapping></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></baseClassMappings></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></plugin></span></pre><p>Let’s assume that you have contracts under
|
|
- <code class="literal">src/test/resources/contract/com/</code>
|
|
- <code class="literal">src/test/resources/contract/foo/</code></p><p>By providing the <code class="literal">baseClassForTests</code> we have a fallback in case mapping didn’t succeed (you could also provide
|
|
the <code class="literal">packageWithBaseClasses</code> as fallback). That way the tests generated from <code class="literal">src/test/resources/contract/com/</code> contracts
|
|
will be extending the <code class="literal">com.example.ComBase</code> whereas the rest of tests will extend <code class="literal">com.example.FooBase</code>.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_invoking_generated_tests_2" href="#_invoking_generated_tests_2"></a>80.2.10 Invoking generated tests</h3></div></div></div><p>Spring Cloud Contract Maven Plugin generates verification code into directory <code class="literal">/generated-test-sources/contractVerifier</code> and attach this directory to <code class="literal">testCompile</code> goal.</p><p>For Groovy Spock code use:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><plugin></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.codehaus.gmavenplus<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>gmavenplus-plugin<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>1.5<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><executions></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><execution></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goals></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goal></span>testCompile<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goal></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goals></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></execution></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></executions></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><testSources></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><testSource></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><directory></span>${project.basedir}/src/test/groovy<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></directory></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><includes></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><include></span>**/*.groovy<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></include></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></includes></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></testSource></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><testSource></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><directory></span>${project.build.directory}/generated-test-sources/contractVerifier<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></directory></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><includes></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><include></span>**/*.groovy<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></include></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></includes></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></testSource></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></testSources></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></plugin></span></pre><p>To ensure that provider side is complaint with defined contracts, you need to invoke <code class="literal">mvn generateTest test</code></p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_faq_with_maven_plugin" href="#_faq_with_maven_plugin"></a>80.2.11 FAQ with Maven Plugin</h3></div></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_maven_plugin_and_sts" href="#_maven_plugin_and_sts"></a>80.2.12 Maven Plugin and STS</h3></div></div></div><p>In case you see the following exception while using STS</p><div class="informalfigure"><div class="mediaobject"><img src="https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/1.0.x/docs/src/main/asciidoc/images/sts_exception.png" alt="STS Exception"></div></div><p>when you click on the marker you should see sth like this</p><pre class="programlisting"> plugin:<span class="hl-number">1.1</span>.<span class="hl-number">0.</span>M1:convert:default-convert:process-<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">test</span>-resources) org.apache.maven.plugin.PluginExecutionException: Execution default-convert of goal org.springframework.cloud:spring-
|
|
cloud-contract-maven-plugin:<span class="hl-number">1.1</span>.<span class="hl-number">0.</span>M1:convert failed. at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:<span class="hl-number">145</span>) at
|
|
org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:<span class="hl-number">331</span>) at org.eclipse.m2e.core.internal.embedder.MavenImpl$<span class="hl-number">11.</span>call(MavenImpl.java:<span class="hl-number">1362</span>) at
|
|
...
|
|
org.eclipse.core.internal.jobs.Worker.run(Worker.java:<span class="hl-number">55</span>) Caused by: java.lang.NullPointerException at
|
|
org.eclipse.m2e.core.internal.builder.plexusbuildapi.EclipseIncrementalBuildContext.hasDelta(EclipseIncrementalBuildContext.java:<span class="hl-number">53</span>) at
|
|
org.sonatype.plexus.build.incremental.ThreadBuildContext.hasDelta(ThreadBuildContext.java:<span class="hl-number">59</span>) at</pre><p>In order to fix this issue just provide the following section in your <code class="literal">pom.xml</code></p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><build></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><pluginManagement></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><plugins></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment"><!--This plugin's configuration is used to store Eclipse m2e settings
|
|
only. It has no influence on the Maven build itself. --></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><plugin></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.eclipse.m2e<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>lifecycle-mapping<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>1.0.0<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><lifecycleMappingMetadata></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><pluginExecutions></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><pluginExecution></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><pluginExecutionFilter></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-contract-maven-plugin<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><versionRange></span>[1.0,)<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></versionRange></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goals></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goal></span>convert<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goal></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goals></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></pluginExecutionFilter></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><action></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><execute /></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></action></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></pluginExecution></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></pluginExecutions></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></lifecycleMappingMetadata></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></configuration></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></plugin></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></plugins></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></pluginManagement></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></build></span></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_spring_cloud_contract_verifier_on_consumer_side_2" href="#_spring_cloud_contract_verifier_on_consumer_side_2"></a>80.2.13 Spring Cloud Contract Verifier on consumer side</h3></div></div></div><p>You can actually use the Spring Cloud Contract Verifier also for the consumer side!
|
|
You can use the plugin so that it only converts the contracts and generates the stubs.
|
|
To achieve that you need to configure Spring Cloud Contract Verifier plugin in exactly
|
|
the same way as in case of provider. You need to copy contracts stored in
|
|
<code class="literal">src/test/resources/contracts</code> and generate WireMock json stubs using:
|
|
<code class="literal">mvn generateStubs</code> command. By default generated WireMock mapping is
|
|
stored in directory <code class="literal">target/mappings</code>. Your project should create from
|
|
this generated mappings additional artifact with classifier <code class="literal">stubs</code> for
|
|
easy deploy to maven repository.</p><p>Sample configuration:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><plugin></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-contract-maven-plugin<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>${verifier-plugin.version}<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><executions></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><execution></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goals></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goal></span>convert<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goal></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><goal></span>generateStubs<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goal></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></goals></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></execution></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></executions></span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></plugin></span></pre><p>When present, json stubs can be used in consumer automated tests.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@RunWith(SpringTestRunner.class)</span></em>
|
|
<em><span class="hl-annotation" style="color: gray">@SpringBootTest</span></em>
|
|
<em><span class="hl-annotation" style="color: gray">@AutoConfigureStubRunner</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> LoanApplicationServiceTests {
|
|
|
|
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
|
LoanApplicationService service;
|
|
|
|
<em><span class="hl-annotation" style="color: gray">@Test</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> shouldSuccessfullyApplyForLoan() {
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">//given:</span>
|
|
LoanApplication application =
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> LoanApplication(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> Client(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"12345678901"</span>), <span class="hl-number">123.123</span>);
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">//when:</span>
|
|
LoanApplicationResult loanApplication = service.loanApplication(application);
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// then:</span>
|
|
assertThat(loanApplication.loanApplicationStatus).isEqualTo(LoanApplicationStatus.LOAN_APPLIED);
|
|
assertThat(loanApplication.rejectionReason).isNull();
|
|
}
|
|
}</pre><p>Underneath <code class="literal">LoanApplication</code> makes a call to the <code class="literal">FraudDetection</code> service. This request is handled by
|
|
a WireMock server configured using stubs generated by Spring Cloud Contract Verifier.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_scenarios" href="#_scenarios"></a>80.3 Scenarios</h2></div></div></div><p>It’s possible to handle scenarios with Spring Cloud Contract Verifier. All you need to do is to stick to proper naming convention while creating your contracts. The convention requires to include order number followed by the underscore.</p><pre class="screen">my_contracts_dir\
|
|
scenario1\
|
|
1_login.groovy
|
|
2_showCart.groovy
|
|
3_logout.groovy</pre><p>Such tree will cause Spring Cloud Contract Verifier generating WireMock’s scenario with name <code class="literal">scenario1</code> and three steps:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">login marked as <code class="literal">Started</code> pointing to:</li><li class="listitem">showCart marked as <code class="literal">Step1</code> pointing to:</li><li class="listitem">logout marked as <code class="literal">Step2</code> which will close the scenario.</li></ul></div><p>More details about WireMock scenarios can be found under <a class="link" href="http://wiremock.org/stateful-behaviour.html" target="_top">http://wiremock.org/stateful-behaviour.html</a></p><p>Spring Cloud Contract Verifier will also generate tests with guaranteed order of execution.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_stubs_and_transitive_dependencies" href="#_stubs_and_transitive_dependencies"></a>80.4 Stubs and transitive dependencies</h2></div></div></div><p>The Maven and Gradle plugin that we’re created are adding the tasks that create the stubs jar for you. What can be problematic
|
|
is that when reusing the stubs you can by mistake import all of that stub dependencies! When building a Maven artifact
|
|
even though you have a couple of different jars, all of them share one pom:</p><pre class="programlisting">├── github-webhook-<span class="hl-number">0.0</span>.<span class="hl-number">1.</span>BUILD-<span class="hl-number">20160903.075506</span>-<span class="hl-number">1</span>-stubs.jar
|
|
├── github-webhook-<span class="hl-number">0.0</span>.<span class="hl-number">1.</span>BUILD-<span class="hl-number">20160903.075506</span>-<span class="hl-number">1</span>-stubs.jar.sha1
|
|
├── github-webhook-<span class="hl-number">0.0</span>.<span class="hl-number">1.</span>BUILD-<span class="hl-number">20160903.075655</span>-<span class="hl-number">2</span>-stubs.jar
|
|
├── github-webhook-<span class="hl-number">0.0</span>.<span class="hl-number">1.</span>BUILD-<span class="hl-number">20160903.075655</span>-<span class="hl-number">2</span>-stubs.jar.sha1
|
|
├── github-webhook-<span class="hl-number">0.0</span>.<span class="hl-number">1.</span>BUILD-SNAPSHOT.jar
|
|
├── github-webhook-<span class="hl-number">0.0</span>.<span class="hl-number">1.</span>BUILD-SNAPSHOT.pom
|
|
├── github-webhook-<span class="hl-number">0.0</span>.<span class="hl-number">1.</span>BUILD-SNAPSHOT-stubs.jar
|
|
├── ...
|
|
└── ...</pre><p>There are three possibilities of working with those dependencies so as not to have any issues with transitive dependencies.</p><p><span class="strong"><strong>Mark all application dependencies as optional</strong></span></p><p>If in the <code class="literal">github-webhook</code> application we would mark all of our dependencies as optional, when you include the
|
|
<code class="literal">github-webhook</code> stubs in another application (or when that dependency gets downloaded by Stub Runner) then, since
|
|
all of the depenencies are optional, they will not get downloaded.</p><p><span class="strong"><strong>Create a separate artifactid for stubs</strong></span></p><p>If you create a separate artifactid then you can set it up in whatever way you wish. For example by having no dependencies at all.</p><p><span class="strong"><strong>Exclude dependencies on the consumer side</strong></span></p><p>As a consumer, if you add the stub dependency to your classpath you can explicitly exclude the unwanted dependencies.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__spring_cloud_contract_verifier_introduction.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="multi__spring_cloud_contract.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="multi__spring_cloud_contract_verifier_messaging.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">79. Spring Cloud Contract Verifier Introduction </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud.html">Home</a></td><td width="40%" align="right" valign="top"> 81. Spring Cloud Contract Verifier Messaging</td></tr></table></div></body></html> |