Sync docs from master to gh-pages

This commit is contained in:
buildmaster
2018-02-16 15:52:38 +00:00
parent a5e58c43dc
commit 98f4c2d3dd
30 changed files with 276 additions and 312 deletions

View File

@@ -4,7 +4,7 @@
<book xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<info>
<title>Spring Cloud Contract</title>
<date>2018-02-08</date>
<date>2018-02-11</date>
</info>
<preface>
<title></title>
@@ -1382,7 +1382,7 @@ of the JAR containing the contracts:</simpara>
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-contract-maven-plugin&lt;/artifactId&gt;
&lt;configuration&gt;
&lt;stubsMode&gt;REMOTE&lt;/stubsMode&gt;
&lt;contractsMode&gt;REMOTE&lt;/contractsMode&gt;
&lt;contractsRepositoryUrl&gt;http://link/to/your/nexus/or/artifactory/or/sth&lt;/contractsRepositoryUrl&gt;
&lt;contractDependency&gt;
&lt;groupId&gt;com.example.standalone&lt;/groupId&gt;
@@ -1726,9 +1726,10 @@ closure to set it up.
* <emphasis role="strong">contractsPath</emphasis>: Specifies the path to the jar. If contract dependencies are
downloaded, the path defaults to <literal>groupid/artifactid</literal> where <literal>groupid</literal> is slash
separated. Otherwise, it scans contracts under the provided directory.
* <emphasis role="strong">contractsWorkOffline</emphasis>: Specifies whether to download the dependencies each time, so
that you can work online. In other words, it specifies whether to reuses the local Maven
repo.</simpara>
* <emphasis role="strong">contractsMode</emphasis>: Specifies the mode of downloading contracts (whether the
JAR is available offline, remotely etc.)
* <emphasis role="strong">contractsSnapshotCheckSkip</emphasis>: If set to <literal>true</literal> will not assert whether the
downloaded stubs / contract JAR was downloaded from a remote location or a local one</simpara>
</section>
<section xml:id="gradle-single-base-class">
<title>Single Base Class for All Tests</title>
@@ -1873,9 +1874,6 @@ following sections:</simpara>
<listitem>
<simpara><xref linkend="maven-sts"/></simpara>
</listitem>
<listitem>
<simpara><xref linkend="maven-consumer"/></simpara>
</listitem>
</itemizedlist>
<section xml:id="maven-add-plugin">
<title>Add maven plugin</title>
@@ -2124,8 +2122,11 @@ the following options:</simpara>
Defaults to <literal>groupid/artifactid</literal> where <literal>gropuid</literal> is slash separated.</simpara>
</listitem>
<listitem>
<simpara><emphasis role="strong">contractsWorkOffline</emphasis>: Dictates whether the dependencies should be downloaded or the
local Maven artifacts should be reused.</simpara>
<simpara><emphasis role="strong">contractsMode</emphasis>: Picks the mode in which stubs will be found and registered</simpara>
</listitem>
<listitem>
<simpara><emphasis role="strong">contractsSnapshotCheckSkip</emphasis>: If <literal>true</literal> then will not assert whether a stub / contract
JAR was downloaded from local or remote location</simpara>
</listitem>
<listitem>
<simpara><emphasis role="strong">contractsRepositoryUrl</emphasis>: URL to a repo with the artifacts that have contracts. If it is not provided,
@@ -2311,56 +2312,6 @@ goal.</simpara>
&lt;/pluginManagement&gt;
&lt;/build&gt;</programlisting>
</section>
<section xml:id="maven-consumer">
<title>Spring Cloud Contract Verifier on the Consumer Side</title>
<simpara>You can also use the Spring Cloud Contract Verifier for the consumer side. To do so, 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 you would for a provider. You need to copy contracts stored in
<literal>src/test/resources/contracts</literal> and generate WireMock JSON stubs using the
<literal>mvn generateStubs</literal> command. By default, the generated WireMock mapping is stored in a
directory named <literal>target/mappings</literal>. From these generated mappings, your project should
create additional artifacts with a classifier of <literal>stubs</literal> for easy deployment to the maven
repository.</simpara>
<simpara>Here is a sample configuration:</simpara>
<programlisting language="xml" linenumbering="unnumbered">&lt;plugin&gt;
&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
&lt;artifactId&gt;spring-cloud-contract-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${verifier-plugin.version}&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;goals&gt;
&lt;goal&gt;convert&lt;/goal&gt;
&lt;goal&gt;generateStubs&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;</programlisting>
<simpara>When present, JSON stubs can be used in consumer automated tests, as shown here:</simpara>
<programlisting language="groovy" linenumbering="unnumbered">@RunWith(SpringTestRunner.class)
@SpringBootTest
@AutoConfigureStubRunner
public class LoanApplicationServiceTests {
@Autowired
LoanApplicationService service;
@Test
public void shouldSuccessfullyApplyForLoan() {
//given:
LoanApplication application =
new LoanApplication(new Client("12345678901"), 123.123);
//when:
LoanApplicationResult loanApplication = service.loanApplication(application);
// then:
assertThat(loanApplication.loanApplicationStatus).isEqualTo(LoanApplicationStatus.LOAN_APPLIED);
assertThat(loanApplication.rejectionReason).isNull();
}
}</programlisting>
<simpara><literal>LoanApplication</literal> makes a call to the <literal>FraudDetection</literal> service. This request is handled
by a WireMock server configured with stubs generated by the Spring Cloud Contract
Verifier.</simpara>
</section>
</section>
<section xml:id="_stubs_and_transitive_dependencies">
<title>Stubs and Transitive Dependencies</title>
@@ -2402,6 +2353,29 @@ For example, you might decide to have no dependencies at all.</simpara>
<simpara>As a consumer, if you add the stub dependency to your classpath, you can explicitly
exclude the unwanted dependencies.</simpara>
</section>
<section xml:id="_ci_server_setup">
<title>CI Server setup</title>
<simpara>When fetching stubs / contracts in a CI, shared environment, what might happen is that
both the producer and the consumer reuse the same local Maven repository. Due to this,
the framework, responsible for downloading a stub JAR from remote location,
can&#8217;t decide which JAR should be picked, local or remote one. That caused
the <literal>"The artifact was found in the local repository but you have explicitly
stated that it should be downloaded from a remote one"</literal> exception
and failed the build.</simpara>
<simpara>For such cases we&#8217;re introducing the property and plugin setup mechanism:</simpara>
<itemizedlist>
<listitem>
<simpara>via <literal>stubrunner.snapshot-check-skip</literal> system property</simpara>
</listitem>
<listitem>
<simpara>via <literal>STUBRUNNER_SNAPSHOT_CHECK_SKIP</literal> environment variable</simpara>
</listitem>
</itemizedlist>
<simpara>if either of these values is set to <literal>true</literal>, then the stub downloader will not
verify the origin of the downloaded JAR.</simpara>
<simpara>For the plugins you need to set the <literal>contractsSnapshotSkipCheck</literal> property
to <literal>true</literal>.</simpara>
</section>
<section xml:id="_scenarios">
<title>Scenarios</title>
<simpara>You can handle scenarios with Spring Cloud Contract Verifier. All you need to do is to