001package org.apache.maven.project.artifact;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.repository.RepositorySystem;
023import org.codehaus.plexus.PlexusTestCase;
024
025public class MavenMetadataSourceTest
026    extends PlexusTestCase
027{
028    private RepositorySystem repositorySystem;
029
030    protected void setUp()
031        throws Exception
032    {
033        super.setUp();
034        repositorySystem = lookup( RepositorySystem.class );
035    }
036
037    @Override
038    protected void tearDown()
039        throws Exception
040    {
041        repositorySystem = null;
042        super.tearDown();
043    }
044
045    public void testShouldNotCarryExclusionsOverFromDependencyToDependency()
046        throws Exception
047    {
048        /*
049        Dependency dep1 = new Dependency();
050        dep1.setGroupId( "test" );
051        dep1.setArtifactId( "test-artifact" );
052        dep1.setVersion( "1" );
053        dep1.setType( "jar" );
054
055        Exclusion exc = new Exclusion();
056        exc.setGroupId( "test" );
057        exc.setArtifactId( "test-artifact3" );
058
059        dep1.addExclusion( exc );
060
061        Dependency dep2 = new Dependency();
062        dep2.setGroupId( "test" );
063        dep2.setArtifactId( "test-artifact2" );
064        dep2.setVersion( "1" );
065        dep2.setType( "jar" );
066
067        List deps = new ArrayList();
068        deps.add( dep1 );
069        deps.add( dep2 );
070
071        ArtifactFactory factory = lookup( ArtifactFactory.class );
072
073        ArtifactFilter dependencyFilter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
074
075        MavenProject project = new MavenProject( new Model() );
076
077        Set result = project.createArtifacts( dependencyFilter );
078
079        for ( Iterator it = result.iterator(); it.hasNext(); )
080        {
081            Artifact artifact = ( Artifact ) it.next();
082
083            if ( "test-artifact2".equals( artifact.getArtifactId() ) )
084            {
085                ArtifactFilter filter = artifact.getDependencyFilter();
086
087                assertSame( dependencyFilter, filter );
088            }
089        }
090        */
091    }
092
093    //TODO: restore these if it makes sense
094    /*
095    public void testShouldUseCompileScopeIfDependencyScopeEmpty()
096        throws Exception
097    {
098        String groupId = "org.apache.maven";
099        String artifactId = "maven-model";
100
101        Dependency dep = new Dependency();
102
103        dep.setGroupId( groupId );
104        dep.setArtifactId( artifactId );
105        dep.setVersion( "2.0-alpha-3" );
106
107        Model model = new Model();
108
109        model.addDependency( dep );
110
111        MavenProject project = new MavenProject( model, repositorySystem );
112
113        project.setArtifacts( project.createArtifacts( null ) );
114
115        String key = ArtifactUtils.versionlessKey( groupId, artifactId );
116
117        Map artifactMap = project.getArtifactMap();
118
119        assertNotNull( "artifact-map should not be null.", artifactMap );
120        assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
121
122        Artifact artifact = (Artifact) artifactMap.get( key );
123
124        assertNotNull( "dependency artifact not found in map.", artifact );
125        assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_COMPILE, artifact.getScope() );
126
127        //check for back-propagation of default scope.
128        assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_COMPILE, dep.getScope() );
129    }
130
131    public void testShouldUseInjectedTestScopeFromDependencyManagement()
132        throws Exception
133    {
134        String groupId = "org.apache.maven";
135        String artifactId = "maven-model";
136
137        Dependency dep = new Dependency();
138
139        dep.setGroupId( groupId );
140        dep.setArtifactId( artifactId );
141        dep.setVersion( "2.0-alpha-3" );
142
143        Model model = new Model();
144
145        model.addDependency( dep );
146
147        Dependency mgd = new Dependency();
148        mgd.setGroupId( groupId );
149        mgd.setArtifactId( artifactId );
150        mgd.setScope( Artifact.SCOPE_TEST );
151
152        DependencyManagement depMgmt = new DependencyManagement();
153
154        depMgmt.addDependency( mgd );
155
156        model.setDependencyManagement( depMgmt );
157
158        MavenProject project = new MavenProject( model, repositorySystem );
159
160        TestModelDefaultsInjector injector = new TestModelDefaultsInjector();
161
162        injector.injectDefaults( model );
163
164        project.setArtifacts( project.createArtifacts( null ) );
165
166        String key = ArtifactUtils.versionlessKey( groupId, artifactId );
167
168        Map artifactMap = project.getArtifactMap();
169
170        assertNotNull( "artifact-map should not be null.", artifactMap );
171        assertEquals( "artifact-map should contain 1 element.", 1, artifactMap.size() );
172
173        Artifact artifact = (Artifact) artifactMap.get( key );
174
175        assertNotNull( "dependency artifact not found in map.", artifact );
176        assertEquals( "dependency artifact has wrong scope.", Artifact.SCOPE_TEST, artifact.getScope() );
177
178        //check for back-propagation of default scope.
179        assertEquals( "default scope NOT back-propagated to dependency.", Artifact.SCOPE_TEST, dep.getScope() );
180    }
181    */
182
183}