generating specs
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package io.codearte.accurest.maven;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
|
||||
import io.codearte.accurest.AccurestException;
|
||||
import io.codearte.accurest.TestGenerator;
|
||||
import io.codearte.accurest.config.AccurestConfigProperties;
|
||||
|
||||
@Mojo(name = "generateSpecs", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES)
|
||||
public class GenerateSpecsMojo extends AbstractMojo {
|
||||
|
||||
@Parameter(defaultValue = "${basedir}")
|
||||
protected File baseDir;
|
||||
|
||||
@Parameter(defaultValue = "${project.build.directory}")
|
||||
protected File projectBuildDirectory;
|
||||
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
AccurestConfigProperties config = new AccurestConfigProperties();
|
||||
|
||||
config.setContractsDslDir(new File(baseDir, "/src/test/resources/stubs"));
|
||||
config.setBasePackageForTests("io.codearte.accurest.tests");
|
||||
config.setGeneratedTestSourcesDir(new File(projectBuildDirectory, "/generated-sources/accurest"));
|
||||
|
||||
getLog().info("Accurest Plugin: Invoking test sources generation");
|
||||
getLog().info(format("Registering %s as test source directory", config.getGeneratedTestSourcesDir()));
|
||||
|
||||
try {
|
||||
TestGenerator generator = new TestGenerator(config);
|
||||
int generatedClasses = generator.generate();
|
||||
getLog().info(String.format("Generated %s test classes.", generatedClasses));
|
||||
} catch (AccurestException e) {
|
||||
throw new MojoExecutionException(format("Accurest Plugin exception: %s", e.getMessage()), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,30 +26,15 @@ public class GenerateStubsMojo extends AbstractMojo {
|
||||
private String mappingsDir = "mappings";
|
||||
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
getLog().info("");
|
||||
getLog().info("*** Accurest Maven Plugin ***");
|
||||
getLog().info("");
|
||||
AccurestConfigProperties config = new AccurestConfigProperties();
|
||||
config.setContractsDslDir(new File(baseDir, "/src/test/resources/stubs"));
|
||||
config.setStubsOutputDir(new File(projectBuildDirectory, mappingsDir));
|
||||
|
||||
File stubsOutputDir = new File(projectBuildDirectory, mappingsDir);
|
||||
|
||||
getLog().info("baseDir = " + baseDir);
|
||||
getLog().info("projectBuildDirectory = " + projectBuildDirectory);
|
||||
getLog().info("mappings = " + mappingsDir);
|
||||
|
||||
AccurestConfigProperties configProperties = new AccurestConfigProperties();
|
||||
|
||||
File contractsDslDir = new File(baseDir, "/src/test/resources/stubs");
|
||||
|
||||
configProperties.setContractsDslDir(contractsDslDir);
|
||||
configProperties.setBasePackageForTests("io.codearte.accurest.tests");
|
||||
configProperties.setStubsOutputDir(stubsOutputDir);
|
||||
getLog().info("Accurest Plugin: Invoking GroovyDSL to WireMock client stubs conversion");
|
||||
getLog().info(String.format("From '%s' to '%s'", contractsDslDir, stubsOutputDir));
|
||||
getLog().info(String.format("From '%s' to '%s'", config.getContractsDslDir(), config.getStubsOutputDir()));
|
||||
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(new DslToWireMockClientConverter(),
|
||||
configProperties);
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(new DslToWireMockClientConverter(), config);
|
||||
converter.processFiles();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,12 +25,19 @@ public class PluginIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
public void shouldCreateStubs() throws Exception {
|
||||
File basedir = resources.getBasedir("basic-with-execution");
|
||||
maven.forProject(basedir)
|
||||
.withCliOption("-X")
|
||||
.execute("package")
|
||||
.assertErrorFreeLog()
|
||||
.assertLogText("Accurest Plugin: Invoking GroovyDSL to WireMock client stubs conversion");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateSpecs() throws Exception {
|
||||
File basedir = resources.getBasedir("basic-with-execution");
|
||||
maven.forProject(basedir)
|
||||
.execute("package")
|
||||
.assertLogText("Accurest Plugin: Invoking test sources generation");
|
||||
}
|
||||
}
|
||||
@@ -19,17 +19,24 @@ public class PluginUnitTest {
|
||||
public final TestMavenRuntime maven = new TestMavenRuntime();
|
||||
|
||||
@Test
|
||||
public void shouldGenerateWarlockStubsInDefaultLocation() throws Exception {
|
||||
public void shouldGenerateWiremockStubsInDefaultcLocation() throws Exception {
|
||||
File basedir = resources.getBasedir("basic");
|
||||
maven.executeMojo(basedir, "generateStubs");
|
||||
assertFilesPresent(basedir, "target/mappings/Sample.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateWarlockStubsInSelectedLocation() throws Exception {
|
||||
public void shouldGenerateWiremockStubsInSelectedLocation() throws Exception {
|
||||
File basedir = resources.getBasedir("basic");
|
||||
maven.executeMojo(basedir, "generateStubs", TestMavenRuntime.newParameter("mappingsDir", "foo"));
|
||||
assertFilesPresent(basedir, "target/foo/Sample.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateContractSpecificationInDefaultLocation() throws Exception {
|
||||
File basedir = resources.getBasedir("basic");
|
||||
maven.executeMojo(basedir, "generateSpecs");
|
||||
assertFilesPresent(basedir,
|
||||
"target/generated-sources/accurest/io/codearte/accurest/tests/AccurestSpec.groovy");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,45 @@
|
||||
<artifactId>sample-project</artifactId>
|
||||
<version>0.1</version>
|
||||
|
||||
<dependencies>
|
||||
<!--TODO: Replace this stuff with import accurest-test dependency-->
|
||||
<dependency>
|
||||
<groupId>org.spockframework</groupId>
|
||||
<artifactId>spock-core</artifactId>
|
||||
<version>1.0-groovy-2.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.restassured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<version>2.9.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jayway.restassured</groupId>
|
||||
<artifactId>spring-mock-mvc</artifactId>
|
||||
<version>2.9.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock</artifactId>
|
||||
<version>2.0.4-beta</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.toomuchcoding.jsonassert</groupId>
|
||||
<artifactId>jsonassert</artifactId>
|
||||
<version>0.2.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -18,10 +57,42 @@
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generateStubs</goal>
|
||||
<goal>generateSpecs</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<testSources>
|
||||
<testSource>
|
||||
<directory>${project.build.directory}/generated-sources/accurest</directory>
|
||||
<includes>
|
||||
<include>**/*.groovy</include>
|
||||
</includes>
|
||||
</testSource>
|
||||
</testSources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Spec.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
Reference in New Issue
Block a user