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