From d2fc2882712d219c2e3ac8af1775b91cafbf02ce Mon Sep 17 00:00:00 2001 From: Herve Boutemy Date: Sun, 11 Nov 2012 23:18:04 +0000 Subject: [PATCH] added readArtifactDescriptor() API test git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1408144 13f79535-47bb-0310-9956-ffa450edef68 --- .../internal/RepositorySystemTest.java | 68 ++++++++++++------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/maven-aether-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java b/maven-aether-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java index 896d393a24..e1ac5898a7 100644 --- a/maven-aether-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java +++ b/maven-aether-provider/src/test/java/org/apache/maven/repository/internal/RepositorySystemTest.java @@ -19,10 +19,15 @@ package org.apache.maven.repository.internal; * under the License. */ +import java.util.List; + import org.sonatype.aether.artifact.Artifact; import org.sonatype.aether.collection.CollectRequest; import org.sonatype.aether.collection.CollectResult; import org.sonatype.aether.graph.Dependency; +import org.sonatype.aether.graph.DependencyNode; +import org.sonatype.aether.resolution.ArtifactDescriptorRequest; +import org.sonatype.aether.resolution.ArtifactDescriptorResult; import org.sonatype.aether.resolution.ArtifactRequest; import org.sonatype.aether.resolution.ArtifactResult; import org.sonatype.aether.util.artifact.DefaultArtifact; @@ -48,28 +53,28 @@ public class RepositorySystemTest public void testReadArtifactDescriptor() throws Exception { - //ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession session, ArtifactDescriptorRequest request ) - // throws ArtifactDescriptorException; + Artifact artifact = new DefaultArtifact( "ut.simple:artifact:extension:classifier:1.0" ); + + ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(); + request.setArtifact( artifact ); + request.addRepository( newTestRepository() ); + + ArtifactDescriptorResult result = system.readArtifactDescriptor( session, request ); + + List deps = result.getDependencies(); + assertEquals( 2, deps.size() ); + checkUtSimpleArtifactDependencies( deps.get( 0 ), deps.get( 1 ) ); } - public void testCollectDependencies() - throws Exception + /** + * check ut.simple:artifact:1.0 dependencies + */ + private void checkUtSimpleArtifactDependencies( Dependency dep1, Dependency dep2 ) { - Artifact artifact = new DefaultArtifact( "ut.simple:artifact:extension:classifier:1.0" ); - // notice: extension and classifier not really used in this test... - - CollectRequest collectRequest = new CollectRequest(); - collectRequest.setRoot( new Dependency( artifact, null ) ); - collectRequest.addRepository( newTestRepository() ); - - CollectResult collectResult = system.collectDependencies( session, collectRequest ); - - assertEquals( 2, collectResult.getRoot().getChildren().size() ); - Dependency dep = collectResult.getRoot().getChildren().get( 0 ).getDependency(); - assertEquals( "compile", dep.getScope() ); - assertFalse( dep.isOptional() ); - assertEquals( 0, dep.getExclusions().size() ); - Artifact depArtifact = dep.getArtifact(); + assertEquals( "compile", dep1.getScope() ); + assertFalse( dep1.isOptional() ); + assertEquals( 0, dep1.getExclusions().size() ); + Artifact depArtifact = dep1.getArtifact(); assertEquals( "ut.simple", depArtifact.getGroupId() ); assertEquals( "dependency", depArtifact.getArtifactId() ); assertEquals( "1.0", depArtifact.getVersion() ); @@ -84,11 +89,10 @@ public class RepositorySystemTest assertEquals( "false", depArtifact.getProperty( "includesDependencies", null ) ); assertEquals( 4, depArtifact.getProperties().size() ); - dep = collectResult.getRoot().getChildren().get( 1 ).getDependency(); - assertEquals( "compile", dep.getScope() ); - assertFalse( dep.isOptional() ); - assertEquals( 0, dep.getExclusions().size() ); - depArtifact = dep.getArtifact(); + assertEquals( "compile", dep2.getScope() ); + assertFalse( dep2.isOptional() ); + assertEquals( 0, dep2.getExclusions().size() ); + depArtifact = dep2.getArtifact(); assertEquals( "ut.simple", depArtifact.getGroupId() ); assertEquals( "dependency", depArtifact.getArtifactId() ); assertEquals( "1.0", depArtifact.getVersion() ); @@ -103,6 +107,22 @@ public class RepositorySystemTest assertEquals( "false", depArtifact.getProperty( "includesDependencies", null ) ); assertEquals( 4, depArtifact.getProperties().size() ); } + public void testCollectDependencies() + throws Exception + { + Artifact artifact = new DefaultArtifact( "ut.simple:artifact:extension:classifier:1.0" ); + // notice: extension and classifier not really used in this test... + + CollectRequest collectRequest = new CollectRequest(); + collectRequest.setRoot( new Dependency( artifact, null ) ); + collectRequest.addRepository( newTestRepository() ); + + CollectResult collectResult = system.collectDependencies( session, collectRequest ); + + List nodes = collectResult.getRoot().getChildren(); + assertEquals( 2, nodes.size() ); + checkUtSimpleArtifactDependencies( nodes.get( 0 ).getDependency(), nodes.get( 1 ).getDependency() ); + } public void testResolveArtifact() throws Exception