diff --git a/docs/src/main/asciidoc/verifier/stubrunner.adoc b/docs/src/main/asciidoc/verifier/stubrunner.adoc
index c9534dc3ac..d2b4019f0d 100644
--- a/docs/src/main/asciidoc/verifier/stubrunner.adoc
+++ b/docs/src/main/asciidoc/verifier/stubrunner.adoc
@@ -61,17 +61,17 @@ include::{stubrunner_core_path}/spring-cloud-contract-stub-runner-spring-cloud/R
==== Common properties for JUnit and Spring
-Some of the properties that are repetitive can be set using system properties or property sources (for Spring). Here are their names with their default values:
+Some of the properties that are repetitive can be set using system properties or configuration properties (for Spring). Here are their names with their default values:
[frame="topbot",options="header"]
|======================
| Property name | Default value | Description
-|stubrunner.port.range.min|10000| Minimal value of a port for a started WireMock with stubs
-|stubrunner.port.range.max|15000| Minimal value of a port for a started WireMock with stubs
-|stubrunner.stubs.repository.root|| Comma separated list of Maven repo urls. If blank then will call the local maven repo
+|stubrunner.minPort|10000| Minimal value of a port for a started WireMock with stubs
+|stubrunner.maxPort|15000| Minimal value of a port for a started WireMock with stubs
+|stubrunner.stubs.repositoryRoot|| Maven repo url. If blank then will call the local maven repo
|stubrunner.stubs.classifier|stubs| Default classifier for the stub artifacts
-|stubrunner.work-offline|false| If true then will not contact any remote repositories to download stubs
-|stubrunner.stubs.ids|| Comma separated list of Ivy notation of stubs to download
+|stubrunner.workOffline|false| If true then will not contact any remote repositories to download stubs
+|stubrunner.stubs.ids|| Array of Ivy notation stubs to download
|======================
===== Stub runner stubs ids
diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-camel/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-camel/src/test/resources/application.yml
index db021bb201..4eef5ea578 100644
--- a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-camel/src/test/resources/application.yml
+++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-camel/src/test/resources/application.yml
@@ -1,2 +1,2 @@
-stubrunner.stubs.repository.root: classpath:m2repo/repository/
+stubrunner.stubs.repositoryRoot: classpath:m2repo/repository/
stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:camelService
\ No newline at end of file
diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-integration/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-integration/src/test/resources/application.yml
index 911b24bbaa..32d7427875 100644
--- a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-integration/src/test/resources/application.yml
+++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-integration/src/test/resources/application.yml
@@ -1,2 +1,2 @@
-stubrunner.stubs.repository.root: classpath:m2repo/repository/
+stubrunner.stubs.repositoryRoot: classpath:m2repo/repository/
stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:integrationService:0.0.1-SNAPSHOT
\ No newline at end of file
diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-stream/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-stream/src/test/resources/application.yml
index f7c3f12f4a..baaaa1d38e 100644
--- a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-stream/src/test/resources/application.yml
+++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner-stream/src/test/resources/application.yml
@@ -1,4 +1,4 @@
-stubrunner.stubs.repository.root: classpath:m2repo/repository/
+stubrunner.stubs.repositoryRoot: classpath:m2repo/repository/
stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:streamService:0.0.1-SNAPSHOT:stubs
spring:
diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/pom.xml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/pom.xml
index 4bb8982043..8440fe0cf5 100644
--- a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/pom.xml
+++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/pom.xml
@@ -40,6 +40,11 @@
org.springframework.cloud
spring-cloud-contract-spec
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
org.springframework
spring-core
diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.java
index 6c3c6b0535..6e2091e265 100644
--- a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.java
+++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptionsBuilder.java
@@ -16,7 +16,7 @@
package org.springframework.cloud.contract.stubrunner;
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import org.springframework.cloud.contract.stubrunner.util.StubsParser;
+import org.springframework.util.StringUtils;
public class StubRunnerOptionsBuilder {
@@ -44,7 +45,7 @@ public class StubRunnerOptionsBuilder {
withOptions(options);
}
- public StubRunnerOptionsBuilder withStubs(String stubs) {
+ public StubRunnerOptionsBuilder withStubs(String... stubs) {
addStub(stubsToList(stubs));
return this;
}
@@ -112,8 +113,12 @@ public class StubRunnerOptionsBuilder {
return StubsParser.fromString(stubs, stubsClassifier);
}
- private static List stubsToList(String stubIdsToPortMapping) {
- return Arrays.asList(stubIdsToPortMapping.split(","));
+ private static List stubsToList(String[] stubIdsToPortMapping) {
+ List list = new ArrayList<>();
+ for (String stub : stubIdsToPortMapping) {
+ list.addAll(StringUtils.commaDelimitedListToSet(stub));
+ }
+ return list;
}
private void addStub(List notations) {
diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java
index 3a9e2d040c..aeed18a969 100644
--- a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java
+++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerConfiguration.java
@@ -19,8 +19,8 @@ package org.springframework.cloud.contract.stubrunner.spring;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.contract.stubrunner.AetherStubDownloader;
import org.springframework.cloud.contract.stubrunner.BatchStubRunner;
import org.springframework.cloud.contract.stubrunner.BatchStubRunnerFactory;
@@ -35,45 +35,49 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
/**
- * Configuration that initializes a {@link BatchStubRunner} that runs {@link StubRunner} instance for each stub
+ * Configuration that initializes a {@link BatchStubRunner} that runs {@link StubRunner}
+ * instance for each stub
*/
@Configuration
-@ConditionalOnMissingBean(type="org.springframework.cloud.contract.wiremock.WiremockServerConfiguration")
+@EnableConfigurationProperties(StubRunnerProperties.class)
+@ConditionalOnMissingBean(type = "org.springframework.cloud.contract.wiremock.WiremockServerConfiguration")
public class StubRunnerConfiguration {
- @Autowired(required = false) ContractVerifierMessaging,?> contractVerifierMessaging;
- @Autowired(required = false) StubDownloader stubDownloader;
+ @Autowired(required = false)
+ private ContractVerifierMessaging, ?> contractVerifierMessaging;
+ @Autowired(required = false)
+ private StubDownloader stubDownloader;
+ @Autowired
+ private StubRunnerProperties props;
/**
- * Bean that initializes stub runners, runs them and on shutdown closes them. Upon its instantiation
- * JAR with stubs is downloaded and unpacked to a temporary folder and WireMock server are started
- * for each of those stubs
+ * Bean that initializes stub runners, runs them and on shutdown closes them. Upon its
+ * instantiation JAR with stubs is downloaded and unpacked to a temporary folder and
+ * WireMock server are started for each of those stubs
*
- * @param minPortValue min port value of the WireMock instance for stubs
- * @param maxPortValue max port value of the WireMock instance for stubs
- * @param stubRepositoryRoot root URL from where the JAR with stub mappings will be downloaded
- * @param stubsSuffix classifier for the jar containing stubs
- * @param workOffline forces offline work
- * @param stubs comma separated list of stubs presented in Ivy notation
+ * @param minPortValue min port value of the WireMock instance for stubs
+ * @param maxPortValue max port value of the WireMock instance for stubs
+ * @param stubRepositoryRoot root URL from where the JAR with stub mappings will be
+ * downloaded
+ * @param stubsSuffix classifier for the jar containing stubs
+ * @param workOffline forces offline work
+ * @param stubs comma separated list of stubs presented in Ivy notation
*/
@Bean
- public BatchStubRunner batchStubRunner(
- @Value("${stubrunner.port.range.min:10000}") Integer minPortValue,
- @Value("${stubrunner.port.range.max:15000}") Integer maxPortValue,
- @Value("${stubrunner.stubs.repository.root:}") Resource stubRepositoryRoot,
- @Value("${stubrunner.stubs.classifier:stubs}") String stubsSuffix,
- @Value("${stubrunner.work-offline:false}") boolean workOffline,
- @Value("${stubrunner.stubs.ids:}") String stubs) throws IOException {
+ public BatchStubRunner batchStubRunner() throws IOException {
StubRunnerOptions stubRunnerOptions = new StubRunnerOptionsBuilder()
- .withMinMaxPort(minPortValue, maxPortValue)
- .withStubRepositoryRoot(uriStringOrEmpty(stubRepositoryRoot))
- .withWorkOffline(stubRepositoryRoot == null || workOffline)
- .withStubsClassifier(stubsSuffix)
- .withStubs(stubs)
- .build();
+ .withMinMaxPort(props.getMinPort(), props.getMaxPort())
+ .withStubRepositoryRoot(
+ uriStringOrEmpty(props.getStubs().getRepositoryRoot()))
+ .withWorkOffline(props.getStubs().getRepositoryRoot() == null
+ || props.isWorkOffline())
+ .withStubsClassifier(props.getStubs().getClassifier())
+ .withStubs(props.getStubs().getIds()).build();
BatchStubRunner batchStubRunner = new BatchStubRunnerFactory(stubRunnerOptions,
- stubDownloader != null ? stubDownloader : new AetherStubDownloader(stubRunnerOptions),
- contractVerifierMessaging != null ? contractVerifierMessaging : new NoOpContractVerifierMessaging()).buildBatchStubRunner();
+ stubDownloader != null ? stubDownloader
+ : new AetherStubDownloader(stubRunnerOptions),
+ contractVerifierMessaging != null ? contractVerifierMessaging
+ : new NoOpContractVerifierMessaging()).buildBatchStubRunner();
// TODO: Consider running it in a separate thread
batchStubRunner.runStubs();
return batchStubRunner;
diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerProperties.java b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerProperties.java
new file mode 100644
index 0000000000..de038d0d45
--- /dev/null
+++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/spring/StubRunnerProperties.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2012-2015 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.cloud.contract.stubrunner.spring;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.core.io.Resource;
+
+/**
+ * @author Dave Syer
+ *
+ */
+@ConfigurationProperties("stubrunner")
+public class StubRunnerProperties {
+
+ /**
+ *
+ */
+ private int minPort = 10000;
+
+ /**
+ *
+ */
+ private int maxPort = 15000;
+
+ /**
+ *
+ */
+ private boolean workOffline;
+
+ private Stubs stubs = new Stubs();
+
+ public int getMinPort() {
+ return minPort;
+ }
+
+ public void setMinPort(int minPort) {
+ this.minPort = minPort;
+ }
+
+ public int getMaxPort() {
+ return maxPort;
+ }
+
+ public void setMaxPort(int maxPort) {
+ this.maxPort = maxPort;
+ }
+
+ public boolean isWorkOffline() {
+ return workOffline;
+ }
+
+ public void setWorkOffline(boolean workOffline) {
+ this.workOffline = workOffline;
+ }
+
+ public Stubs getStubs() {
+ return stubs;
+ }
+
+ public void setStubs(Stubs stubs) {
+ this.stubs = stubs;
+ }
+
+ public static class Stubs {
+ /**
+ * The repository root to use (defaults to local Maven repo).
+ */
+ private Resource repositoryRoot;
+ /**
+ * The ids of the stubs to run in "ivy" notation (groupId:artifactId[:classifier]:version[:port]).
+ */
+ private String[] ids = new String[0];
+ /**
+ * The classifier to use by default in ivy co-ordinates for a stub.
+ */
+ private String classifier = "stubs";
+
+ public Resource getRepositoryRoot() {
+ return repositoryRoot;
+ }
+
+ public void setRepositoryRoot(Resource repositoryRoot) {
+ this.repositoryRoot = repositoryRoot;
+ }
+
+ public String[] getIds() {
+ return ids;
+ }
+
+ public void setIds(String[] ids) {
+ this.ids = ids;
+ }
+
+ public String getClassifier() {
+ return classifier;
+ }
+
+ public void setClassifier(String classifier) {
+ this.classifier = classifier;
+ }
+ }
+
+}
diff --git a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/application.yml b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/application.yml
index a1a2c866bf..8d88487059 100644
--- a/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/application.yml
+++ b/spring-cloud-contract-stub-runner/spring-cloud-contract-stub-runner/src/test/resources/application.yml
@@ -1,5 +1,8 @@
-stubrunner.stubs.repository.root: classpath:m2repo/repository/
-stubrunner.stubs.ids: org.springframework.cloud.contract.verifier.stubs:loanIssuance,org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer,org.springframework.cloud.contract.verifier.stubs:bootService
+stubrunner.stubs.repositoryRoot: classpath:m2repo/repository/
+stubrunner.stubs.ids:
+ - org.springframework.cloud.contract.verifier.stubs:loanIssuance
+ - org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer
+ - org.springframework.cloud.contract.verifier.stubs:bootService
stubrunner.stubs.idsToServiceIds:
ivyNotation: someValueInsideYourCode