Merge branch 'master' into 2.0.x

This commit is contained in:
Marcin Grzejszczak
2017-08-28 15:01:46 +02:00
5 changed files with 62 additions and 5 deletions

View File

@@ -54,7 +54,7 @@ public class RunMojo extends AbstractMojo {
private File destination;
/**
* HTTP port for WireMock server
* HTTP port for the WireMock server that serves stubs
*/
@Parameter(property = "spring.cloud.contract.verifier.http.port", defaultValue = "8080")
private int httpPort;
@@ -71,15 +71,30 @@ public class RunMojo extends AbstractMojo {
@Parameter(property = "spring.cloud.contract.verifier.skipTestOnly", defaultValue = "false")
private boolean skipTestOnly;
/**
* List of stubs to be downloaded and ran in a colon separated Ivy notation
*/
@Parameter(property = "spring.cloud.contract.verifier.stubs")
private String stubs;
/**
* Minimal port at which the stub should start
*/
@Parameter(property = "spring.cloud.contract.verifier.http.minPort", defaultValue = "10000")
private int minPort;
/**
* Maximal port at which the stub should start
*/
@Parameter(property = "spring.cloud.contract.verifier.http.maxPort", defaultValue = "15000")
private int maxPort;
/**
* Should the plugin wait for the user to press the key after starting the stubs
*/
@Parameter(property = "spring.cloud.contract.verifier.wait-for-key-pressed", defaultValue = "true")
private boolean waitForKeyPressed;
/**
* Classifier used by stubs artifacts.
*/
@@ -109,7 +124,7 @@ public class RunMojo extends AbstractMojo {
.withStubsClassifier(this.stubsClassifier);
if (isNullOrEmpty(this.stubs)) {
StubRunnerOptions options = optionsBuilder
.withPort(this.httpPort)
.withMinMaxPort(this.httpPort, this.httpPort)
.build();
StubRunner stubRunner = this.localStubRunner.run(resolveStubsDirectory().getAbsolutePath(), options);
batchStubRunner = new BatchStubRunner(Collections.singleton(stubRunner));
@@ -139,6 +154,9 @@ public class RunMojo extends AbstractMojo {
}
private void pressAnyKeyToContinue() {
if (!this.waitForKeyPressed) {
return;
}
getLog().info("Press ENTER to continue...");
try {
System.in.read();

View File

@@ -2,9 +2,9 @@
== Converting Spring Cloud Contract DSL into WireMock stub mappings
mvn org.springramework.cloud:spring-cloud-contract-maven-plugin:convert
mvn org.springframework.cloud:spring-cloud-contract-maven-plugin:convert
or shortly footnoteref:[prefix,Additional configuration inside `~/.m2/settings.xml` is required: `<pluginGroups><pluginGroup> org.springramework.cloud:spring-cloud-contract-maven-plugin</pluginGroup></pluginGroups>`.]
or shortly footnoteref:[prefix,Additional configuration inside `~/.m2/settings.xml` is required: `<pluginGroups><pluginGroup> org.springframework.cloud:spring-cloud-contract-maven-plugin</pluginGroup></pluginGroups>`.]
mvn spring-cloud-contract-verifier:convert
@@ -14,7 +14,7 @@ For more information please go to the Spring Cloud Contract Wiki or Plugin Docum
Run stubs mappings from current directory:
mvn org.springramework.cloud:spring-cloud-contract-maven-plugin:run
mvn org.springframework.cloud:spring-cloud-contract-maven-plugin:run
or shortly footnoteref:[prefix]

View File

@@ -29,6 +29,7 @@ import io.takari.maven.testing.TestResources;
import io.takari.maven.testing.executor.MavenRuntime;
import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
import org.springframework.util.SocketUtils;
@RunWith(MavenJUnitTestRunner.class)
@MavenVersions({ "3.3.3" })
@@ -108,4 +109,19 @@ public class PluginIT {
.assertLogText("Creating new stub")
.assertErrorFreeLog();
}
@Test
public void should_run_WireMock_Stubs_mappings() throws Exception {
int availableTcpPort = SocketUtils.findAvailableTcpPort();
File basedir = this.resources.getBasedir("generatedStubsOnly");
this.properties.getPluginVersion();
this.maven.forProject(basedir)
.withCliOption("-X")
.withCliOption("-Dspring.cloud.contract.verifier.http.port=" + availableTcpPort)
.withCliOption("-Dspring.cloud.contract.verifier.wait-for-key-pressed=false")
.execute(String.format("org.springframework.cloud:spring-cloud-contract-maven-plugin:%s:run",
this.properties.getPluginVersion()))
.assertLogText("All stubs are now running RunningStubs [namesAndPorts={=" + availableTcpPort + "}]")
.assertErrorFreeLog();
}
}

View File

@@ -0,0 +1,22 @@
{
"request" : {
"url" : "/users",
"method" : "POST",
"bodyPatterns" : [ {
"matchesJsonPath" : "$[?(@.login == 'john')]"
}, {
"matchesJsonPath" : "$[?(@.name == 'John The Contract')]"
} ],
"headers" : {
"Content-Type" : {
"equalTo" : "application/json"
}
}
},
"response" : {
"status" : 200,
"headers" : {
"Location" : "/users/john"
}
}
}