configurable contracts directory

This commit is contained in:
Mariusz Smykula
2016-03-27 07:38:11 +02:00
parent 0c69a9dd2f
commit 60bc33b157
5 changed files with 52 additions and 2 deletions

View File

@@ -24,10 +24,13 @@ public class GenerateSpecsMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.build.directory}")
protected File projectBuildDirectory;
@Parameter(property = "contractsDir", defaultValue = "/src/test/resources/stubs", required = false)
private String contractsDir = "/src/test/resources/stubs";
public void execute() throws MojoExecutionException, MojoFailureException {
AccurestConfigProperties config = new AccurestConfigProperties();
config.setContractsDslDir(new File(baseDir, "/src/test/resources/stubs"));
config.setContractsDslDir(new File(baseDir, contractsDir));
config.setBasePackageForTests("io.codearte.accurest.tests");
config.setGeneratedTestSourcesDir(new File(projectBuildDirectory, "/generated-sources/accurest"));

View File

@@ -25,9 +25,12 @@ public class GenerateStubsMojo extends AbstractMojo {
@Parameter(property = "mappingsDir", defaultValue = "mappings", required = false)
private String mappingsDir = "mappings";
@Parameter(property = "contractsDir", defaultValue = "/src/test/resources/stubs", required = false)
private String contractsDir = "/src/test/resources/stubs";
public void execute() throws MojoExecutionException, MojoFailureException {
AccurestConfigProperties config = new AccurestConfigProperties();
config.setContractsDslDir(new File(baseDir, "/src/test/resources/stubs"));
config.setContractsDslDir(new File(baseDir, contractsDir));
config.setStubsOutputDir(new File(projectBuildDirectory, mappingsDir));
getLog().info("Accurest Plugin: Invoking GroovyDSL to WireMock client stubs conversion");

View File

@@ -32,6 +32,13 @@ public class PluginUnitTest {
assertFilesPresent(basedir, "target/foo/Sample.json");
}
@Test
public void shouldGenerateWiremockStubsInSelectedLocation2() throws Exception {
File basedir = resources.getBasedir("customContractsLocation");
maven.executeMojo(basedir, "generateStubs", TestMavenRuntime.newParameter("contractsDir", "src/foo"));
assertFilesPresent(basedir, "target/mappings/Sample.json");
}
@Test
public void shouldGenerateContractSpecificationInDefaultLocation() throws Exception {
File basedir = resources.getBasedir("basic");

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.codearte.accurest.sample</groupId>
<artifactId>sample-project</artifactId>
<version>0.1</version>
<build>
<plugins>
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,18 @@
io.codearte.accurest.dsl.GroovyDsl.make {
request {
method 'POST'
url('/users') {
}
headers {
header 'Content-Type': 'application/json'
}
body '''{ "login" : "john", "name": "John The Contract" }'''
}
response {
status 200
headers {
header 'Location': '/users/john'
}
}
}