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