View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.repository.metadata;
20  
21  import org.apache.maven.artifact.ArtifactScopeEnum;
22  import org.codehaus.plexus.PlexusTestCase;
23  
24  /**
25   *
26   * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
27   *
28   */
29  public class DefaultClasspathTransformationTest extends PlexusTestCase {
30      ClasspathTransformation transform;
31  
32      MetadataGraph graph;
33  
34      MetadataGraphVertex v1;
35      MetadataGraphVertex v2;
36      MetadataGraphVertex v3;
37      MetadataGraphVertex v4;
38      // ------------------------------------------------------------------------------------------
39      @Override
40      protected void setUp() throws Exception {
41          super.setUp();
42          transform = (ClasspathTransformation) lookup(ClasspathTransformation.ROLE, "default");
43  
44          graph = new MetadataGraph(4, 3);
45          /*
46           *       v2
47           *   v1<
48           *       v3-v4
49           *
50           */
51          v1 = graph.addVertex(new ArtifactMetadata("g", "a1", "1.0"));
52          graph.setEntry(v1);
53          v2 = graph.addVertex(new ArtifactMetadata("g", "a2", "1.0"));
54          v3 = graph.addVertex(new ArtifactMetadata("g", "a3", "1.0"));
55          v4 = graph.addVertex(new ArtifactMetadata("g", "a4", "1.0"));
56  
57          // v1-->v2
58          graph.addEdge(v1, v2, new MetadataGraphEdge("1.1", true, null, null, 2, 1));
59          graph.addEdge(v1, v2, new MetadataGraphEdge("1.2", true, null, null, 2, 2));
60  
61          // v1-->v3
62          graph.addEdge(v1, v3, new MetadataGraphEdge("1.1", true, null, null, 2, 1));
63          graph.addEdge(v1, v3, new MetadataGraphEdge("1.2", true, null, null, 4, 2));
64  
65          // v3-->v4
66          graph.addEdge(v3, v4, new MetadataGraphEdge("1.1", true, ArtifactScopeEnum.runtime, null, 2, 2));
67          graph.addEdge(v3, v4, new MetadataGraphEdge("1.2", true, ArtifactScopeEnum.test, null, 2, 2));
68      }
69      // ------------------------------------------------------------------------------------------
70      public void testCompileClasspathTransform() throws Exception {
71          ClasspathContainer res;
72  
73          res = transform.transform(graph, ArtifactScopeEnum.compile, false);
74  
75          assertNotNull("null classpath container after compile transform", res);
76          assertNotNull("null classpath after compile transform", res.getClasspath());
77          assertEquals(
78                  "compile classpath should have 3 entries", 3, res.getClasspath().size());
79      }
80      // ------------------------------------------------------------------------------------------
81      public void testRuntimeClasspathTransform() throws Exception {
82          ClasspathContainer res;
83  
84          res = transform.transform(graph, ArtifactScopeEnum.runtime, false);
85  
86          assertNotNull("null classpath container after runtime transform", res);
87          assertNotNull("null classpath after runtime transform", res.getClasspath());
88          assertEquals(
89                  "runtime classpath should have 4 entries", 4, res.getClasspath().size());
90  
91          ArtifactMetadata md = res.getClasspath().get(3);
92          assertEquals("runtime artifact version should be 1.1", "1.1", md.getVersion());
93      }
94      // ------------------------------------------------------------------------------------------
95      public void testTestClasspathTransform() throws Exception {
96          ClasspathContainer res;
97  
98          res = transform.transform(graph, ArtifactScopeEnum.test, false);
99  
100         assertNotNull("null classpath container after runtime transform", res);
101         assertNotNull("null classpath after runtime transform", res.getClasspath());
102         assertEquals(
103                 "runtime classpath should have 4 entries", 4, res.getClasspath().size());
104 
105         ArtifactMetadata md = res.getClasspath().get(3);
106         assertEquals("test artifact version should be 1.2", "1.2", md.getVersion());
107     }
108     // ------------------------------------------------------------------------------------------
109     // ------------------------------------------------------------------------------------------
110 }