o Created UT from MNG-3821

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@728654 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2008-12-22 11:48:10 +00:00
parent edb695cff5
commit 3ce9917532
3 changed files with 138 additions and 11 deletions

View File

@ -14,12 +14,15 @@ import org.codehaus.plexus.PlexusTestCase;
public class PomConstructionTest
extends PlexusTestCase
{
private static String BASE_POM_DIR = "src/test/resources-project-builder";
private ProjectBuilder projectBuilder;
private MavenTools mavenTools;
private PomArtifactResolver pomArtifactResolver;
private File testDirectory;
protected void setUp()
@ -28,6 +31,16 @@ public class PomConstructionTest
testDirectory = new File( getBasedir(), BASE_POM_DIR );
projectBuilder = lookup( ProjectBuilder.class );
mavenTools = lookup( MavenTools.class );
pomArtifactResolver = new PomArtifactResolver()
{
public void resolve( Artifact artifact )
throws IOException
{
throw new IllegalStateException( "Parent POM should be locally reachable " + artifact );
}
};
}
// Some better conventions for the test poms needs to be created and each of these tests
@ -45,7 +58,7 @@ public class PomConstructionTest
assertEquals( 3, model.getLineageCount() );
PomTestWrapper pom = new PomTestWrapper( model );
assertModelEquals( pom, "maven-dependency-plugin", "build/plugins[4]/artifactId" );
List executions = (List) pom.getValue( "build/plugins[4]/executions" );
List<?> executions = (List<?>) pom.getValue( "build/plugins[4]/executions" );
assertEquals( 7, executions.size() );
}
@ -68,14 +81,40 @@ public class PomConstructionTest
PomArtifactResolver resolver = artifactResolver( "single-test-poms" );
PomClassicDomainModel model = projectBuilder.buildModel( pomFile, null, resolver );
PomTestWrapper pom = new PomTestWrapper( model );
List dependencies = (List) pom.getValue( "build/plugins[1]/dependencies" );
List<?> dependencies = (List<?>) pom.getValue( "build/plugins[1]/dependencies" );
assertEquals( 1, dependencies.size() );
}
/* FIXME: cf. MNG-3821
public void testErroneousJoiningOfDifferentPluginsWithEqualExecutionIds()
throws Exception
{
PomTestWrapper pom = buildPom( "equal-plugin-exec-ids" );
assertEquals( "maven-it-plugin-a", pom.getValue( "build/plugins[1]/artifactId" ) );
assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
assertEquals( "maven-it-plugin-b", pom.getValue( "build/plugins[2]/artifactId" ) );
assertEquals( 1, ( (List<?>) pom.getValue( "build/plugins[1]/executions" ) ).size() );
assertEquals( "maven-it-plugin-a", pom.getValue( "reporting/plugins[1]/artifactId" ) );
assertEquals( 1, ( (List<?>) pom.getValue( "reporting/plugins[1]/reportSets" ) ).size() );
assertEquals( "maven-it-plugin-b", pom.getValue( "reporting/plugins[2]/artifactId" ) );
assertEquals( 1, ( (List<?>) pom.getValue( "reporting/plugins[1]/reportSets" ) ).size() );
}
*/
private PomArtifactResolver artifactResolver( String basedir )
{
PomArtifactResolver resolver = new FileBasedPomArtifactResolver( new File( BASE_POM_DIR, basedir ) );
return resolver;
return new FileBasedPomArtifactResolver( new File( BASE_POM_DIR, basedir ) );
}
private PomTestWrapper buildPom( String pomPath )
throws IOException
{
File pomFile = new File( testDirectory, pomPath );
if ( pomFile.isDirectory() )
{
pomFile = new File( pomFile, "pom.xml" );
}
return new PomTestWrapper( projectBuilder.buildModel( pomFile, null, pomArtifactResolver ) );
}
protected void assertModelEquals( PomTestWrapper pom, Object expected, String expression )

View File

@ -44,6 +44,11 @@ public class PomTestWrapper {
context = JXPathContext.newContext(domainModel.getModel());
}
public PomClassicDomainModel getDomainModel()
{
return this.domainModel;
}
public String getValueOfProjectUri(String projectUri, boolean withResolvedValue) throws IOException {
if(projectUri.contains("#collection") || projectUri.contains("#set")) {
throw new IllegalArgumentException("projectUri: contains a collection or set");
@ -65,7 +70,7 @@ public class PomTestWrapper {
}
*/
public Iterator getIteratorForXPathExpression(String expression) {
public Iterator<?> getIteratorForXPathExpression(String expression) {
return context.iterate(expression);
}

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3821</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Maven Integration Test :: MNG-3821</name>
<description>
Verify that using the same id for executions/reportsets of different plugins doesn't blow up the project builder.
</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-a</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>the-one-and-only-id</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-b</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>the-one-and-only-id</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-a</artifactId>
<version>1.0-SNAPSHOT</version>
<reportSets>
<reportSet>
<id>the-one-and-only-id</id>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-b</artifactId>
<version>1.0-SNAPSHOT</version>
<reportSets>
<reportSet>
<id>the-one-and-only-id</id>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>