View Javadoc
1   package org.apache.maven.shared.artifact.filter.collection;
2   
3   /* 
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  /**
22   * 
23   */
24  
25  import java.util.Set;
26  
27  import junit.framework.TestCase;
28  
29  import org.apache.maven.artifact.Artifact;
30  import org.apache.maven.plugin.testing.ArtifactStubFactory;
31  
32  /**
33   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
34   */
35  public class TestProjectTransitivityFilter
36      extends TestCase
37  {
38      Set<Artifact> artifacts;
39  
40      Set<Artifact> directArtifacts;
41      
42      Set<Artifact> classifiedArtifacts;
43  
44      protected void setUp()
45          throws Exception
46      {
47          super.setUp();
48  
49          ArtifactStubFactory fact = new ArtifactStubFactory( null, false );
50          artifacts = fact.getScopedArtifacts();
51          directArtifacts = fact.getReleaseAndSnapshotArtifacts();
52          classifiedArtifacts = fact.getClassifiedArtifacts();
53          artifacts.addAll( directArtifacts );
54          artifacts.addAll( classifiedArtifacts );
55      }
56  
57      public void testAll()
58      {
59          ProjectTransitivityFilter filter = new ProjectTransitivityFilter( directArtifacts, false );
60  
61          Set<Artifact> result = filter.filter( artifacts );
62  
63          assertEquals( 11, result.size() );
64      }
65  
66      public void testExclude()
67      {
68          ProjectTransitivityFilter filter = new ProjectTransitivityFilter( directArtifacts, false );
69          assertFalse( filter.isExcludeTransitive() );
70          filter.setExcludeTransitive( true );
71          assertTrue( filter.isExcludeTransitive() );
72          Set<Artifact> result = filter.filter( artifacts );
73  
74          assertEquals( 2, result.size() );
75  
76          for ( Artifact artifact : result )
77          {
78              assertTrue( artifact.getArtifactId().equals( "release" ) || artifact.getArtifactId().equals( "snapshot" ) );
79          }
80      }
81  
82      public void testClassified()
83      {
84          ProjectTransitivityFilter filter = new ProjectTransitivityFilter( classifiedArtifacts, true );
85  
86          Set<Artifact> result = filter.filter( artifacts );
87  
88          assertEquals( 4, result.size() );
89      }
90  
91  }