001 package org.apache.maven.repository.metadata; 002 003 import org.apache.maven.artifact.ArtifactScopeEnum; 004 import org.apache.maven.repository.metadata.ArtifactMetadata; 005 import org.apache.maven.repository.metadata.ClasspathContainer; 006 import org.apache.maven.repository.metadata.ClasspathTransformation; 007 import org.apache.maven.repository.metadata.MetadataGraph; 008 import org.apache.maven.repository.metadata.MetadataGraphEdge; 009 import org.apache.maven.repository.metadata.MetadataGraphVertex; 010 import org.codehaus.plexus.PlexusTestCase; 011 012 /** 013 * 014 * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> 015 * 016 */ 017 018 public class DefaultClasspathTransformationTest 019 extends PlexusTestCase 020 { 021 ClasspathTransformation transform; 022 023 MetadataGraph graph; 024 025 MetadataGraphVertex v1; 026 MetadataGraphVertex v2; 027 MetadataGraphVertex v3; 028 MetadataGraphVertex v4; 029 //------------------------------------------------------------------------------------------ 030 @Override 031 protected void setUp() throws Exception 032 { 033 super.setUp(); 034 transform = (ClasspathTransformation) lookup( ClasspathTransformation.ROLE, "default" ); 035 036 graph = new MetadataGraph( 4, 3 ); 037 /* 038 * v2 039 * v1< 040 * v3-v4 041 * 042 */ 043 v1 = graph.addVertex(new ArtifactMetadata("g","a1","1.0")); 044 graph.setEntry(v1); 045 v2 = graph.addVertex(new ArtifactMetadata("g","a2","1.0")); 046 v3 = graph.addVertex(new ArtifactMetadata("g","a3","1.0")); 047 v4 = graph.addVertex(new ArtifactMetadata("g","a4","1.0")); 048 049 // v1-->v2 050 graph.addEdge(v1, v2, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) ); 051 graph.addEdge(v1, v2, new MetadataGraphEdge( "1.2", true, null, null, 2, 2 ) ); 052 053 // v1-->v3 054 graph.addEdge(v1, v3, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) ); 055 graph.addEdge(v1, v3, new MetadataGraphEdge( "1.2", true, null, null, 4, 2 ) ); 056 057 // v3-->v4 058 graph.addEdge(v3, v4, new MetadataGraphEdge( "1.1", true, ArtifactScopeEnum.runtime, null, 2, 2 ) ); 059 graph.addEdge(v3, v4, new MetadataGraphEdge( "1.2", true, ArtifactScopeEnum.test, null, 2, 2 ) ); 060 } 061 //------------------------------------------------------------------------------------------ 062 public void testCompileClasspathTransform() 063 throws Exception 064 { 065 ClasspathContainer res; 066 067 res = transform.transform( graph, ArtifactScopeEnum.compile, false ); 068 069 assertNotNull("null classpath container after compile transform", res ); 070 assertNotNull("null classpath after compile transform", res.getClasspath() ); 071 assertEquals("compile classpath should have 3 entries", 3, res.getClasspath().size() ); 072 } 073 //------------------------------------------------------------------------------------------ 074 public void testRuntimeClasspathTransform() 075 throws Exception 076 { 077 ClasspathContainer res; 078 079 res = transform.transform( graph, ArtifactScopeEnum.runtime, false ); 080 081 assertNotNull("null classpath container after runtime transform", res ); 082 assertNotNull("null classpath after runtime transform", res.getClasspath() ); 083 assertEquals("runtime classpath should have 4 entries", 4, res.getClasspath().size() ); 084 085 ArtifactMetadata md = res.getClasspath().get(3); 086 assertEquals("runtime artifact version should be 1.1", "1.1", md.getVersion() ); 087 } 088 //------------------------------------------------------------------------------------------ 089 public void testTestClasspathTransform() 090 throws Exception 091 { 092 ClasspathContainer res; 093 094 res = transform.transform( graph, ArtifactScopeEnum.test, false ); 095 096 assertNotNull("null classpath container after runtime transform", res ); 097 assertNotNull("null classpath after runtime transform", res.getClasspath() ); 098 assertEquals("runtime classpath should have 4 entries", 4, res.getClasspath().size() ); 099 100 ArtifactMetadata md = res.getClasspath().get(3); 101 assertEquals("test artifact version should be 1.2", "1.2", md.getVersion() ); 102 } 103 //------------------------------------------------------------------------------------------ 104 //------------------------------------------------------------------------------------------ 105 }