diff --git a/pom.xml b/pom.xml index ecfc8f6..f3bdb4f 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,6 @@ raml-maven-plugin-it raml-generator-for-testing lint-checker-core - raml-maven-test-utils diff --git a/raml-maven-plugin/pom.xml b/raml-maven-plugin/pom.xml index 954cd5d..dd70273 100644 --- a/raml-maven-plugin/pom.xml +++ b/raml-maven-plugin/pom.xml @@ -20,6 +20,7 @@ 3.5 + 1.0.0 @@ -160,8 +161,8 @@ uk.gov.justice.maven - raml-maven-test-utils - ${project.version} + maven-test-utils + ${maven-test-utils.version} test diff --git a/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/generator/GenerateMojoTest.java b/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/generator/GenerateMojoTest.java index c259eb2..deeadeb 100644 --- a/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/generator/GenerateMojoTest.java +++ b/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/generator/GenerateMojoTest.java @@ -8,8 +8,8 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.IsEqual.equalTo; +import uk.gov.justice.maven.test.utils.BetterAbstractMojoTestCase; import uk.gov.justice.raml.core.GeneratorConfig; -import uk.gov.justice.raml.maven.test.utils.BetterAbstractMojoTestCase; import java.io.File; import java.nio.file.Files; diff --git a/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/lintchecker/rules/LintCheckMojoTest.java b/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/lintchecker/rules/LintCheckMojoTest.java index 1e3ecb7..18177d4 100644 --- a/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/lintchecker/rules/LintCheckMojoTest.java +++ b/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/lintchecker/rules/LintCheckMojoTest.java @@ -4,11 +4,8 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; +import uk.gov.justice.maven.test.utils.BetterAbstractMojoTestCase; import uk.gov.justice.raml.maven.lintchecker.LintCheckerException; -import uk.gov.justice.raml.maven.lintchecker.rules.FailingLintCheckRule; -import uk.gov.justice.raml.maven.lintchecker.rules.LintCheckMojo; -import uk.gov.justice.raml.maven.lintchecker.rules.SucceedingLintCheckRule; -import uk.gov.justice.raml.maven.test.utils.BetterAbstractMojoTestCase; import java.io.File; diff --git a/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/validator/RamlSyntaxCheckMojoTest.java b/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/validator/RamlSyntaxCheckMojoTest.java index c8feae2..07d4575 100644 --- a/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/validator/RamlSyntaxCheckMojoTest.java +++ b/raml-maven-plugin/src/test/java/uk/gov/justice/raml/maven/validator/RamlSyntaxCheckMojoTest.java @@ -9,8 +9,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import uk.gov.justice.maven.test.utils.BetterAbstractMojoTestCase; import uk.gov.justice.raml.maven.common.BasicGoalConfig; -import uk.gov.justice.raml.maven.test.utils.BetterAbstractMojoTestCase; import java.io.File; import java.io.IOException; diff --git a/raml-maven-test-utils/pom.xml b/raml-maven-test-utils/pom.xml deleted file mode 100644 index 4a35e03..0000000 --- a/raml-maven-test-utils/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - raml-maven - uk.gov.justice.maven - 1.6.6-SNAPSHOT - - 4.0.0 - - raml-maven-test-utils - - - ${cpp.scm.connection} - ${cpp.scm.developerConnection} - ${cpp.scm.url} - - - - - org.apache.maven.plugin-testing - maven-plugin-testing-harness - - - plexus-container-default - org.codehaus.plexus - - - - - org.apache.maven.plugin-tools - maven-plugin-annotations - provided - - - org.apache.maven - maven-artifact - - - - - org.apache.maven - maven-core - - - junit - junit - - - org.hamcrest - hamcrest-core - - - diff --git a/raml-maven-test-utils/src/main/java/uk/gov/justice/raml/maven/test/utils/BetterAbstractMojoTestCase.java b/raml-maven-test-utils/src/main/java/uk/gov/justice/raml/maven/test/utils/BetterAbstractMojoTestCase.java deleted file mode 100644 index 65282da..0000000 --- a/raml-maven-test-utils/src/main/java/uk/gov/justice/raml/maven/test/utils/BetterAbstractMojoTestCase.java +++ /dev/null @@ -1,108 +0,0 @@ -package uk.gov.justice.raml.maven.test.utils; - -import java.io.File; -import java.util.Arrays; - -import org.apache.maven.DefaultMaven; -import org.apache.maven.Maven; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.DefaultMavenExecutionResult; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequestPopulator; -import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.ProjectBuilder; -import org.apache.maven.project.ProjectBuildingRequest; -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; -import org.eclipse.aether.repository.LocalRepository; - -/** - * Use this as you would {@link AbstractMojoTestCase}, where you want more of the standard maven - * defaults to be set (and where the {@link AbstractMojoTestCase} leaves them as null or empty). - * This includes:
  • local repo, repo sessions and managers configured
  • maven default remote - * repos installed (NB: this does not use your ~/.m2 local settings)
  • system properties are - * copies

    No changes to subclass code is needed; this simply intercepts the {@link - * #newMavenSession(MavenProject)} method used by the various {@link #lookupMojo(String, File)} - * methods.

    This also provides new methods, {@link #newMavenSession()} to conveniently create a - * maven session, and {@link #lookupConfiguredMojo(File, String)} so you don't have to always build - * the project yourself. - * - * TODO: Determine how to unit test this class - * The only real way to test this class is to extend and create a concrete version - * and then build a MOJO to test, however this cannot be done without pulling in - * the extra dependencies into the project as MAIN. We are already doing this effectively - * in the raml-maven module and in the lint checker rules (in microservices framework). - * Originally this class was part of TEST in raml-maven-plugin and was moved into MAIN - * so it could be used across maven projects to test MOJOs. - * - */ -public abstract class BetterAbstractMojoTestCase extends AbstractMojoTestCase { - - protected MavenProject project; - - protected MavenSession newMavenSession() { - try { - MavenExecutionRequest request = new DefaultMavenExecutionRequest(); - MavenExecutionResult result = new DefaultMavenExecutionResult(); - - // populate sensible defaults, including repository basedir and remote repos - MavenExecutionRequestPopulator populator; - populator = getContainer().lookup(MavenExecutionRequestPopulator.class); - populator.populateDefaults(request); - - // this is needed to allow java profiles to get resolved; i.e. avoid during project builds: - // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14 - request.setSystemProperties(System.getProperties()); - - // and this is needed so that the repo session in the maven session - // has a repo manager, and it points at the local repo - // (cf MavenRepositorySystemUtils.newSession() which is what is otherwise done) - DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class); - DefaultRepositorySystemSession repoSession = - (DefaultRepositorySystemSession) maven.newRepositorySession(request); - repoSession.setLocalRepositoryManager( - new SimpleLocalRepositoryManagerFactory().newInstance(repoSession, - new LocalRepository(request.getLocalRepository().getBasedir()))); - - @SuppressWarnings("deprecation") - MavenSession session = new MavenSession(getContainer(), - repoSession, - request, result); - return session; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Extends the super to use the new {@link #newMavenSession()} introduced here which sets the - * defaults one expects from maven; the standard test case leaves a lot of things blank - */ - @Override - protected MavenSession newMavenSession(MavenProject project) { - MavenSession session = newMavenSession(); - session.setCurrentProject(project); - session.setProjects(Arrays.asList(project)); - return session; - } - - /** - * As {@link #lookupConfiguredMojo(MavenProject, String)} but taking the pom file and creating - * the {@link MavenProject}. - */ - protected Mojo lookupConfiguredMojo(File pom, String goal) throws Exception { - assertNotNull(pom); - assertTrue(pom.exists()); - - ProjectBuildingRequest buildingRequest = newMavenSession().getProjectBuildingRequest(); - ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); - project = projectBuilder.build(pom, buildingRequest).getProject(); - - return lookupConfiguredMojo(project, goal); - } - -}