Sync docs from master to gh-pages
This commit is contained in:
@@ -474,6 +474,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
||||
<li><a href="#_producer">Producer</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#_can_i_have_multiple_base_classes_for_tests">Can I have multiple base classes for tests?</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -495,7 +496,8 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
||||
<li><a href="#_configure_plugin">Configure plugin</a>
|
||||
<ul class="sectlevel5">
|
||||
<li><a href="#_configuration_options">Configuration options</a></li>
|
||||
<li><a href="#_base_class_for_tests">Base class for tests</a></li>
|
||||
<li><a href="#_single_base_class_for_all_tests">Single base class for all tests</a></li>
|
||||
<li><a href="#_different_base_classes_for_contracts">Different base classes for contracts</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#_invoking_generated_tests">Invoking generated tests</a></li>
|
||||
@@ -514,7 +516,8 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
||||
<li><a href="#_configure_plugin_2">Configure plugin</a>
|
||||
<ul class="sectlevel5">
|
||||
<li><a href="#_important_configuration_options">Important configuration options</a></li>
|
||||
<li><a href="#_base_class_for_tests_2">Base class for tests</a></li>
|
||||
<li><a href="#_single_base_class_for_all_tests_2">Single base class for all tests</a></li>
|
||||
<li><a href="#_different_base_classes_for_contracts_2">Different base classes for contracts</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#_invoking_generated_tests_2">Invoking generated tests</a></li>
|
||||
@@ -1293,7 +1296,7 @@ It’s really important that you understand the map notation to set up contr
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<baseClassForTests>com.example.fraud.MvcTest</baseClassForTests>
|
||||
<packageWithBaseClasses>com.example.fraud</packageWithBaseClasses>
|
||||
</configuration>
|
||||
</plugin></code></pre>
|
||||
</div>
|
||||
@@ -1479,7 +1482,7 @@ git pull https://your-git-server.com/server-side-fork.git contract-change-pr</co
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<baseClassForTests>com.example.fraud.MvcTest</baseClassForTests>
|
||||
<packageWithBaseClasses>com.example.fraud</packageWithBaseClasses>
|
||||
</configuration>
|
||||
</plugin></code></pre>
|
||||
</div>
|
||||
@@ -1496,7 +1499,7 @@ import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
public class MvcTest {
|
||||
public class FraudBase {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -2323,6 +2326,13 @@ when some incompatible changes are done.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect4">
|
||||
<h5 id="_can_i_have_multiple_base_classes_for_tests">Can I have multiple base classes for tests?</h5>
|
||||
<div class="paragraph">
|
||||
<p>Yes! Check out the <a href="https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#different_base_classes_for_contracts">Different base classes for contracts</a> sections
|
||||
of either Gradle or Maven plugins.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
@@ -2559,7 +2569,13 @@ publishing {
|
||||
<p><strong>basePackageForTests</strong> - specifies base package for all generated tests. By default set to org.springframework.cloud.verifier.tests</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>baseClassForTests</strong> - base class for generated tests. By default <code>spock.lang.Specification</code> if using Spock tests.</p>
|
||||
<p><strong>baseClassForTests</strong> - base class for all generated tests. By default <code>spock.lang.Specification</code> if using Spock tests.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>packageWithBaseClasses</strong> - instead of providing a fixed value for base class you can provide a package where all the base classes lay. Takes precedence over <strong>baseClassForTests</strong>.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>baseClassMappings</strong> - explicitly map contract package to a FQN of a base class. Takes precedence over <strong>packageWithBaseClasses</strong> and <strong>baseClassForTests</strong>.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>ruleClassForTests</strong> - specifies Rule which should be added to generated test classes.</p>
|
||||
@@ -2599,7 +2615,7 @@ publishing {
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect5">
|
||||
<h6 id="_base_class_for_tests">Base class for tests</h6>
|
||||
<h6 id="_single_base_class_for_all_tests">Single base class for all tests</h6>
|
||||
<div class="paragraph">
|
||||
<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>
|
||||
</div>
|
||||
@@ -2627,6 +2643,62 @@ publishing {
|
||||
should also contain <code>protected WebTarget webTarget</code> field, right now the only option to test JAX-RS API is to start a web server.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect5">
|
||||
<h6 id="_different_base_classes_for_contracts">Different base classes for contracts</h6>
|
||||
<div class="paragraph">
|
||||
<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>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p>follow a convention by providing the <code>packageWithBaseClasses</code></p>
|
||||
</li>
|
||||
<li>
|
||||
<p>provide explicit mapping via <code>baseClassMappings</code></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><strong>Convention</strong></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The convention is such that if you have a contract under e.g. <code>src/test/resources/contract/foo/bar/baz/</code> and provide the value of the <code>packageWithBaseClasses</code> property
|
||||
to <code>com.example.base</code> then we will assume that there is a <code>BarBazBase</code> class under <code>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>Base</code> suffix. Takes precedence over <strong>baseClassForTests</strong>. Example of usage in the <code>contracts</code> closure:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlight"><code class="language-groovy" data-lang="groovy">packageWithBaseClasses = 'com.example.base'</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><strong>Mapping</strong></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<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>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlight"><code class="language-groovy" data-lang="groovy">baseClassForTests = "com.example.FooBase"
|
||||
baseClassMappings {
|
||||
baseClassMapping('.*/com/.*', 'com.example.ComBase')
|
||||
baseClassMapping('.*/bar/.*':'com.example.BarBase')
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Let’s assume that you have contracts under
|
||||
- <code>src/test/resources/contract/com/</code>
|
||||
- <code>src/test/resources/contract/foo/</code></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>By providing the <code>baseClassForTests</code> we have a fallback in case mapping didn’t succeed (you could also provide
|
||||
the <code>packageWithBaseClasses</code> as fallback). That way the tests generated from <code>src/test/resources/contract/com/</code> contracts
|
||||
will be extending the <code>com.example.ComBase</code> whereas the rest of tests will extend <code>com.example.FooBase</code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect4">
|
||||
<h5 id="_invoking_generated_tests">Invoking generated tests</h5>
|
||||
@@ -2719,7 +2791,7 @@ class LoanApplicationServiceSpec extends Specification {
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<baseClassForTests>com.example.fraud.MvcTest</baseClassForTests>
|
||||
<packageWithBaseClasses>com.example.fraud</packageWithBaseClasses>
|
||||
</configuration>
|
||||
</plugin></code></pre>
|
||||
</div>
|
||||
@@ -2864,6 +2936,19 @@ src/test/resources/contracts/myservice/shouldReturnUser.groovy</code></pre>
|
||||
<li>
|
||||
<p><strong>testFramework</strong> - the target test framework to be used; currently Spock and JUnit are supported with JUnit being the default framework</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>packageWithBaseClasses</strong> - 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>src/test/resources/contract/foo/bar/baz/</code> and provide the value of this property
|
||||
to <code>com.example.base</code> then we will assume that there is a <code>BarBazBase</code> class under <code>com.example.base</code> package. Takes precedence
|
||||
over <strong>baseClassForTests</strong></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><strong>baseClassMappings</strong> - list of base class mappings that where you have to provide <code>contractPackageRegex</code> which is checked
|
||||
against the package in which the contract lays and <code>baseClassFQN</code> that maps to fully qualified name of the base class for the matched
|
||||
contract. If you have a contract under <code>src/test/resources/contract/foo/bar/baz/</code> and map the property <code>.*</code> → <code>com.example.base.BaseClass</code> then
|
||||
the test class generated from these contracts will extend <code>com.example.base.BaseClass</code>. Takes precedence over <strong>packageWithBaseClasses</strong>
|
||||
and <strong>baseClassForTests</strong>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
@@ -2890,7 +2975,7 @@ src/test/resources/contracts/myservice/shouldReturnUser.groovy</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect5">
|
||||
<h6 id="_base_class_for_tests_2">Base class for tests</h6>
|
||||
<h6 id="_single_base_class_for_all_tests_2">Single base class for all tests</h6>
|
||||
<div class="paragraph">
|
||||
<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>
|
||||
@@ -2914,6 +2999,81 @@ class MvcSpec extends Specification {
|
||||
<p>In case of using <code>Explicit</code> mode, you can use base class to initialize the whole tested app similarly as in regular integration tests. In case of <code>JAXRSCLIENT</code> mode this base class should also contain <code>protected WebTarget webTarget</code> field, right now the only option to test JAX-RS API is to start a web server.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect5">
|
||||
<h6 id="_different_base_classes_for_contracts_2">Different base classes for contracts</h6>
|
||||
<div class="paragraph">
|
||||
<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>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p>follow a convention by providing the <code>packageWithBaseClasses</code></p>
|
||||
</li>
|
||||
<li>
|
||||
<p>provide explicit mapping via <code>baseClassMappings</code></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><strong>Convention</strong></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The convention is such that if you have a contract under e.g. <code>src/test/resources/contract/hello/v1/</code> and provide the value of the <code>packageWithBaseClasses</code> property
|
||||
to <code>hello</code> then we will assume that there is a <code>HelloV1Base</code> class under <code>hello</code> package. In other words we take last two parts of package
|
||||
if they exist and form a class with a <code>Base</code> suffix. Takes precedence over <strong>baseClassForTests</strong>. Example of usage in the <code>contracts</code> closure:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlight"><code class="language-xml" data-lang="xml"> <plugin>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<packageWithBaseClasses>hello</packageWithBaseClasses>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><strong>Mapping</strong></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<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>baseClassMappings</code> of <code>baseClassMapping</code> that takes a <code>contractPackageRegex</code> to <code>baseClassFQN</code> mapping.
|
||||
Let’s take a look at the following example:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlight"><code class="language-xml" data-lang="xml"><plugin>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<baseClassForTests>com.example.FooBase</baseClassForTests>
|
||||
<baseClassMappings>
|
||||
<baseClassMapping>
|
||||
<contractPackageRegex>.*com.*</contractPackageRegex>
|
||||
<baseClassFQN>com.example.TestBase</baseClassFQN>
|
||||
</baseClassMapping >
|
||||
</baseClassMappings>
|
||||
</configuration>
|
||||
</plugin></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Let’s assume that you have contracts under
|
||||
- <code>src/test/resources/contract/com/</code>
|
||||
- <code>src/test/resources/contract/foo/</code></p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>By providing the <code>baseClassForTests</code> we have a fallback in case mapping didn’t succeed (you could also provide
|
||||
the <code>packageWithBaseClasses</code> as fallback). That way the tests generated from <code>src/test/resources/contract/com/</code> contracts
|
||||
will be extending the <code>com.example.ComBase</code> whereas the rest of tests will extend <code>com.example.FooBase</code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect4">
|
||||
<h5 id="_invoking_generated_tests_2">Invoking generated tests</h5>
|
||||
|
||||
Reference in New Issue
Block a user