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