Add contracts to stub.jar by default (#13)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
||||
.idea/
|
||||
*.iml
|
||||
target
|
||||
/target
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
|
||||
@@ -37,9 +37,6 @@ class ConvertMojo extends AbstractMojo {
|
||||
@Parameter(property = 'accurest.skip', defaultValue = 'false')
|
||||
private boolean skip
|
||||
|
||||
@Parameter(defaultValue = 'false')
|
||||
private boolean attachContracts
|
||||
|
||||
@Parameter(defaultValue = '${session}', readonly = true)
|
||||
private MavenSession mavenSession
|
||||
|
||||
@@ -56,13 +53,9 @@ class ConvertMojo extends AbstractMojo {
|
||||
return
|
||||
}
|
||||
|
||||
if (attachContracts) {
|
||||
log.info("Attaching accurest contracts")
|
||||
copyContracts()
|
||||
}
|
||||
copyContracts()
|
||||
|
||||
AccurestConfigProperties config = new AccurestConfigProperties()
|
||||
|
||||
config.contractsDslDir = insideProject ? contractsDirectory : source
|
||||
config.stubsOutputDir = insideProject ? new File(outputDirectory, 'mappings') : destination
|
||||
|
||||
@@ -75,8 +68,8 @@ class ConvertMojo extends AbstractMojo {
|
||||
}
|
||||
|
||||
private void copyContracts() {
|
||||
log.info("Copying accurest contracts")
|
||||
Resource testResource = new Resource(directory: contractsDirectory.absolutePath)
|
||||
|
||||
MavenResourcesExecution mavenResourcesExecution =
|
||||
new MavenResourcesExecution([testResource],
|
||||
new File(outputDirectory, 'contracts'), project, 'UTF-8',
|
||||
|
||||
@@ -17,6 +17,9 @@ import org.codehaus.plexus.archiver.jar.JarArchiver
|
||||
@CompileStatic
|
||||
class GenerateStubsMojo extends AbstractMojo {
|
||||
|
||||
private static final String STUB_MAPPING_FILE_PATTERN = '**/*.json'
|
||||
private static final String ACCUREST_FILE_PATTERN = '**/*.groovy'
|
||||
|
||||
@Parameter(defaultValue = '${project.build.directory}', readonly = true, required = true)
|
||||
private File projectBuildDirectory
|
||||
|
||||
@@ -35,6 +38,9 @@ class GenerateStubsMojo extends AbstractMojo {
|
||||
@Component(role = Archiver.class, hint = "jar")
|
||||
private JarArchiver jarArchiver;
|
||||
|
||||
@Parameter(defaultValue = 'true')
|
||||
private boolean attachContracts
|
||||
|
||||
void execute() throws MojoExecutionException, MojoFailureException {
|
||||
|
||||
if (skip) {
|
||||
@@ -54,7 +60,12 @@ class GenerateStubsMojo extends AbstractMojo {
|
||||
File stubJarFile = new File(projectBuildDirectory, stubArchiveName);
|
||||
|
||||
try {
|
||||
jarArchiver.addDirectory(stubsOutputDir);
|
||||
if (attachContracts) {
|
||||
jarArchiver.addDirectory(stubsOutputDir, [STUB_MAPPING_FILE_PATTERN, ACCUREST_FILE_PATTERN] as String[], [] as String[]);
|
||||
} else {
|
||||
log.info("Skipping attaching accurest contracts")
|
||||
jarArchiver.addDirectory(stubsOutputDir, [STUB_MAPPING_FILE_PATTERN] as String[], [ACCUREST_FILE_PATTERN] as String[]);
|
||||
}
|
||||
jarArchiver.setCompress(true);
|
||||
jarArchiver.setDestFile(stubJarFile);
|
||||
jarArchiver.createArchive();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.codearte.accurest.maven;
|
||||
|
||||
import static io.takari.maven.testing.TestMavenRuntime.newParameter;
|
||||
import static io.takari.maven.testing.TestResources.assertFileContents;
|
||||
import static io.takari.maven.testing.TestResources.assertFilesPresent;
|
||||
|
||||
import java.io.File;
|
||||
@@ -56,4 +57,19 @@ public class PluginUnitTest {
|
||||
"target/generated-test-sources/accurest/io/codearte/accurest/tests/AccurestTest.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateStubs() throws Exception {
|
||||
File basedir = resources.getBasedir("generatedStubs");
|
||||
maven.executeMojo(basedir, "generateStubs");
|
||||
assertFilesPresent(basedir, "target/sample-project-0.1-stubs.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateStubsWithMappingsOnly() throws Exception {
|
||||
File basedir = resources.getBasedir("generatedStubs");
|
||||
maven.executeMojo(basedir, "generateStubs", newParameter("attachContracts", "false"));
|
||||
assertFilesPresent(basedir, "target/sample-project-0.1-stubs.jar");
|
||||
// FIXME: add assertion for jar content
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
19
src/test/projects/generatedStubs/pom.xml
Normal file
19
src/test/projects/generatedStubs/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'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user