revert two goals to generate tests

This commit is contained in:
Mariusz Smykula
2016-04-02 21:32:41 +02:00
parent 623ae5bd34
commit 2bc9fea276
7 changed files with 64 additions and 89 deletions

View File

@@ -19,7 +19,7 @@ Sample usage
<execution>
<goals>
<goal>generateStubs</goal>
<goal>generateSpecs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>

View File

@@ -1,62 +0,0 @@
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.plugins.annotations.Parameter;
import io.codearte.accurest.AccurestException;
import io.codearte.accurest.TestGenerator;
import io.codearte.accurest.config.AccurestConfigProperties;
import io.codearte.accurest.config.TestFramework;
import io.codearte.accurest.config.TestMode;
public abstract class AbstractGenerateVerificationCodeMojo extends AbstractMojo {
@Parameter(defaultValue = "${basedir}", readonly = true, required = true)
protected File baseDir;
@Parameter(defaultValue = "${project.build.directory}", readonly = true, required = true)
protected File projectBuildDirectory;
@Parameter(defaultValue = "/src/test/accurest")
protected String contractsDir;
@Parameter(defaultValue = "/generated-test-sources/accurest")
protected String generatedTestSourcesDir;
@Parameter(defaultValue = "io.codearte.accurest.tests")
protected String basePackageForTests;
@Parameter
protected String baseClassForTests;
@Parameter(defaultValue = "MOCKMVC")
protected TestMode testMode;
protected void generateVerificationCode(TestFramework testFramework) throws MojoExecutionException {
AccurestConfigProperties config = new AccurestConfigProperties();
config.setContractsDslDir(new File(baseDir, contractsDir));
config.setBasePackageForTests(basePackageForTests);
config.setGeneratedTestSourcesDir(new File(projectBuildDirectory, generatedTestSourcesDir));
config.setBaseClassForTests(baseClassForTests);
config.setTargetFramework(testFramework);
config.setTestMode(testMode);
getLog().info(format("Using %s as test source directory", config.getGeneratedTestSourcesDir()));
getLog().info(format("Using %s as base class for verification classes", config.getBaseClassForTests()));
try {
TestGenerator generator = new TestGenerator(config);
int generatedClasses = generator.generate();
getLog().info(format("Generated %s test classes.", generatedClasses));
} catch (AccurestException e) {
throw new MojoExecutionException(format("Accurest Plugin exception: %s", e.getMessage()), e);
}
}
}

View File

@@ -1,18 +0,0 @@
package io.codearte.accurest.maven;
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 io.codearte.accurest.config.TestFramework;
@Mojo(name = "generateSpecs", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES)
public class GenerateSpecsMojo extends AbstractGenerateVerificationCodeMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Generating Spock Specifications source code for Accurest contract verification");
generateVerificationCode(TestFramework.SPOCK);
}
}

View File

@@ -1,18 +1,70 @@
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;
import io.codearte.accurest.config.TestFramework;
import io.codearte.accurest.config.TestMode;
@Mojo(name = "generateTests", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES)
public class GenerateTestsMojo extends AbstractGenerateVerificationCodeMojo {
public class GenerateTestsMojo extends AbstractMojo {
@Parameter(defaultValue = "${basedir}", readonly = true, required = true)
private File baseDir;
@Parameter(defaultValue = "${project.build.directory}", readonly = true, required = true)
private File projectBuildDirectory;
@Parameter(defaultValue = "/src/test/accurest")
private String contractsDir;
@Parameter(defaultValue = "/generated-test-sources/accurest")
private String generatedTestSourcesDir;
@Parameter(defaultValue = "io.codearte.accurest.tests")
private String basePackageForTests;
@Parameter
private String baseClassForTests;
@Parameter(defaultValue = "MOCKMVC")
private TestMode testMode;
@Parameter(defaultValue = "JUNIT")
private TestFramework testFramework;
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Generating JUnit Tests source code for Accurest contract verification");
generateVerificationCode(TestFramework.JUNIT);
getLog().info("Generating server tests source code for Accurest contract verification");
AccurestConfigProperties config = new AccurestConfigProperties();
config.setContractsDslDir(new File(baseDir, contractsDir));
config.setBasePackageForTests(basePackageForTests);
config.setGeneratedTestSourcesDir(new File(projectBuildDirectory, generatedTestSourcesDir));
config.setBaseClassForTests(baseClassForTests);
config.setTargetFramework(testFramework);
config.setTestMode(testMode);
getLog().info(format("Using %s as test source directory", config.getGeneratedTestSourcesDir()));
getLog().info(format("Using %s as base class for test classes", config.getBaseClassForTests()));
try {
TestGenerator generator = new TestGenerator(config);
int generatedClasses = generator.generate();
getLog().info(format("Generated %s test classes.", generatedClasses));
} catch (AccurestException e) {
throw new MojoExecutionException(format("Accurest Plugin exception: %s", e.getMessage()), e);
}
}
}

View File

@@ -33,19 +33,20 @@ public class PluginIntegrationTest {
maven.forProject(basedir)
.execute("package")
.assertErrorFreeLog()
.assertLogText("Generating Spock Specifications source code for Accurest contract verification")
.assertLogText("Generating server tests source code for Accurest contract verification")
.assertLogText("Generated 1 test classes.")
.assertLogText("Accurest Plugin: Invoking GroovyDSL to WireMock client stubs conversion")
.assertLogText("Creating new json")
.assertErrorFreeLog();
}
@Test
public void should_build_project_Spring_Boot_Java_with_Accurest() throws Exception {
File basedir = resources.getBasedir("spring-boot-java");
maven.forProject(basedir)
.execute("package")
.assertErrorFreeLog()
.assertLogText("Generating JUnit Tests source code for Accurest contract verification")
.assertLogText("Generating server tests source code for Accurest contract verification")
.assertLogText("Generated 1 test classes.")
.assertLogText("Accurest Plugin: Invoking GroovyDSL to WireMock client stubs conversion")
.assertLogText("Creating new json")
@@ -58,7 +59,8 @@ public class PluginIntegrationTest {
properties.getPluginVersion();
maven.forProject(basedir)
.withCliOption("-X")
.execute(String.format("io.codearte.accurest:accurest-maven-plugin:%s:convert", properties.getPluginVersion()))
.execute(String.format("io.codearte.accurest:accurest-maven-plugin:%s:convert",
properties.getPluginVersion()))
.assertLogText("Converting from accurest contracts written in GroovyDSL to WireMock stubs mappings")
.assertLogText("Creating new json")
.assertErrorFreeLog();

View File

@@ -43,7 +43,7 @@ public class PluginUnitTest {
@Test
public void shouldGenerateContractSpecificationInDefaultLocation() throws Exception {
File basedir = resources.getBasedir("basic");
maven.executeMojo(basedir, "generateSpecs");
maven.executeMojo(basedir, "generateTests", newParameter("testFramework", "SPOCK"));
assertFilesPresent(basedir,
"target/generated-test-sources/accurest/io/codearte/accurest/tests/AccurestSpec.groovy");
}

View File

@@ -79,13 +79,14 @@
<execution>
<goals>
<goal>generateStubs</goal>
<goal>generateSpecs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>
<configuration>
<baseClassForTests>com.ofg.twitter.place.BaseMockMvcSpec</baseClassForTests>
<contractsDir>/src/test/resources/stubs</contractsDir>
<testFramework>SPOCK</testFramework>
</configuration>
</plugin>
<plugin>