diff --git a/multi/multi__spring_cloud_contract_stub_runner.html b/multi/multi__spring_cloud_contract_stub_runner.html index 544f1c4c61..9cbf282af8 100644 --- a/multi/multi__spring_cloud_contract_stub_runner.html +++ b/multi/multi__spring_cloud_contract_stub_runner.html @@ -218,7 +218,35 @@ structure in your stubs jar.
└──
│ └── contract2.groovy
└── mappings
└── mapping.jsonBy maintaining this structure classpath gets scanned and you can profit from the messaging / -HTTP stubs without the need to download artifacts.
You can set the following options to the main class:
-c, --classifier Suffix for the jar containing stubs (e.
+HTTP stubs without the need to download artifacts.Stub Runner has a notion of a HttpServerStub that abstracts the underlaying
+concrete implementation of the HTTP server (e.g. WireMock is one of the implementations).
+Sometimes, you need to perform some additional tuning of the stub servers,
+that is concrete for the given implementation. To do that, Stub Runner gives you
+the httpServerStubConfigurer property that is available in the annotation,
+JUnit rule, and is accessible via system properties, where you can provide
+your implementation of the org.springframework.cloud.contract.stubrunner.HttpServerStubConfigurer interface. The implementations can alter
+the configuration files for the given HTTP server stub.
Spring Cloud Contract Stub Runner comes with an implementation that you
+can extend, for WireMock - org.springframework.cloud.contract.stubrunner.provider.wiremock.WireMockHttpServerStubConfigurer. In the configure method
+you can provide your own, custom configuration for the given stub. The use
+case might be starting WireMock for the given artifact id, on an HTTPs port. Example:
WireMockHttpServerStubConfigurer implementation. +
@CompileStatic +static class HttpsForFraudDetection extends WireMockHttpServerStubConfigurer { + + private static final Log log = LogFactory.getLog(HttpsForFraudDetection) + + @Override + WireMockConfiguration configure(WireMockConfiguration httpStubConfiguration, HttpServerStubConfiguration httpServerStubConfiguration) { + if (httpServerStubConfiguration.stubConfiguration.artifactId == "fraudDetectionServer") { + int httpsPort = SocketUtils.findAvailableTcpPort() + log.info("Will set HTTPs port [" + httpsPort + "] for fraud detection server") + return httpStubConfiguration + .httpsPort(httpsPort) + } + return httpStubConfiguration + } +}
+
You can then reuse it via the annotation
@AutoConfigureStubRunner(mappingsOutputFolder = "target/outputmappings/",
+ httpServerStubConfigurer = HttpsForFraudDetection)Whenever an https port is found, it will take precedence over the http one.
You can set the following options to the main class:
-c, --classifier Suffix for the jar containing stubs (e. g. 'stubs' if the stub jar would have a 'stubs' classifier for stubs: foobar-stubs ). Defaults to 'stubs' @@ -401,7 +429,8 @@ its methods as presented below:@SpringBootTest(properties = [" stubrunner.cloud.enabled=false", 'foo=${stubrunner.runningstubs.fraudDetectionServer.port}', 'fooWithGroup=${stubrunner.runningstubs.org.springframework.cloud.contract.verifier.stubs.fraudDetectionServer.port}']) -@AutoConfigureStubRunner(mappingsOutputFolder = "target/outputmappings/") +@AutoConfigureStubRunner(mappingsOutputFolder = "target/outputmappings/", + httpServerStubConfigurer = HttpsForFraudDetection) @ActiveProfiles("test") class StubRunnerConfigurationSpec extends Specification { @@ -433,6 +462,8 @@ its methods as presented below:'Stubs were registered' "${stubFinder.findStubUrl('loanIssuance').toString()}/name".toURL().text == 'loanIssuance' "${stubFinder.findStubUrl('fraudDetectionServer').toString()}/name".toURL().text == 'fraudDetectionServer' + and: 'Fraud Detection is an HTTPS endpoint' + stubFinder.findStubUrl('fraudDetectionServer').toString().startsWith("https") } def 'should throw an exception when stub is not found'() { @@ -488,6 +519,23 @@ its methods as presented below:@Configuration @EnableAutoConfiguration static class Config {} + + @CompileStatic + static class HttpsForFraudDetection extends WireMockHttpServerStubConfigurer { + + private static final Log log = LogFactory.getLog(HttpsForFraudDetection) + + @Override + WireMockConfiguration configure(WireMockConfiguration httpStubConfiguration, HttpServerStubConfiguration httpServerStubConfiguration) { + if (httpServerStubConfiguration.stubConfiguration.artifactId == "fraudDetectionServer") { + int httpsPort = SocketUtils.findAvailableTcpPort() + log.info("Will set HTTPs port [" + httpsPort + "] for fraud detection server") + return httpStubConfiguration + .httpsPort(httpsPort) + } + return httpStubConfiguration + } + } } // end::test[]for the following configuration file:
stubrunner: repositoryRoot: classpath:m2repo/repository/ diff --git a/multi/multi__using_the_pluggable_architecture.html b/multi/multi__using_the_pluggable_architecture.html index 1f3b477dd6..9818229d57 100644 --- a/multi/multi__using_the_pluggable_architecture.html +++ b/multi/multi__using_the_pluggable_architecture.html @@ -440,10 +440,10 @@ to clone the repository and use it as a source of contracts to generate tests or stubs.Either via environment variables, system properties, properties set inside the plugin or contracts repository configuration you can tweak the downloader’s behaviour. Below you can find the list of -properties
Table 10.1. SCM Stub Downloader properties
Type of a property
Name of the property
Description
*
git.branch(plugin prop)*
stubrunner.properties.git.branch(system prop)*
STUBRUNNER_PROPERTIES_GIT_BRANCH(env prop)master
Which branch to checkout
*
git.username(plugin prop)*
stubrunner.properties.git.username(system prop)*
STUBRUNNER_PROPERTIES_GIT_USERNAME(env prop)Git clone username
*
git.password(plugin prop)*
stubrunner.properties.git.password(system prop)*
STUBRUNNER_PROPERTIES_GIT_PASSWORD(env prop)Git clone password
*
git.no-of-attempts(plugin prop)*
stubrunner.properties.git.no-of-attempts(system prop)*
STUBRUNNER_PROPERTIES_GIT_NO_OF_ATTEMPTS(env prop)10
Number of attempts to push the commits to
origin*
git.wait-between-attempts(Plugin prop)*
stubrunner.properties.git.wait-between-attempts(system prop)*
STUBRUNNER_PROPERTIES_GIT_WAIT_BETWEEN_ATTEMPTS(env prop)1000
Number of millis to wait between attempts to push the commits to
origin
Whenever the repositoryRoot starts with a Pact protocol
+properties
Table 10.1. SCM Stub Downloader properties
Type of a property | Name of the property | Description |
* * * | master | Which branch to checkout |
* * * | Git clone username | |
* * * | Git clone password | |
* * * | 10 | Number of attempts to push the commits to |
* * * | 1000 | Number of millis to wait between attempts to push the commits to |
Whenever the repositoryRoot starts with a Pact protocol
(starts with pact://), the stub downloader will try
to fetch the Pact contract definitions from the Pact Broker.
Whatever is set after pact:// will be parsed as the Pact Broker URL.
Either via environment variables, system properties, properties set inside the plugin or contracts repository configuration you can tweak the downloader’s behaviour. Below you can find the list of -properties
Table 10.2. SCM Stub Downloader properties
Name of a property | Default | Description |
* * * | Host from URL passed to | What is the URL of Pact Broker |
* * * | Port from URL passed to | What is the port of Pact Broker |
* * * | Protocol from URL passed to | What is the protocol of Pact Broker |
* * * | Version of the stub, or | What tags should be used to fetch the stub |
* * * |
| What kind of authentication should be used to connect to the Pact Broker |
* * * | The username passed to | Username used to connect to the Pact Broker |
* * * | The password passed to | Password used to connect to the Pact Broker |
* * * | false | When |