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.List;
28  import java.util.Set;
29  
30  import junit.framework.TestCase;
31  
32  import org.apache.maven.artifact.Artifact;
33  import org.apache.maven.plugin.testing.ArtifactStubFactory;
34  
35  /**
36   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
37   */
38  public class TestTypeFilter
39      extends TestCase
40  {
41      Set artifacts = new HashSet();
42  
43      protected void setUp()
44          throws Exception
45      {
46          super.setUp();
47  
48          ArtifactStubFactory factory = new ArtifactStubFactory( null, false );
49          artifacts = factory.getTypedArtifacts();
50      }
51  
52      public void testTypeParsing()
53      {
54          TypeFilter filter = new TypeFilter( "war,jar", "sources,zip," );
55          List includes = filter.getIncludes();
56          List excludes = filter.getExcludes();
57  
58          assertEquals( 2, includes.size() );
59          assertEquals( 2, excludes.size() );
60          assertEquals( "war", includes.get( 0 ).toString() );
61          assertEquals( "jar", includes.get( 1 ).toString() );
62          assertEquals( "sources", excludes.get( 0 ).toString() );
63          assertEquals( "zip", excludes.get( 1 ).toString() );
64      }
65  
66      public void testFiltering()
67      {
68          TypeFilter filter = new TypeFilter( "war,jar", "war,zip," );
69          Set result = filter.filter( artifacts );
70          assertEquals( 1, result.size() );
71  
72          Iterator iter = result.iterator();
73          while ( iter.hasNext() )
74          {
75              Artifact artifact = (Artifact) iter.next();
76              assertTrue( artifact.getType().equals( "jar" ) );
77          }
78      }
79  
80      public void testFiltering2()
81      {
82          TypeFilter filter = new TypeFilter( null, "war,jar," );
83          Set result = filter.filter( artifacts );
84          assertEquals( 3, result.size() );
85  
86          Iterator iter = result.iterator();
87          while ( iter.hasNext() )
88          {
89              Artifact artifact = (Artifact) iter.next();
90              assertTrue( !artifact.getType().equals( "war" ) && !artifact.getType().equals( "jar" ) );
91          }
92      }
93  
94      public void testFiltering3()
95      {
96          TypeFilter filter = new TypeFilter( null, null );
97          Set result = filter.filter( artifacts );
98          assertEquals( 5, result.size() );
99      }
100 }