changes to sample to make it generic and self documenting

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@558915 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brian E Fox 2007-07-24 02:20:12 +00:00
parent 82415445e6
commit 51d66b92e6
10 changed files with 143 additions and 55 deletions

View File

@ -11,10 +11,10 @@
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.its</groupId>
<artifactId>maven-integration-test-helper</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<groupId>org.apache.maven.its</groupId>
<artifactId>maven-integration-test-helper</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@ -22,4 +22,17 @@
<scope>test</scope>
</dependency>
</dependencies>
<!-- TODO: remove when snapshots are released -->
<repositories>
<repository>
<id>apache.snapshots</id>
<url>http://people.apache.org/repo/m2-snapshot-repository</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>

View File

@ -1,45 +0,0 @@
package org.apache.maven.integrationtests;
import java.io.File;
import java.util.List;
import java.util.ArrayList;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
//!! public class ${className}
public class MavenIT0111PluginsThatRequireAResourceFromAnExtensionTest
extends AbstractMavenIntegrationTestCase
{
public void testit0111()
throws Exception
{
File testDir =
ResourceExtractor.simpleExtractResources( getClass(), "/it0111-pluginThatRequiresResourceFromAnExtension" );
Verifier verifier;
// Install the parent POM
verifier = new Verifier( testDir.getAbsolutePath() );
verifier.deleteArtifact( "org.apache.maven.its.it0111", "parent", "1.0", "pom" );
verifier.deleteArtifact( "org.apache.maven.its.it0111", "checkstyle-test", "1.0", "jar" );
verifier.deleteArtifact( "org.apache.maven.its.it0111", "checkstyle-assembly", "1.0", "jar" );
List cliOptions = new ArrayList();
cliOptions.add( "-N" );
verifier.executeGoal( "install" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
// Install the extension with the resources required for the test
verifier = new Verifier( new File( testDir.getAbsolutePath(), "checkstyle-assembly" ).getAbsolutePath() );
verifier.executeGoal( "install" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
// Run the whole test
verifier = new Verifier( new File( testDir.getAbsolutePath(), "checkstyle-test" ).getAbsolutePath() );
verifier.executeGoal( "install" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
}
}

View File

@ -0,0 +1,113 @@
package org.apache.maven.integrationtests;
import java.io.File;
import java.util.List;
import java.util.ArrayList;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
/**
* This is a sample integration test. The IT tests typically
* operate by having a sample project in the
* /src/test/resources folder along with a junit test like
* this one. The junit test uses the verifier (which uses
* the invoker) to invoke a new instance of Maven on the
* project in the resources folder. It then checks the
* results. This is a non-trivial example that shows two
* phases. See more information inline in the code.
*
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
*
*/
public class MavenITmngXXXXDescriptionOfProblemTest
extends AbstractMavenIntegrationTestCase
{
public void testitMNGxxxx ()
throws Exception
{
// TODO: RENAME THIS TEST TO SUIT YOUR SCENARIO.
// Usign the Jira issue id this reproduces is a good
// start, along with a description:
// ie MNG-13x-HoustonWeHaveAProblemTest (must end in test)
// The testdir is computed from the location of this
// file.
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-xxxx-descriptionOfProblem" );
Verifier verifier;
/*
* We must first make sure that any artifact created
* by this test has been removed from the local
* repository. Failing to do this could cause
* unstable test results. Fortunately, the verifier
* makes it easy to do this.
*/
verifier = new Verifier( testDir.getAbsolutePath() );
verifier.deleteArtifact( "org.apache.maven.its.itsample", "parent", "1.0", "pom" );
verifier.deleteArtifact( "org.apache.maven.its.itsample", "checkstyle-test", "1.0", "jar" );
verifier.deleteArtifact( "org.apache.maven.its.itsample", "checkstyle-assembly", "1.0", "jar" );
/*
* The Command Line Options (CLI) are passed to the
* verifier as a list. This is handy for things like
* redefining the local repository if needed. In
* this case, we use the -N flag so that Maven won't
* recurse. We are only installing the parent pom to
* the local repo here.
*/
List cliOptions = new ArrayList();
cliOptions.add( "-N" );
verifier.executeGoal( "install" );
/*
* This is the simplest way to check a build
* succeeded. It is also the simplest way to create
* an IT test: make the build pass when the test
* should pass, and make the build fail when the
* test should fail. There are other methods
* supported by the verifier. They can be seen here:
* http://maven.apache.org/shared/maven-verifier/apidocs/index.html
*/
verifier.verifyErrorFreeLog();
/*
* Reset the streams before executing the verifier
* again.
*/
verifier.resetStreams();
/*
* This particular test requires an extension
* containing resources to be installed that is then
* used by the actual IT test. Here we invoker Maven
* again to install it. Again, this is just
* preparation for the test.
*/
verifier = new Verifier( new File( testDir.getAbsolutePath(), "checkstyle-assembly" ).getAbsolutePath() );
verifier.executeGoal( "install" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
/*
* Now we are running the actual test. This
* particular test will attempt to load the
* resources from the extension jar previously
* installed. If Maven doesn't pass this to the
* classpath correctly, the build will fail. This
* particular test will fail in Maven <2.0.6.
*/
verifier = new Verifier( new File( testDir.getAbsolutePath(), "checkstyle-test" ).getAbsolutePath() );
verifier.executeGoal( "install" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
/*
* The verifier also supports beanshell scripts for
* verification of more complex scenarios. There are
* plenty of examples in the core-it tests here:
* http://svn.apache.org/repos/asf/maven/core-integration-testing/trunk
*/
}
}

View File

@ -2,7 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.it0111</groupId>
<groupId>org.apache.maven.its.itsample</groupId>
<artifactId>parent</artifactId>
<version>1</version>
</parent>

View File

@ -1,7 +1,7 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.it0111</groupId>
<groupId>org.apache.maven.its.itsample</groupId>
<artifactId>parent</artifactId>
<version>1</version>
</parent>
@ -9,15 +9,20 @@
<name>Checkstyle Test</name>
<build>
<!--This extension is installed by the IT prior to invoking this build. See ../checkstyle-assembly-->
<extensions>
<extension>
<groupId>org.apache.maven.its.it0111</groupId>
<groupId>org.apache.maven.its.itsample</groupId>
<artifactId>checkstyle-assembly</artifactId>
<version>1.0</version>
</extension>
</extensions>
<!-- Typically the tests will not rely on actual plugins and should be self-contained, in this case the problem was most
often experienced with Checkstyle so it makes it a valid test. Notice however that it is pinned to a known released version
so the test won't randomly fail in the future if the plugin behavior changes.
If the extension listed above isn't correctly installed on the plugin classpath, this invocation will fail to find the custom rule -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -40,7 +45,6 @@
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,6 +1,6 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.it0111</groupId>
<groupId>org.apache.maven.its.itsample</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1</version>

View File

@ -0,0 +1,3 @@
This is a sample IT based on a real one. This test first installs a jar containing some checkstyle rules. The second invocation uses that jar as an extension
so that checkstyle finds the resources. If Maven behaves properly, the build succeeds, if not, the build fails. This is the simplest way to structure an IT when
possible as it's cut and dry and is very easy to check with the verifier.