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.HashSet;
26  import java.util.Iterator;
27  import java.util.Set;
28  
29  import junit.framework.TestCase;
30  
31  import org.apache.maven.artifact.Artifact;
32  import org.apache.maven.plugin.testing.ArtifactStubFactory;
33  
34  /**
35   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
36   */
37  public class TestProjectTransitivityFilter
38      extends TestCase
39  {
40      Set artifacts = new HashSet();
41  
42      Set directArtifacts = new HashSet();
43      
44      Set classifiedArtifacts = new HashSet();
45  
46      protected void setUp()
47          throws Exception
48      {
49          super.setUp();
50  
51          ArtifactStubFactory fact = new ArtifactStubFactory( null, false );
52          artifacts = fact.getScopedArtifacts();
53          directArtifacts = fact.getReleaseAndSnapshotArtifacts();
54          classifiedArtifacts = fact.getClassifiedArtifacts();
55          artifacts.addAll( directArtifacts );
56          artifacts.addAll( classifiedArtifacts );
57      }
58  
59      public void testAll()
60      {
61          ProjectTransitivityFilter filter = new ProjectTransitivityFilter( directArtifacts, false );
62  
63          Set result = filter.filter( artifacts );
64  
65          assertEquals( 11, result.size() );
66      }
67  
68      public void testExclude()
69      {
70          ProjectTransitivityFilter filter = new ProjectTransitivityFilter( directArtifacts, false );
71          assertFalse( filter.isExcludeTransitive() );
72          filter.setExcludeTransitive( true );
73          assertTrue( filter.isExcludeTransitive() );
74          Set result = filter.filter( artifacts );
75  
76          assertEquals( 2, result.size() );
77  
78          Iterator iter = result.iterator();
79          while ( iter.hasNext() )
80          {
81              Artifact artifact = (Artifact) iter.next();
82              assertTrue( artifact.getArtifactId().equals( "release" ) || artifact.getArtifactId().equals( "snapshot" ) );
83          }
84      }
85  
86      public void testClassified()
87      {
88          ProjectTransitivityFilter filter = new ProjectTransitivityFilter( classifiedArtifacts, true );
89  
90          Set result = filter.filter( artifacts );
91  
92          assertEquals( 4, result.size() );
93      }
94  
95  }