From 59ebc673c0023e6289f9dd3725a29e6e70f930b7 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Fri, 29 Jun 2007 05:55:49 +0000 Subject: [PATCH] o separation of the base integration test. this can now be used in the IT suite we run and used in the archetype. git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@551804 13f79535-47bb-0310-9956-ffa450edef68 --- its/maven-integration-test-helper/pom.xml | 25 ++++ .../AbstractMavenIntegrationTestCase.java | 109 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 its/maven-integration-test-helper/pom.xml create mode 100644 its/maven-integration-test-helper/src/main/java/org/apache/maven/integrationtests/AbstractMavenIntegrationTestCase.java diff --git a/its/maven-integration-test-helper/pom.xml b/its/maven-integration-test-helper/pom.xml new file mode 100644 index 0000000000..3116866f96 --- /dev/null +++ b/its/maven-integration-test-helper/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + org.apache.maven.its + maven-integration-test-helper + 1.0-SNAPSHOT + Maven Integration Tests + + + + org.apache.maven + maven-artifact + 2.0.5 + + + org.apache.maven.shared + maven-verifier + 1.1-SNAPSHOT + + + junit + junit + 3.8.1 + + + diff --git a/its/maven-integration-test-helper/src/main/java/org/apache/maven/integrationtests/AbstractMavenIntegrationTestCase.java b/its/maven-integration-test-helper/src/main/java/org/apache/maven/integrationtests/AbstractMavenIntegrationTestCase.java new file mode 100644 index 0000000000..2e2c88ca93 --- /dev/null +++ b/its/maven-integration-test-helper/src/main/java/org/apache/maven/integrationtests/AbstractMavenIntegrationTestCase.java @@ -0,0 +1,109 @@ +package org.apache.maven.integrationtests; + +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.it.util.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; + +import junit.framework.TestCase; + +/** + * @author Jason van Zyl + * @author Kenney Westerhof + */ +public abstract class AbstractMavenIntegrationTestCase + extends TestCase +{ + /** + * Save System.out for progress reports etc. + */ + private static PrintStream out = System.out; + + private boolean skip; + + private DefaultArtifactVersion version; + + private VersionRange versionRange; + + protected AbstractMavenIntegrationTestCase() + { + } + + protected AbstractMavenIntegrationTestCase( String versionRangeStr ) + throws InvalidVersionSpecificationException + { + this.versionRange = VersionRange.createFromVersionSpec( versionRangeStr ); + + String v = System.getProperty( "maven.version" ); + if ( v != null ) + { + this.version = new DefaultArtifactVersion( v ); + if ( !versionRange.containsVersion( this.version ) ) + { + skip = true; + } + } + else + { + out.print( "WARNING: " + getITName() + ": version range '" + versionRange + + "' supplied but no maven version - not skipping test." ); + } + } + + protected void runTest() + throws Throwable + { + out.print( getITName() + "(" + getName() + ").." ); + + if ( skip ) + { + out.println( " Skipping (version " + version + " not in range " + versionRange + ")" ); + return; + } + + if ( "true".equals( System.getProperty( "useEmptyLocalRepository", "false" ) ) ) + { + setupLocalRepo(); + } + + try + { + super.runTest(); + out.println( " Ok" ); + } + catch ( Throwable t ) + { + out.println( " Failure" ); + throw t; + } + } + + private String getITName() + { + String simpleName = getClass().getName(); + int idx = simpleName.lastIndexOf( '.' ); + simpleName = idx >= 0 ? simpleName.substring( idx + 1 ) : simpleName; + simpleName = simpleName.startsWith( "MavenIT" ) ? simpleName.substring( "MavenIT".length() ) : simpleName; + simpleName = simpleName.endsWith( "Test" ) ? simpleName.substring( 0, simpleName.length() - 4 ) : simpleName; + return simpleName; + } + + protected File setupLocalRepo() + throws IOException + { + String tempDirPath = System.getProperty( "maven.test.tmpdir", System.getProperty( "java.io.tmpdir" ) ); + File localRepo = new File( tempDirPath, "local-repository/" + getITName() ); + if ( localRepo.isDirectory() ) + { + FileUtils.deleteDirectory( localRepo ); + } + + System.setProperty( "maven.repo.local", localRepo.getAbsolutePath() ); + + return localRepo; + } +}