Adding tests to verify that super-POM is injected with active profiles when used in standalone fasion.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@421390 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2006-07-12 19:43:54 +00:00
parent cc859f5cfb
commit 0712f84f81
1 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,145 @@
package org.apache.maven.project;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
public class DefaultMavenProjectBuilderTest
extends PlexusTestCase
{
private List filesToDelete = new ArrayList();
private File localRepoDir;
private DefaultMavenProjectBuilder projectBuilder;
public void setUp()
throws Exception
{
super.setUp();
projectBuilder = (DefaultMavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
localRepoDir = new File( System.getProperty( "java.io.tmpdir" ), "local-repo." + System.currentTimeMillis() );
localRepoDir.mkdirs();
filesToDelete.add( localRepoDir );
}
public void tearDown()
throws Exception
{
super.tearDown();
if ( !filesToDelete.isEmpty() )
{
for ( Iterator it = filesToDelete.iterator(); it.hasNext(); )
{
File file = (File) it.next();
if ( file.exists() )
{
if ( file.isDirectory() )
{
FileUtils.deleteDirectory( file );
}
else
{
file.delete();
}
}
}
}
}
public void testShouldInjectOneProfileToStandaloneSuperPom()
throws Exception
{
ProfileManager pm = new DefaultProfileManager( getContainer(), new Properties() );
String profileId = "test-profile";
String key = "test";
String value = "value";
Profile profile = new Profile();
profile.setId( profileId );
profile.addProperty( key, value );
pm.addProfile( profile );
pm.explicitlyActivate( profileId );
MavenProject project = projectBuilder.buildStandaloneSuperProject( getLocalRepository(), pm );
assertEquals( value, project.getProperties().getProperty( key ) );
}
public void testShouldInjectProfileWithRepositoryToStandaloneSuperPom()
throws Exception
{
ProfileManager pm = new DefaultProfileManager( getContainer(), new Properties() );
String profileId = "test-profile";
String repoId = "test-repo";
Profile profile = new Profile();
profile.setId( profileId );
Repository repo = new Repository();
repo.setId( repoId );
repo.setUrl( "http://www.google.com" );
profile.addRepository( repo );
pm.addProfile( profile );
pm.explicitlyActivate( profileId );
MavenProject project = projectBuilder.buildStandaloneSuperProject( getLocalRepository(), pm );
List repositories = project.getRepositories();
assertNotNull( repositories );
Repository result = null;
for ( Iterator it = repositories.iterator(); it.hasNext(); )
{
Repository candidate = (Repository) it.next();
if ( repoId.equals( candidate.getId() ) )
{
result = candidate;
break;
}
}
assertNotNull( "Profile-injected repository not found in super-POM.", result );
assertEquals( "Profile-injected repository was not first in repo list within super-POM", repoId,
( (Repository) repositories.get( 0 ) ).getId() );
}
protected ArtifactRepository getLocalRepository()
throws Exception
{
ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE,
"legacy" );
ArtifactRepository r = new DefaultArtifactRepository( "local", "file://" + localRepoDir.getAbsolutePath(),
repoLayout );
return r;
}
}