[MNG-3545] Adding test for profile activation and deactivation.

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@656403 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Paul Gier 2008-05-14 20:19:26 +00:00
parent 7821187c9e
commit 638b340dbe
3 changed files with 351 additions and 0 deletions

View File

@ -65,6 +65,7 @@ public class IntegrationTestSuite
* a fail fast technique as well.
*/
suite.addTestSuite( MavenITmng3545ProfileDeactivation.class );
suite.addTestSuite( MavenITmng3498ForkToOtherMojoTest.class );
suite.addTestSuite( MavenITmng3485OverrideWagonExtensionTest.class );
suite.addTestSuite( MavenITmng3482DependencyPomInterpolationTest.class );

View File

@ -0,0 +1,196 @@
package org.apache.maven.integrationtests;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
/**
* Test activation and deactivation of profiles.
*
*/
public class MavenITmng3545ProfileDeactivation
extends AbstractMavenIntegrationTestCase
{
public MavenITmng3545ProfileDeactivation()
throws InvalidVersionSpecificationException
{
super( "(2.0.9,)" );
}
/**
* Test build with two active by default profiles
*
*/
public void testBasicBuildWithDefaultProfiles()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545-ProfileDeactivation" );
Verifier verifier;
verifier = new Verifier( testDir.getAbsolutePath() );
List cliOptions = new ArrayList();
verifier.setCliOptions( cliOptions );
verifier.executeGoal( "package" );
verifier.verifyErrorFreeLog();
// profile 1 and 2 are active by default
verifier.assertFilePresent( "target/profile1/touch.txt" );
verifier.assertFilePresent( "target/profile2/touch.txt" );
verifier.assertFileNotPresent( "target/profile3/touch.txt" );
verifier.assertFileNotPresent( "target/profile4/touch.txt" );
verifier.assertFileNotPresent( "target/profile5/touch.txt" );
verifier.resetStreams();
}
/**
* Test command line deactivation of active by default profiles.
*
*/
public void testDeactivateDefaultProfiles()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545-ProfileDeactivation" );
Verifier verifier;
verifier = new Verifier( testDir.getAbsolutePath() );
List cliOptions = new ArrayList();
// Deactivate active by default profiles
cliOptions.add( "-P-profile1" );
cliOptions.add( "-P -profile2" );
verifier.setCliOptions( cliOptions );
verifier.executeGoal( "package" );
verifier.verifyErrorFreeLog();
verifier.assertFileNotPresent( "target/profile1/touch.txt" );
verifier.assertFileNotPresent( "target/profile2/touch.txt" );
verifier.resetStreams();
}
/**
* Test command line deactivation of a profile that was activated
* by a property
*
*/
public void testDeactivateActivatedByProp()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545-ProfileDeactivation" );
Verifier verifier;
verifier = new Verifier( testDir.getAbsolutePath() );
List cliOptions = new ArrayList();
// Activate with a prop, then deactivate
cliOptions.add( "-Dprofile3-active-by-property=true" );
cliOptions.add( "-P-profile3" );
verifier.setCliOptions( cliOptions );
verifier.executeGoal( "package" );
verifier.verifyErrorFreeLog();
verifier.assertFilePresent( "target/profile1/touch.txt" );
verifier.assertFilePresent( "target/profile2/touch.txt" );
verifier.assertFileNotPresent( "target/profile3/touch.txt" );
verifier.assertFileNotPresent( "target/profile4/touch.txt" );
verifier.assertFileNotPresent( "target/profile5/touch.txt" );
verifier.resetStreams();
}
/**
* Test that deactivating from the command line takes priority over
* activating from the command line.
*
*/
public void testActivateThenDeactivate()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545-ProfileDeactivation" );
Verifier verifier;
verifier = new Verifier( testDir.getAbsolutePath() );
List cliOptions = new ArrayList();
// Activate then deactivate
cliOptions.add( "-Pprofile4" );
cliOptions.add( "-P-profile4" );
verifier.setCliOptions( cliOptions );
verifier.executeGoal( "package" );
verifier.verifyErrorFreeLog();
verifier.assertFilePresent( "target/profile1/touch.txt" );
verifier.assertFilePresent( "target/profile2/touch.txt" );
verifier.assertFileNotPresent( "target/profile3/touch.txt" );
verifier.assertFileNotPresent( "target/profile4/touch.txt" );
verifier.assertFileNotPresent( "target/profile5/touch.txt" );
verifier.resetStreams();
}
/**
* Test that default profiles are deactivated when another profile is
* activated.
*
*/
public void testDefaultProfileAutoDeactivation()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545-ProfileDeactivation" );
Verifier verifier;
verifier = new Verifier( testDir.getAbsolutePath() );
List cliOptions = new ArrayList();
// Activate
cliOptions.add( "-Pprofile4" );
verifier.setCliOptions( cliOptions );
verifier.executeGoal( "package" );
verifier.verifyErrorFreeLog();
verifier.assertFileNotPresent( "target/profile1/touch.txt" );
verifier.assertFileNotPresent( "target/profile2/touch.txt" );
verifier.assertFileNotPresent( "target/profile3/touch.txt" );
verifier.assertFilePresent( "target/profile4/touch.txt" );
verifier.assertFileNotPresent( "target/profile5/touch.txt" );
verifier.resetStreams();
}
/**
* remove the target dir after each test run
*/
public void tearDown()
throws IOException
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545-ProfileDeactivation" );
File targetDir = new File( testDir, "target" );
if ( targetDir.exists() )
{
targetDir.delete();
}
}
}

View File

@ -0,0 +1,154 @@
<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.mng3545</groupId>
<artifactId>test-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-touch</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>profile1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-touch</artifactId>
<executions>
<execution>
<id>profile1-touch</id>
<goals>
<goal>touch</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/profile1</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>profile2</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-touch</artifactId>
<executions>
<execution>
<id>profile2-touch</id>
<goals>
<goal>touch</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/profile2</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>profile3</id>
<activation>
<property>
<name>profile3-activation-property</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-touch</artifactId>
<executions>
<execution>
<id>profile3-touch</id>
<goals>
<goal>touch</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/profile3</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>profile4</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-touch</artifactId>
<executions>
<execution>
<id>profile4-touch</id>
<goals>
<goal>touch</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/profile4</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>profile5</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-touch</artifactId>
<executions>
<execution>
<id>profile5-touch</id>
<goals>
<goal>touch</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/profile5</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<!--remove when the IT plugins are actually release-->
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<url>http://people.apache.org/repo/m2-snapshot-repository</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</project>