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  
26  import java.lang.reflect.InvocationTargetException;
27  import java.util.Set;
28  
29  import org.apache.maven.artifact.Artifact;
30  import org.apache.maven.plugin.testing.ArtifactStubFactory;
31  
32  /**
33   * TestCases for GroupIdFilter
34   */
35  public class TestGroupIdFilter
36      extends AbstractArtifactFeatureFilterTestCase
37  {
38  
39      protected void setUp()
40          throws Exception
41      {
42          super.setUp();
43          filterClass = GroupIdFilter.class;
44          ArtifactStubFactory factory = new ArtifactStubFactory( null, false );
45          artifacts = factory.getGroupIdArtifacts();
46      }
47  
48      public void testParsing()
49          throws Exception
50      {
51          parsing();
52      }
53  
54      public void testFiltering()
55          throws Exception
56      {
57          Set<Artifact> result = filtering();
58          for ( Artifact artifact : result )
59          {
60              assertTrue( artifact.getGroupId().equals( "one" ) || artifact.getGroupId().equals( "two" ) );
61          }
62      }
63  
64      public void testFiltering2()
65          throws Exception
66      {
67          Set<Artifact> result = filtering2();
68          for ( Artifact artifact : result )
69          {
70              assertTrue( artifact.getGroupId().equals( "two" ) || artifact.getGroupId().equals( "four" ) );
71          }
72      }
73  
74      public void testFiltering3()
75          throws Exception
76      {
77          filtering3();
78      }
79  
80      public void testFiltering4()
81          throws Exception
82      {
83          // include o* from groupIds one,two should leave one
84          Set<Artifact> result = filtering();
85          assertEquals( 1, result.size() );
86          GroupIdFilter filter = new GroupIdFilter( "o", null );
87          result = filter.filter( result );
88          for ( Artifact artifact : result )
89          {
90              assertTrue( artifact.getGroupId().equals( "one" ) );
91  
92          }
93  
94          // exclude on* from groupIds one,two should leave two
95          result = filtering();
96          assertEquals( 1, result.size() );
97          filter = new GroupIdFilter( null, "on" );
98          result = filter.filter( result );
99          for ( Artifact artifact : result )
100         {
101             assertTrue( artifact.getGroupId().equals( "two" ) );
102 
103         }
104     }
105 
106     public void testMultipleInclude()
107         throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException,
108         IllegalAccessException, InvocationTargetException, ArtifactFilterException
109     {
110         ArtifactsFilter filter = new GroupIdFilter( "one,two", null );
111 
112         assertEquals( 4, artifacts.size() );
113 
114         Set<Artifact> result = filter.filter( artifacts );
115 
116         assertEquals( 2, result.size() );
117     }
118 
119     public void testMultipleExclude()
120         throws SecurityException, IllegalArgumentException, NoSuchMethodException, InstantiationException,
121         IllegalAccessException, InvocationTargetException, ArtifactFilterException
122     {
123         ArtifactsFilter filter = new GroupIdFilter( null, "one,two" );
124 
125         assertEquals( 4, artifacts.size() );
126 
127         Set<Artifact> result = filter.filter( artifacts );
128 
129         assertEquals( 2, result.size() );
130     }
131 }