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