diff --git a/multi/multi__spring_cloud_contract_faq.html b/multi/multi__spring_cloud_contract_faq.html index 1f974d14b3..1aedba9dac 100644 --- a/multi/multi__spring_cloud_contract_faq.html +++ b/multi/multi__spring_cloud_contract_faq.html @@ -280,6 +280,7 @@ of the JAR containing the contracts:
<groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-maven-plugin</artifactId> <configuration> + <stubsMode>REMOTE</stubsMode> <contractsRepositoryUrl>http://link/to/your/nexus/or/artifactory/or/sth</contractsRepositoryUrl> <contractDependency> <groupId>com.example.standalone</groupId> diff --git a/multi/multi__spring_cloud_contract_stub_runner.html b/multi/multi__spring_cloud_contract_stub_runner.html index f7ddef1819..9077f2ba3b 100644 --- a/multi/multi__spring_cloud_contract_stub_runner.html +++ b/multi/multi__spring_cloud_contract_stub_runner.html @@ -159,12 +159,10 @@ publishing { }
Runs stubs for service collaborators. Treating stubs as contracts of services allows to use stub-runner as an implementation of Consumer Driven Contracts.
Stub Runner allows you to automatically download the stubs of the provided dependencies (or pick those from the classpath), start WireMock servers for them and feed them with proper stub definitions. -For messaging, special stub routes are defined.
You can pick the following options of acquiring stubs
org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder for full customizationThe latter example is described in the Custom Stub Runner section.
If you provide the stubrunner.repositoryRoot or stubrunner.workOffline flag will be set
-to true then Stub Runner will connect to the given server and download the required jars.
-It will then unpack the JAR to a temporary folder and reference those files in further
-contract processing.
Example:
@AutoConfigureStubRunner(repositoryRoot="http://foo.bar", ids = "com.example:beer-api-producer:+:stubs:8095")
If you DON’T provide the stubrunner.repositoryRoot and stubrunner.workOffline flag will
-be set to false (that’s the default) then classpath will get scanned. Let’s look at the
-following example:
@AutoConfigureStubRunner(ids = {
+For messaging, special stub routes are defined.You can pick the following options of acquiring stubs
- Aether based solution that downloads JARs with stubs from Artifactory / Nexus
- Classpath scanning solution that searches classpath via pattern to retrieve stubs
- Write your own implementation of the
org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder for full customization
The latter example is described in the Custom Stub Runner section.
You can control the stub downloading via the stubsMode switch. It picks value from the
+StubRunnerProperties.StubsMode enum. You can use the following options
StubRunnerProperties.StubsMode.CLASSPATH (default value) - will pick stubs from the classpathStubRunnerProperties.StubsMode.LOCAL - will pick stubs from a local storage (e.g. .m2)StubRunnerProperties.StubsMode.REMOTE - will pick stubs from a remote location
Example:
@AutoConfigureStubRunner(repositoryRoot="http://foo.bar", ids = "com.example:beer-api-producer:+:stubs:8095", stubsMode = StubRunnerProperties.StubsMode.LOCAL)
If you set the stubsMode property to StubRunnerProperties.StubsMode.CLASSPATH
+(or set nothing since CLASSPATH is the default value) then classpath will get scanned.
+Let’s look at the following example:
@AutoConfigureStubRunner(ids = {
"com.example:beer-api-producer:+:stubs:8095",
"com.example.foo:bar:1.0.0:superstubs:8096"
})If you’ve added the dependencies to your classpath
Maven.
@@ -249,10 +247,10 @@ HTTP stubs without the need to download artifacts.
'false'Stubs are defined in JSON documents, whose syntax is defined in WireMock documentation
Example:
{
+ repositoryStubs are defined in JSON documents, whose syntax is defined in WireMock documentation
Example:
{
"request": {
"method": "GET",
"url": "/ping"
@@ -328,6 +326,7 @@ Check their
Map<StubConfiguration, Collection<Contract>> getContracts();
}Example of usage in Spock tests:
@ClassRule @Shared StubRunnerRule rule = new StubRunnerRule()
+ .stubsMode(StubRunnerProperties.StubsMode.REMOTE)
.repoRoot(StubRunnerRuleSpec.getResource("/m2repo/repository").toURI().toString())
.downloadStub("org.springframework.cloud.contract.verifier.stubs", "loanIssuance")
.downloadStub("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")
@@ -459,11 +458,13 @@ its methods as presented below:@AutoConfigureStubRunner.
+ - org.springframework.cloud.contract.verifier.stubs:bootService
+ stubs-mode: remoteInstead of using the properties you can also use the properties inside the @AutoConfigureStubRunner.
Below you can find an example of achieving the same result by setting values on the annotation.
@AutoConfigureStubRunner(
ids = ["org.springframework.cloud.contract.verifier.stubs:loanIssuance",
"org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer",
"org.springframework.cloud.contract.verifier.stubs:bootService"],
+ stubsMode = StubRunnerProperties.StubsMode.REMOTE,
repositoryRoot = "classpath:m2repo/repository/")
Stub Runner Spring registers environment variables in the following manner
for every registered WireMock server. Example for Stub Runner ids
com.example:foo, com.example:bar.
stubrunner.runningstubs.foo.portstubrunner.runningstubs.bar.port
Which you can reference in your code.
Stub Runner can integrate with Spring Cloud.
For real life examples you can check the
The most important feature of Stub Runner Spring Cloud is the fact that it’s stubbing
DiscoveryClientRibbon ServerListthat means that regardless of the fact whether you’re using Zookeeper, Consul, Eureka or anything else, you don’t need that in your tests.
@@ -498,7 +499,7 @@ project you can start Stub Runner Boot by executing spring
or a subdirectory called config or in ~/.spring-cloud. The file could look like this
(example for running stubs installed locally)
stubrunner.yml.
stubrunner:
- workOffline: true
+ stubsMode: LOCAL
ids:
- com.example:beer-api-producer:+:9876
and then just call spring cloud stubrunner from your terminal window to start
@@ -658,6 +659,7 @@ Or set the test as follows:
@SpringBootTest(properties = ["spring.application.name=bar-consumer"]) @AutoConfigureStubRunner(ids = "org.springframework.cloud.contract.verifier.stubs:producerWithMultipleConsumers", repositoryRoot = "classpath:m2repo/repository/", + stubsMode = StubRunnerProperties.StubsMode.REMOTE, stubsPerConsumer = true) @DirtiesContext class StubRunnerStubsPerConsumerSpec extends Specification { @@ -668,6 +670,7 @@ Or set the test as follows:@AutoConfigureStubRunner(ids = "org.springframework.cloud.contract.verifier.stubs:producerWithMultipleConsumers", repositoryRoot = "classpath:m2repo/repository/", consumerName = "foo-consumer", + stubsMode = StubRunnerProperties.StubsMode.REMOTE, stubsPerConsumer = true) @DirtiesContext class StubRunnerStubsPerConsumerWithConsumerNameSpec extends Specification { @@ -675,8 +678,7 @@ Or set the test as follows:foo-consumer in its name (i.e. those from thesrc/test/resources/contracts/foo-consumer/some/contracts/…folder) will be allowed to be referenced.You can check out issue 224 for more information about the reasons behind this change.
This section briefly describes common properties, including:
You can set repetitive properties by using system properties or Spring configuration -properties. Here are their names with their default values:
| Property name | Default value | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stubrunner.minPort | 10000 | Minimum value of a port for a started WireMock with stubs. | ||||||||||||||||||||||||||||||||||||
stubrunner.maxPort | 15000 | Maximum value of a port for a started WireMock with stubs. | ||||||||||||||||||||||||||||||||||||
stubrunner.repositoryRoot | Maven repo URL. If blank, then call the local maven repo. | |||||||||||||||||||||||||||||||||||||
stubrunner.classifier | stubs | Default classifier for the stub artifacts. | ||||||||||||||||||||||||||||||||||||
stubrunner.workOffline | false | If true, then do not contact any remote repositories to -download stubs. | ||||||||||||||||||||||||||||||||||||
stubrunner.ids | Array of Ivy notation stubs to download. | |||||||||||||||||||||||||||||||||||||
stubrunner.username | Optional username to access the tool that stores the JARs with +properties. Here are their names with their default values:
|