diff --git a/pom.xml b/pom.xml
index 046e683a45..f03f8bada9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,7 @@
UTF-8
UTF-8
- 1.1.0-M3
+ 1.1.0-M4
1.1.0
@@ -388,6 +388,11 @@
4.12
test
+
+ org.assertj
+ assertj-core
+ 2.4.0
+
diff --git a/src/main/groovy/io/codearte/accurest/maven/EnhancedStubRunnerOptions.groovy b/src/main/groovy/io/codearte/accurest/maven/EnhancedStubRunnerOptions.groovy
new file mode 100644
index 0000000000..98acc8be3d
--- /dev/null
+++ b/src/main/groovy/io/codearte/accurest/maven/EnhancedStubRunnerOptions.groovy
@@ -0,0 +1,30 @@
+package io.codearte.accurest.maven
+
+import groovy.transform.CompileStatic
+import io.codearte.accurest.stubrunner.StubConfiguration
+import io.codearte.accurest.stubrunner.StubRunnerOptions
+
+@CompileStatic
+public class EnhancedStubRunnerOptions {
+
+ @Delegate private final StubRunnerOptions options
+ private final Collection dependencies
+
+ EnhancedStubRunnerOptions(Collection dependencies, StubRunnerOptions options) {
+ this.options = options
+ this.dependencies = dependencies
+ }
+
+ EnhancedStubRunnerOptions(Integer minPortValue, Integer maxPortValue, String stubRepositoryRoot, boolean workOffline, String stubsClassifier, Collection dependencies, StubRunnerOptions options) {
+ this.options = new StubRunnerOptions(minPortValue, maxPortValue, stubRepositoryRoot, workOffline, stubsClassifier)
+ this.dependencies = dependencies
+ }
+
+ Collection getDependencies() {
+ return dependencies
+ }
+
+ StubRunnerOptions getStubsRunnerOptions() {
+ return options
+ }
+}
diff --git a/src/main/groovy/io/codearte/accurest/maven/EnhancedStubRunnerOptionsBuilder.groovy b/src/main/groovy/io/codearte/accurest/maven/EnhancedStubRunnerOptionsBuilder.groovy
new file mode 100644
index 0000000000..cd68d42ec4
--- /dev/null
+++ b/src/main/groovy/io/codearte/accurest/maven/EnhancedStubRunnerOptionsBuilder.groovy
@@ -0,0 +1,59 @@
+package io.codearte.accurest.maven
+
+import groovy.transform.CompileStatic
+import io.codearte.accurest.stubrunner.StubConfiguration
+import io.codearte.accurest.stubrunner.StubRunnerOptions
+import io.codearte.accurest.stubrunner.util.StubsParser
+
+@CompileStatic
+public class EnhancedStubRunnerOptionsBuilder {
+
+ private LinkedList stubs = new LinkedList<>()
+
+ private final StubRunnerOptions options;
+
+ EnhancedStubRunnerOptionsBuilder(StubRunnerOptions options) {
+ this.options = options
+ }
+
+ EnhancedStubRunnerOptionsBuilder(Integer minPortValue, Integer maxPortValue, String stubRepositoryRoot,
+ boolean workOffline, String stubsClassifier) {
+ this.options = new StubRunnerOptions(minPortValue, maxPortValue, stubRepositoryRoot, workOffline, stubsClassifier)
+ }
+
+ EnhancedStubRunnerOptionsBuilder withStubs(String stubs) {
+ addStub(stubsToList(stubs))
+ return this
+ }
+
+ private Collection buildDependencies() {
+ return StubsParser.fromString(stubs, options.getStubsClassifier());
+ }
+
+ private static List stubsToList(String stubIdsToPortMapping) {
+ return stubIdsToPortMapping.split(',').collect { it }
+ }
+
+ private void addStub(List notations) {
+ for (String notation : notations) {
+ addStub(notation);
+ }
+ }
+
+ private void addStub(String notation) {
+ if (StubsParser.hasPort(notation)) {
+ addPort(notation);
+ stubs.add(StubsParser.ivyFromStringWithPort(notation));
+ } else {
+ stubs.add(notation);
+ }
+ }
+
+ private void addPort(String notation) {
+ options.putStubIdsToPortMapping(StubsParser.fromStringWithPort(notation));
+ }
+
+ EnhancedStubRunnerOptions build() {
+ return new EnhancedStubRunnerOptions(buildDependencies(), options)
+ }
+}
diff --git a/src/main/groovy/io/codearte/accurest/maven/RunMojo.groovy b/src/main/groovy/io/codearte/accurest/maven/RunMojo.groovy
index 81a870abc0..74c6b23ccd 100644
--- a/src/main/groovy/io/codearte/accurest/maven/RunMojo.groovy
+++ b/src/main/groovy/io/codearte/accurest/maven/RunMojo.groovy
@@ -71,8 +71,10 @@ class RunMojo extends AbstractMojo {
StubRunner stubRunner = localStubRunner.run(resolveStubsDirectory().absolutePath, options)
batchStubRunner = new BatchStubRunner(Arrays.asList(stubRunner))
} else {
- StubRunnerOptions options = new StubRunnerOptions(minPort, maxPort, "", false, stubsClassifier)
- batchStubRunner = remoteStubRunner.run(stubs, options, repoSession)
+ EnhancedStubRunnerOptions options = new EnhancedStubRunnerOptionsBuilder(minPort, maxPort, "", false, stubsClassifier)
+ .withStubs(stubs)
+ .build()
+ batchStubRunner = remoteStubRunner.run(options, repoSession)
}
if (!insideProject) {
diff --git a/src/main/groovy/io/codearte/accurest/maven/stubrunner/RemoteStubRunner.groovy b/src/main/groovy/io/codearte/accurest/maven/stubrunner/RemoteStubRunner.groovy
index 0de360b01b..de1831bfa3 100644
--- a/src/main/groovy/io/codearte/accurest/maven/stubrunner/RemoteStubRunner.groovy
+++ b/src/main/groovy/io/codearte/accurest/maven/stubrunner/RemoteStubRunner.groovy
@@ -2,8 +2,11 @@ package io.codearte.accurest.maven.stubrunner
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
-import io.codearte.accurest.stubrunner.*
-import io.codearte.accurest.stubrunner.util.StubsParser
+import io.codearte.accurest.maven.EnhancedStubRunnerOptions
+import io.codearte.accurest.stubrunner.AetherStubDownloader
+import io.codearte.accurest.stubrunner.BatchStubRunner
+import io.codearte.accurest.stubrunner.BatchStubRunnerFactory
+import io.codearte.accurest.stubrunner.RunningStubs
import org.eclipse.aether.RepositorySystemSession
import javax.inject.Inject
@@ -21,12 +24,11 @@ class RemoteStubRunner {
this.aetherStubDownloaderFactory = aetherStubDownloaderFactory
}
- BatchStubRunner run(String stubs, StubRunnerOptions options, RepositorySystemSession repositorySystemSession) {
+ BatchStubRunner run(EnhancedStubRunnerOptions options, RepositorySystemSession repositorySystemSession) {
AetherStubDownloader stubDownloader = aetherStubDownloaderFactory.build(repositorySystemSession)
try {
log.debug("Launching StubRunner with args: $options")
- Collection collaborators = StubsParser.fromString(stubs, options.stubsClassifier)
- BatchStubRunner stubRunner = new BatchStubRunnerFactory(options, collaborators, stubDownloader)
+ BatchStubRunner stubRunner = new BatchStubRunnerFactory(options.getStubsRunnerOptions(), options.getDependencies(), stubDownloader)
.buildBatchStubRunner()
RunningStubs runningCollaborators = stubRunner.runStubs()
log.info(runningCollaborators.toString())
diff --git a/src/test/java/io/codearte/accurest/maven/EnhancedStubRunnerOptionsTest.java b/src/test/java/io/codearte/accurest/maven/EnhancedStubRunnerOptionsTest.java
new file mode 100644
index 0000000000..0e700200c6
--- /dev/null
+++ b/src/test/java/io/codearte/accurest/maven/EnhancedStubRunnerOptionsTest.java
@@ -0,0 +1,72 @@
+package io.codearte.accurest.maven;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+import io.codearte.accurest.stubrunner.StubRunnerOptions;
+
+public class EnhancedStubRunnerOptionsTest {
+
+ private EnhancedStubRunnerOptionsBuilder builder = new EnhancedStubRunnerOptionsBuilder(new StubRunnerOptions());
+
+ @Test
+ public void shouldAddStubCoordinatesWithPort() throws Exception {
+
+ //given
+ builder.withStubs("foo:bar:8080");
+
+ //when
+ EnhancedStubRunnerOptions options = builder.build();
+
+ //then
+ assertThat(options.getDependencies())
+ .hasToString("[foo:bar:+:stubs]");
+ assertThat(options.getStubIdsToPortMapping())
+ .hasToString("{foo:bar:+:stubs=8080}");
+ }
+
+ @Test
+ public void shouldAddStubCoordinatesWithoutPort() throws Exception {
+
+ //given
+ builder.withStubs("foo:bar");
+
+ //when
+ EnhancedStubRunnerOptions options = builder.build();
+
+ //then
+ assertThat(options.getDependencies())
+ .hasToString("[foo:bar:+:stubs]");
+ assertThat(options.getStubIdsToPortMapping())
+ .hasSize(0);
+ }
+
+ @Test
+ public void shouldAddMultipleStubCoordinates() throws Exception {
+
+ //given
+ builder.withStubs("foo:bar,bar:foo");
+
+ //when
+ EnhancedStubRunnerOptions options = builder.build();
+
+ //then
+ assertThat(options.getDependencies())
+ .hasSize(2);
+ }
+
+ @Test
+ public void shouldAddStubCoordinatesWithVersion() throws Exception {
+
+ //given
+ builder.withStubs("foo:1.2.3:bar");
+
+ //when
+ EnhancedStubRunnerOptions options = builder.build();
+
+ //then
+ assertThat(options.getDependencies())
+ .hasToString("[foo:1.2.3:bar:stubs]");
+ }
+}
\ No newline at end of file