View Javadoc
1   package org.apache.maven.repository.metadata;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * 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, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
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   * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
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      	 *       v2
54      	 *   v1<
55      	 *       v3-v4
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      	// v1-->v2
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      	// v1-->v3
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      	// v3-->v4
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 }