1 package org.apache.maven.repository.metadata;
2
3 import org.apache.maven.artifact.ArtifactScopeEnum;
4 import org.apache.maven.repository.metadata.ArtifactMetadata;
5 import org.apache.maven.repository.metadata.ClasspathContainer;
6 import org.apache.maven.repository.metadata.ClasspathTransformation;
7 import org.apache.maven.repository.metadata.MetadataGraph;
8 import org.apache.maven.repository.metadata.MetadataGraphEdge;
9 import org.apache.maven.repository.metadata.MetadataGraphVertex;
10 import org.codehaus.plexus.PlexusTestCase;
11
12
13
14
15
16
17
18 public class DefaultClasspathTransformationTest
19 extends PlexusTestCase
20 {
21 ClasspathTransformation transform;
22
23 MetadataGraph graph;
24
25 MetadataGraphVertex v1;
26 MetadataGraphVertex v2;
27 MetadataGraphVertex v3;
28 MetadataGraphVertex v4;
29
30 @Override
31 protected void setUp() throws Exception
32 {
33 super.setUp();
34 transform = (ClasspathTransformation) lookup( ClasspathTransformation.ROLE, "default" );
35
36 graph = new MetadataGraph( 4, 3 );
37
38
39
40
41
42
43 v1 = graph.addVertex(new ArtifactMetadata("g","a1","1.0"));
44 graph.setEntry(v1);
45 v2 = graph.addVertex(new ArtifactMetadata("g","a2","1.0"));
46 v3 = graph.addVertex(new ArtifactMetadata("g","a3","1.0"));
47 v4 = graph.addVertex(new ArtifactMetadata("g","a4","1.0"));
48
49
50 graph.addEdge(v1, v2, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) );
51 graph.addEdge(v1, v2, new MetadataGraphEdge( "1.2", true, null, null, 2, 2 ) );
52
53
54 graph.addEdge(v1, v3, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) );
55 graph.addEdge(v1, v3, new MetadataGraphEdge( "1.2", true, null, null, 4, 2 ) );
56
57
58 graph.addEdge(v3, v4, new MetadataGraphEdge( "1.1", true, ArtifactScopeEnum.runtime, null, 2, 2 ) );
59 graph.addEdge(v3, v4, new MetadataGraphEdge( "1.2", true, ArtifactScopeEnum.test, null, 2, 2 ) );
60 }
61
62 public void testCompileClasspathTransform()
63 throws Exception
64 {
65 ClasspathContainer res;
66
67 res = transform.transform( graph, ArtifactScopeEnum.compile, false );
68
69 assertNotNull("null classpath container after compile transform", res );
70 assertNotNull("null classpath after compile transform", res.getClasspath() );
71 assertEquals("compile classpath should have 3 entries", 3, res.getClasspath().size() );
72 }
73
74 public void testRuntimeClasspathTransform()
75 throws Exception
76 {
77 ClasspathContainer res;
78
79 res = transform.transform( graph, ArtifactScopeEnum.runtime, false );
80
81 assertNotNull("null classpath container after runtime transform", res );
82 assertNotNull("null classpath after runtime transform", res.getClasspath() );
83 assertEquals("runtime classpath should have 4 entries", 4, res.getClasspath().size() );
84
85 ArtifactMetadata md = res.getClasspath().get(3);
86 assertEquals("runtime artifact version should be 1.1", "1.1", md.getVersion() );
87 }
88
89 public void testTestClasspathTransform()
90 throws Exception
91 {
92 ClasspathContainer res;
93
94 res = transform.transform( graph, ArtifactScopeEnum.test, false );
95
96 assertNotNull("null classpath container after runtime transform", res );
97 assertNotNull("null classpath after runtime transform", res.getClasspath() );
98 assertEquals("runtime classpath should have 4 entries", 4, res.getClasspath().size() );
99
100 ArtifactMetadata md = res.getClasspath().get(3);
101 assertEquals("test artifact version should be 1.2", "1.2", md.getVersion() );
102 }
103
104
105 }