001package org.eclipse.aether.internal.impl.collect.bf;
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 java.util.Arrays;
023import java.util.Collection;
024import java.util.Collections;
025import java.util.List;
026
027import org.eclipse.aether.artifact.DefaultArtifact;
028import org.eclipse.aether.collection.CollectRequest;
029import org.eclipse.aether.collection.CollectResult;
030import org.eclipse.aether.collection.DependencyCollectionException;
031import org.eclipse.aether.graph.Dependency;
032import org.eclipse.aether.graph.Exclusion;
033import org.eclipse.aether.internal.impl.StubRemoteRepositoryManager;
034import org.eclipse.aether.internal.impl.StubVersionRangeResolver;
035import org.eclipse.aether.internal.impl.collect.DependencyCollectorDelegateTestSupport;
036import org.eclipse.aether.internal.test.util.DependencyGraphParser;
037import org.eclipse.aether.util.graph.manager.TransitiveDependencyManager;
038import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
039import org.junit.Assume;
040import org.junit.Test;
041import org.junit.runner.RunWith;
042import org.junit.runners.Parameterized;
043
044import static org.junit.Assert.assertEquals;
045
046/**
047 * UT for {@link BfDependencyCollector}.
048 */
049@RunWith( Parameterized.class )
050public class BfDependencyCollectorTest extends DependencyCollectorDelegateTestSupport
051{
052    @Parameterized.Parameters
053    public static List<Boolean> parameters()
054    {
055        return Arrays.asList( Boolean.TRUE, Boolean.FALSE );
056    }
057
058    @Parameterized.Parameter
059    public boolean useSkipper;
060
061    @Override
062    protected void setupCollector()
063    {
064        session.setConfigProperty( BfDependencyCollector.CONFIG_PROP_SKIPPER, useSkipper );
065
066        collector = new BfDependencyCollector();
067        collector.setArtifactDescriptorReader( newReader( "" ) );
068        collector.setVersionRangeResolver( new StubVersionRangeResolver() );
069        collector.setRemoteRepositoryManager( new StubRemoteRepositoryManager() );
070    }
071
072    private Dependency newDep( String coords, String scope, Collection<Exclusion> exclusions )
073    {
074        Dependency d = new Dependency( new DefaultArtifact( coords ), scope );
075        return d.setExclusions( exclusions );
076    }
077
078    @Test
079    public void testSkipperWithDifferentExclusion() throws DependencyCollectionException
080    {
081        Assume.assumeTrue( useSkipper );
082        collector.setArtifactDescriptorReader( newReader( "managed/" ) );
083        parser = new DependencyGraphParser( "artifact-descriptions/managed/" );
084        session.setDependencyManager( new TransitiveDependencyManager() );
085
086        ExclusionDependencySelector exclSel1 = new ExclusionDependencySelector();
087        session.setDependencySelector( exclSel1 );
088
089        Dependency root1 = newDep( "gid:root:ext:ver", "compile",
090                Collections.singleton( new Exclusion( "gid", "transitive-1", "", "ext" ) ) );
091        Dependency root2 = newDep( "gid:root:ext:ver", "compile",
092                Collections.singleton( new Exclusion( "gid", "transitive-2", "", "ext" ) ) );
093        List<Dependency> dependencies = Arrays.asList( root1, root2 );
094
095        CollectRequest request = new CollectRequest( dependencies, null, Arrays.asList( repository ) );
096        request.addManagedDependency( newDep( "gid:direct:ext:managed-by-dominant-request" ) );
097        request.addManagedDependency( newDep( "gid:transitive-1:ext:managed-by-root" ) );
098
099        CollectResult result = collector.collectDependencies( session, request );
100        assertEquals( 0, result.getExceptions().size() );
101        assertEquals( 2, result.getRoot().getChildren().size() );
102        assertEquals( root1, dep( result.getRoot(), 0 ) );
103        assertEquals( root2, dep( result.getRoot(), 1 ) );
104        //the winner has transitive-1 excluded
105        assertEquals( 1, path( result.getRoot(), 0 ).getChildren().size() );
106        assertEquals( 0, path( result.getRoot(), 0, 0 ).getChildren().size() );
107        //skipped
108        assertEquals( 0, path( result.getRoot(), 1 ).getChildren().size() );
109    }
110
111}