generating wiremock stubs from accurest contracts
This commit is contained in:
100
pom.xml
100
pom.xml
@@ -8,5 +8,105 @@
|
||||
<artifactId>accurest-maven-plugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<packaging>takari-maven-plugin</packaging>
|
||||
|
||||
<prerequisites>
|
||||
<maven>3.3.3</maven>
|
||||
</prerequisites>
|
||||
|
||||
<properties>
|
||||
<mavenVersion>3.2.5</mavenVersion>
|
||||
<mavenPluginPluginVersion>3.4</mavenPluginPluginVersion>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.codearte.accurest</groupId>
|
||||
<artifactId>accurest-core</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.codearte.accurest</groupId>
|
||||
<artifactId>accurest-converters</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
<version>2.4.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core</artifactId>
|
||||
<version>${mavenVersion}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-compat</artifactId>
|
||||
<version>${mavenVersion}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.inject</groupId>
|
||||
<artifactId>javax.inject</artifactId>
|
||||
<version>1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>${mavenVersion}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>${mavenPluginPluginVersion}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.takari.maven.plugins</groupId>
|
||||
<artifactId>takari-plugin-testing</artifactId>
|
||||
<version>2.8.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.takari.maven.plugins</groupId>
|
||||
<artifactId>takari-lifecycle-plugin</artifactId>
|
||||
<version>1.11.12</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<proc>none</proc>
|
||||
</configuration>
|
||||
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.codearte.accurest.maven;
|
||||
|
||||
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.config.AccurestConfigProperties;
|
||||
import io.codearte.accurest.wiremock.DslToWireMockClientConverter;
|
||||
import io.codearte.accurest.wiremock.RecursiveFilesConverter;
|
||||
|
||||
@Mojo(name = "generateStubs", defaultPhase = LifecyclePhase.PROCESS_RESOURCES)
|
||||
public class GenerateStubsMojo extends AbstractMojo {
|
||||
|
||||
@Parameter(defaultValue = "${basedir}")
|
||||
protected File baseDir;
|
||||
|
||||
@Parameter(defaultValue = "${project.build.directory}")
|
||||
protected File projectBuildDirectory;
|
||||
|
||||
@Parameter(property = "mappingsDir", defaultValue = "mappings", required = false)
|
||||
private String mappingsDir = "mappings";
|
||||
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
getLog().info("");
|
||||
getLog().info("*** Accurest Maven Plugin ***");
|
||||
getLog().info("");
|
||||
|
||||
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));
|
||||
|
||||
RecursiveFilesConverter converter = new RecursiveFilesConverter(new DslToWireMockClientConverter(),
|
||||
configProperties);
|
||||
converter.processFiles();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
35
src/test/java/io/codearte/accurest/maven/PluginUnitTest.java
Normal file
35
src/test/java/io/codearte/accurest/maven/PluginUnitTest.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package io.codearte.accurest.maven;
|
||||
|
||||
import static io.takari.maven.testing.TestResources.assertFilesPresent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import io.takari.maven.testing.TestMavenRuntime;
|
||||
import io.takari.maven.testing.TestResources;
|
||||
|
||||
public class PluginUnitTest {
|
||||
|
||||
@Rule
|
||||
public final TestResources resources = new TestResources();
|
||||
|
||||
@Rule
|
||||
public final TestMavenRuntime maven = new TestMavenRuntime();
|
||||
|
||||
@Test
|
||||
public void shouldGenerateWarlockStubsInDefaultLocation() throws Exception {
|
||||
File basedir = resources.getBasedir("basic");
|
||||
maven.executeMojo(basedir, "generateStubs");
|
||||
assertFilesPresent(basedir, "target/mappings/Sample.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateWarlockStubsInSelectedLocation() throws Exception {
|
||||
File basedir = resources.getBasedir("basic");
|
||||
maven.executeMojo(basedir, "generateStubs", TestMavenRuntime.newParameter("mappingsDir", "foo"));
|
||||
assertFilesPresent(basedir, "target/foo/Sample.json");
|
||||
}
|
||||
|
||||
}
|
||||
19
src/test/projects/basic/pom.xml
Normal file
19
src/test/projects/basic/pom.xml
Normal 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>
|
||||
@@ -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'
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/test/projects/example/pom.xml
Normal file
20
src/test/projects/example/pom.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?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>
|
||||
<version>${it-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user