diff --git a/license-maven-plugin/pom.xml b/license-maven-plugin/pom.xml index b03c24a1f..3ac4075b6 100644 --- a/license-maven-plugin/pom.xml +++ b/license-maven-plugin/pom.xml @@ -122,6 +122,48 @@ + + com.soebes.itf.jupiter.extension + itf-maven-plugin + 0.12.0 + + + installing + pre-integration-test + + install + resources-its + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + ${maven.version} + ${maven.home} + + + + junit.jupiter.execution.parallel.enabled=true + junit.jupiter.execution.parallel.mode.default=concurrent + junit.jupiter.execution.parallel.mode.classes.default=same_thread + junit.jupiter.execution.parallel.config.strategy=fixed + junit.jupiter.execution.parallel.config.fixed.parallelism=6 + + + + + + + integration-test + verify + + + + @@ -241,6 +283,20 @@ + + + com.soebes.itf.jupiter.extension + itf-assertj + 0.12.0 + test + + + com.soebes.itf.jupiter.extension + itf-jupiter-extension + 0.12.0 + test + + diff --git a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT.java b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT.java index bf182aa89..98db1caa7 100644 --- a/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT.java +++ b/license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT.java @@ -15,110 +15,63 @@ */ package com.mycila.maven.plugin.license.dependencies; -import com.google.common.io.Files; -import org.apache.maven.it.VerificationException; -import org.apache.maven.it.Verifier; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; +import static com.soebes.itf.extension.assertj.MavenITAssertions.assertThat; -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Optional; +import org.junit.jupiter.api.DisplayName; + +import com.soebes.itf.jupiter.extension.MavenGoal; +import com.soebes.itf.jupiter.extension.MavenJupiterExtension; +import com.soebes.itf.jupiter.extension.MavenTest; +import com.soebes.itf.jupiter.maven.MavenExecutionResult; /** - * We use {@link Verifier} here for mvn executions, mainly so: - * a) we can verify a few cases that the invoker method make really difficult (I'd like to step-through with my IDE) - * b) the test harness method requires creating a custom Artifact resolver, as the dependencGraphBuilder Component will + * The Maven Integration Testing Framework + * is used here. The main reasons being as follow + *

+ * a) we can verify a few cases that the invoker method make really difficult (For debugging purpose follow this + * + * guide) + * b) the test harness method requires creating a custom Artifact resolver, as the dependencyGraphBuilder Component will * not provide a usable bean, and we would need extensive mocking to override data for specific cases * c) it's a lot faster than maven-invoker-plugin - * ... good overview of similar woes - * https://khmarbaise.github.io/maven-it-extension/itf-documentation/background/background.html + * d) No snapshot installation should be necessary (the custom extension does all the necessary filtering) + *

+ * A good overview of similar woes + * https://khmarbaise.github.io/maven-it-extension/itf-documentation/background/background.html. * * @author Royce Remer + * @author Michael J. Simons */ -class MavenProjectLicensesIT { - - File source; - String target; - String phase; - Map env; - - @TempDir - File workspace; - final String sourcePrefix = "src/test/resources/config/"; - final String resource = "/pom.xml"; - - @BeforeEach - public void setUp() { - // your maven may be on a different path, they'll append '/bin/mvn' to it - System.setProperty("maven.home", "/usr/local"); - - this.target = workspace.getAbsolutePath(); - this.env = Collections.singletonMap("LICENSE_PLUGIN_VERSION", this.getClass().getPackage().getImplementationVersion()); - this.phase = "verify"; - } - - private boolean hasLogLine(final String logline) { - Optional verifier; - try { - verifier = Optional.of(new Verifier(target)); - } catch (Exception ex) { - // project didn't even build, this is a test or test resource error - return false; - } - - try { - verifier.get().executeGoal(phase, env); - } catch (VerificationException e) { - // potential purposeful MojoExecutionException (hidden in stack) - try { - verifier.get().verifyTextInLog(logline); - return true; - } catch (VerificationException e1) { - } - } - - // legit test failure - return false; +@MavenJupiterExtension +public class MavenProjectLicensesIT { + + @MavenTest + @MavenGoal("license:check") + @DisplayName("A project with enforcement enabled but nothing in scope should find zero dependencies") + void no_dependencies(MavenExecutionResult result) { + assertThat(result) + .isSuccessful() + .out().info() + .contains(LicenseMessage.INFO_DEPS_DISCOVERED + ": 0"); } - /** - * Helper method to sync test resources to a temporary folder for execution. - * - * @param dir - String relative path to {@link sourcePrefix} to copy from. - * @throws IOException - */ - private void syncTarget(final String dir) throws IOException { - source = new File(sourcePrefix + dir + resource); - final File syncTarget = new File(target + resource); - Files.copy(source, syncTarget); - } - - @Test - void test_null() throws IOException { - final String description = "A project with enforcement enabled but nothing in scope should find zero dependencies"; - syncTarget("null"); - - Assertions.assertTrue(hasLogLine(LicenseMessage.INFO_DEPS_DISCOVERED + ": 0"), description); + @MavenTest + @MavenGoal("license:check") + @DisplayName("A project with enforcement enabled and dependencies in scope under default deny policy should fail.") + void deny(MavenExecutionResult result) { + assertThat(result) + .isFailure() + .out().error() + .anyMatch(s -> s.contains(LicenseMessage.WARN_POLICY_DENIED)); } - @Test - void test_deny() throws IOException { - final String description = "A project with enforcement enabled and dependencies in scope under default deny policy should fail."; - syncTarget("deny"); - - Assertions.assertTrue(hasLogLine(LicenseMessage.WARN_POLICY_DENIED), description); - } - - @Test - void test_approved() throws IOException { - final String description = "A project with allow policy and a single dependency should succeed."; - syncTarget("approve"); - - Assertions.assertTrue(hasLogLine(LicenseMessage.INFO_DEPS_DISCOVERED + ": 1"), description); + @MavenTest + @MavenGoal("license:check") + @DisplayName("A project with allow policy and a single dependency should succeed.") + void approve(MavenExecutionResult result) { + assertThat(result) + .isSuccessful() + .out().info() + .contains(LicenseMessage.INFO_DEPS_DISCOVERED + ": 1"); } } diff --git a/license-maven-plugin/src/test/resources/config/approve/pom.xml b/license-maven-plugin/src/test/resources-its/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT/approve/pom.xml similarity index 96% rename from license-maven-plugin/src/test/resources/config/approve/pom.xml rename to license-maven-plugin/src/test/resources-its/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT/approve/pom.xml index 54f75b688..9bde9f5f8 100644 --- a/license-maven-plugin/src/test/resources/config/approve/pom.xml +++ b/license-maven-plugin/src/test/resources-its/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT/approve/pom.xml @@ -24,7 +24,7 @@ com.mycila license-maven-plugin - ${env.LICENSE_PLUGIN_VERSION} + @project.version@ diff --git a/license-maven-plugin/src/test/resources/config/deny/pom.xml b/license-maven-plugin/src/test/resources-its/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT/deny/pom.xml similarity index 95% rename from license-maven-plugin/src/test/resources/config/deny/pom.xml rename to license-maven-plugin/src/test/resources-its/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT/deny/pom.xml index c39274f72..9dd700582 100644 --- a/license-maven-plugin/src/test/resources/config/deny/pom.xml +++ b/license-maven-plugin/src/test/resources-its/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT/deny/pom.xml @@ -24,7 +24,7 @@ com.mycila license-maven-plugin - ${env.LICENSE_PLUGIN_VERSION} + @project.version@ diff --git a/license-maven-plugin/src/test/resources/config/null/pom.xml b/license-maven-plugin/src/test/resources-its/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT/no_dependencies/pom.xml similarity index 96% rename from license-maven-plugin/src/test/resources/config/null/pom.xml rename to license-maven-plugin/src/test/resources-its/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT/no_dependencies/pom.xml index d7e7389c7..a792a937a 100644 --- a/license-maven-plugin/src/test/resources/config/null/pom.xml +++ b/license-maven-plugin/src/test/resources-its/com/mycila/maven/plugin/license/dependencies/MavenProjectLicensesIT/no_dependencies/pom.xml @@ -24,7 +24,7 @@ com.mycila license-maven-plugin - ${env.LICENSE_PLUGIN_VERSION} + @project.version@ diff --git a/pom.xml b/pom.xml index 9e828799e..920540bd5 100644 --- a/pom.xml +++ b/pom.xml @@ -205,6 +205,11 @@ maven-surefire-plugin 3.0.0-M8 + + org.apache.maven.plugins + maven-failsafe-plugin + 3.0.0-M8 + org.apache.maven.plugins maven-invoker-plugin