Plugins are generating tests for all contracts when using external contracts
When using contract plugins together with a shared repo with contracts we end up with creating contract tests for all the contracts. Stubs are created properly but tests generation ignores the path pattern. With this change we fix the way tests are generated fixes #155
This commit is contained in:
@@ -134,7 +134,7 @@ public class ConvertMojo extends AbstractMojo {
|
||||
this.aetherStubDownloaderFactory, this.repoSession).downloadAndUnpackContractsIfRequired(config, this.contractsDirectory);
|
||||
getLog().info("Directory with contract is present at [" + contractsDirectory + "]");
|
||||
|
||||
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering)
|
||||
new CopyContracts(this.project, this.mavenSession, this.mavenResourcesFiltering, config)
|
||||
.copy(contractsDirectory, this.stubsDirectory);
|
||||
|
||||
config.setContractsDslDir(isInsideProject() ? contractsDirectory : this.source);
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.apache.maven.shared.filtering.MavenResourcesExecution;
|
||||
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties;
|
||||
|
||||
class CopyContracts {
|
||||
private static final Logger log = LoggerFactory
|
||||
@@ -35,17 +36,22 @@ class CopyContracts {
|
||||
private final MavenProject project;
|
||||
private final MavenSession mavenSession;
|
||||
private final MavenResourcesFiltering mavenResourcesFiltering;
|
||||
private final ContractVerifierConfigProperties config;
|
||||
|
||||
public CopyContracts(MavenProject project, MavenSession mavenSession,
|
||||
MavenResourcesFiltering mavenResourcesFiltering) {
|
||||
MavenResourcesFiltering mavenResourcesFiltering,
|
||||
ContractVerifierConfigProperties config) {
|
||||
this.project = project;
|
||||
this.mavenSession = mavenSession;
|
||||
this.mavenResourcesFiltering = mavenResourcesFiltering;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void copy(File contractsDirectory, File outputDirectory)
|
||||
throws MojoExecutionException {
|
||||
log.info("Copying Spring Cloud Contract Verifier contracts");
|
||||
log.info("Copying Spring Cloud Contract Verifier contracts. Only files matching "
|
||||
+ "[" + this.config.getIncludedContracts() + "] pattern will end up in "
|
||||
+ "the final JAR with stubs.");
|
||||
Resource resource = new Resource();
|
||||
resource.setDirectory(contractsDirectory.getAbsolutePath());
|
||||
MavenResourcesExecution execution = new MavenResourcesExecution();
|
||||
|
||||
@@ -19,8 +19,6 @@ package org.springframework.cloud.contract.maven.verifier;
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -148,6 +146,7 @@ public class PluginUnitTest {
|
||||
File basedir = this.resources.getBasedir("complex-remote-contracts");
|
||||
this.maven.executeMojo(basedir, "convert", newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class.getClassLoader().getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
||||
assertFilesPresent(basedir, "target/stubs/mappings/com/example/server/client1/contracts/shouldMarkClientAsFraud.json");
|
||||
assertFilesNotPresent(basedir, "target/stubs/mappings/com/foo/bar/baz/shouldBeIgnoredByPlugin.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,6 +161,7 @@ public class PluginUnitTest {
|
||||
File basedir = this.resources.getBasedir("complex-remote-contracts");
|
||||
this.maven.executeMojo(basedir, "generateTests", newParameter("contractsRepositoryUrl", "file://" + PluginUnitTest.class.getClassLoader().getResource("m2repo/repository").getFile().replace("/", File.separator)));
|
||||
assertFilesPresent(basedir, "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/example/server/client1/ContractsTest.java");
|
||||
assertFilesNotPresent(basedir, "target/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/com/foo/bar/BazTest.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
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>com.example</groupId>
|
||||
<groupId>com.example.foo.bar.baz</groupId>
|
||||
<artifactId>someartifact</artifactId>
|
||||
<version>0.1.BUILD-SNAPSHOT</version>
|
||||
|
||||
|
||||
Binary file not shown.
@@ -58,7 +58,8 @@ class TestGenerator {
|
||||
this.saver = saver
|
||||
contractFileScanner = new ContractFileScanner(configProperties.contractsDslDir,
|
||||
configProperties.excludedFiles as Set,
|
||||
configProperties.ignoredFiles as Set)
|
||||
configProperties.ignoredFiles as Set,
|
||||
this.configProperties.includedContracts)
|
||||
}
|
||||
|
||||
int generate() {
|
||||
|
||||
Reference in New Issue
Block a user