001package org.apache.maven.repository.metadata;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
005 * agreements. See the NOTICE file distributed with this work for additional information regarding
006 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance with the License. You may obtain a
008 * copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed under the License
013 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
014 * or implied. See the License for the specific language governing permissions and limitations under
015 * the License.
016 */
017
018import org.apache.maven.artifact.ArtifactScopeEnum;
019import org.apache.maven.repository.metadata.ArtifactMetadata;
020import org.apache.maven.repository.metadata.ClasspathContainer;
021import org.apache.maven.repository.metadata.ClasspathTransformation;
022import org.apache.maven.repository.metadata.MetadataGraph;
023import org.apache.maven.repository.metadata.MetadataGraphEdge;
024import org.apache.maven.repository.metadata.MetadataGraphVertex;
025import org.codehaus.plexus.PlexusTestCase;
026
027/**
028 *
029 * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
030 *
031 */
032
033public class DefaultClasspathTransformationTest
034extends PlexusTestCase
035{
036        ClasspathTransformation transform;
037
038        MetadataGraph graph;
039
040        MetadataGraphVertex v1;
041        MetadataGraphVertex v2;
042        MetadataGraphVertex v3;
043        MetadataGraphVertex v4;
044    //------------------------------------------------------------------------------------------
045    @Override
046        protected void setUp() throws Exception
047        {
048                super.setUp();
049                transform = (ClasspathTransformation) lookup( ClasspathTransformation.ROLE, "default" );
050        
051        graph = new MetadataGraph( 4, 3 );
052        /*
053         *       v2
054         *   v1<
055         *       v3-v4
056         *
057         */
058        v1 = graph.addVertex(new ArtifactMetadata("g","a1","1.0"));
059        graph.setEntry(v1);
060        v2 = graph.addVertex(new ArtifactMetadata("g","a2","1.0"));
061        v3 = graph.addVertex(new ArtifactMetadata("g","a3","1.0"));
062        v4 = graph.addVertex(new ArtifactMetadata("g","a4","1.0"));
063        
064        // v1-->v2
065        graph.addEdge(v1, v2, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) );
066        graph.addEdge(v1, v2, new MetadataGraphEdge( "1.2", true, null, null, 2, 2 ) );
067        
068        // v1-->v3
069        graph.addEdge(v1, v3, new MetadataGraphEdge( "1.1", true, null, null, 2, 1 ) );
070        graph.addEdge(v1, v3, new MetadataGraphEdge( "1.2", true, null, null, 4, 2 ) );
071        
072        // v3-->v4
073        graph.addEdge(v3, v4, new MetadataGraphEdge( "1.1", true, ArtifactScopeEnum.runtime, null, 2, 2 ) );
074        graph.addEdge(v3, v4, new MetadataGraphEdge( "1.2", true, ArtifactScopeEnum.test, null, 2, 2 ) );
075        }
076    //------------------------------------------------------------------------------------------
077    public void testCompileClasspathTransform()
078    throws Exception
079    {
080        ClasspathContainer res;
081        
082        res = transform.transform( graph, ArtifactScopeEnum.compile, false );
083
084        assertNotNull("null classpath container after compile transform", res );
085        assertNotNull("null classpath after compile transform", res.getClasspath() );
086        assertEquals("compile classpath should have 3 entries", 3, res.getClasspath().size() );
087    }
088    //------------------------------------------------------------------------------------------
089    public void testRuntimeClasspathTransform()
090    throws Exception
091    {
092        ClasspathContainer res;
093        
094        res = transform.transform( graph, ArtifactScopeEnum.runtime, false );
095
096        assertNotNull("null classpath container after runtime transform", res );
097        assertNotNull("null classpath after runtime transform", res.getClasspath() );
098        assertEquals("runtime classpath should have 4 entries", 4, res.getClasspath().size() );
099        
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}