Merge branch '1.2.x'

also accidentally fixed gh-507
This commit is contained in:
Marcin Grzejszczak
2018-02-16 16:05:54 +01:00
28 changed files with 331 additions and 169 deletions

View File

@@ -255,9 +255,10 @@ closure to set it up.
* *contractsPath*: Specifies the path to the jar. If contract dependencies are
downloaded, the path defaults to `groupid/artifactid` where `groupid` is slash
separated. Otherwise, it scans contracts under the provided directory.
* *contractsWorkOffline*: 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.
* *contractsMode*: Specifies the mode of downloading contracts (whether the
JAR is available offline, remotely etc.)
* *contractsSnapshotCheckSkip*: If set to `true` will not assert whether the
downloaded stubs / contract JAR was downloaded from a remote location or a local one
[[gradle-single-base-class]]
==== Single Base Class for All Tests
@@ -393,7 +394,6 @@ following sections:
* <<maven-different-base>>
* <<maven-invoking-generated-tests>>
* <<maven-sts>>
* <<maven-consumer>>
[[maven-add-plugin]]
==== Add maven plugin
@@ -581,8 +581,9 @@ the following options:
* *contractDependency*: The contract dependency that contains all the packaged contracts.
* *contractsPath*: The path to the concrete contracts in the JAR with packaged contracts.
Defaults to `groupid/artifactid` where `gropuid` is slash separated.
* *contractsWorkOffline*: Dictates whether the dependencies should be downloaded or the
local Maven artifacts should be reused.
* *contractsMode*: Picks the mode in which stubs will be found and registered
* *contractsSnapshotCheckSkip*: If `true` then will not assert whether a stub / contract
JAR was downloaded from local or remote location
* *contractsRepositoryUrl*: URL to a repo with the artifacts that have contracts. If it is not provided,
use the current Maven ones.
* *contractsRepositoryUsername*: The user name to be used to connect to the repo with contracts.
@@ -767,67 +768,6 @@ In order to fix this issue, provide the following section in your `pom.xml`:
</build>
----
[[maven-consumer]]
==== Spring Cloud Contract Verifier on the Consumer Side
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
`src/test/resources/contracts` and generate WireMock JSON stubs using the
`mvn generateStubs` command. By default, the generated WireMock mapping is stored in a
directory named `target/mappings`. From these generated mappings, your project should
create additional artifacts with a classifier of `stubs` for easy deployment to the maven
repository.
Here is a sample configuration:
[source,xml,indent=0]
----
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${verifier-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>convert</goal>
<goal>generateStubs</goal>
</goals>
</execution>
</executions>
</plugin>
----
When present, JSON stubs can be used in consumer automated tests, as shown here:
[source,groovy,indent=0]
----
@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();
}
}
----
`LoanApplication` makes a call to the `FraudDetection` service. This request is handled
by a WireMock server configured with stubs generated by the Spring Cloud Contract
Verifier.
=== Stubs and Transitive Dependencies
The Maven and Gradle plugin that add the tasks that create the stubs jar for you. One
@@ -872,6 +812,27 @@ For example, you might decide to have no dependencies at all.
As a consumer, if you add the stub dependency to your classpath, you can explicitly
exclude the unwanted dependencies.
=== CI Server setup
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't decide which JAR should be picked, local or remote one. That caused
the `"The artifact was found in the local repository but you have explicitly
stated that it should be downloaded from a remote one"` exception
and failed the build.
For such cases we're introducing the property and plugin setup mechanism:
- via `stubrunner.snapshot-check-skip` system property
- via `STUBRUNNER_SNAPSHOT_CHECK_SKIP` environment variable
if either of these values is set to `true`, then the stub downloader will not
verify the origin of the downloaded JAR.
For the plugins you need to set the `contractsSnapshotSkipCheck` property
to `true`.
=== Scenarios
You can handle scenarios with Spring Cloud Contract Verifier. All you need to do is to