1 package org.apache.maven.shared.artifact.filter.collection;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.util.Set;
26
27 import junit.framework.TestCase;
28
29 import org.apache.maven.artifact.Artifact;
30 import org.apache.maven.plugin.logging.Log;
31 import org.apache.maven.plugin.testing.ArtifactStubFactory;
32 import org.apache.maven.plugin.testing.SilentLog;
33
34
35
36
37 public class TestScopeFilter
38 extends TestCase
39 {
40 Set<Artifact> artifacts;
41
42 Log log = new SilentLog();
43
44 protected void setUp()
45 throws Exception
46 {
47 super.setUp();
48
49 ArtifactStubFactory factory = new ArtifactStubFactory( null, false );
50 artifacts = factory.getScopedArtifacts();
51 }
52
53 public void testScopeCompile()
54 throws ArtifactFilterException
55 {
56 ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_COMPILE, null );
57 Set<Artifact> result = filter.filter( artifacts );
58 assertEquals( 3, result.size() );
59
60 }
61
62 public void testScopeRuntime()
63 throws ArtifactFilterException
64 {
65 ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_RUNTIME, null );
66 Set<Artifact> result = filter.filter( artifacts );
67 assertEquals( 2, result.size() );
68
69 }
70
71 public void testScopeTest()
72 throws ArtifactFilterException
73 {
74 ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_TEST, null );
75 Set<Artifact> result = filter.filter( artifacts );
76 assertEquals( 5, result.size() );
77 }
78
79 public void testScopeProvided()
80 throws ArtifactFilterException
81 {
82
83 ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_PROVIDED, null );
84 Set<Artifact> result = filter.filter( artifacts );
85 assertTrue( result.size() > 0 );
86 for ( Artifact artifact : result )
87 {
88 assertEquals( Artifact.SCOPE_PROVIDED, artifact.getScope() );
89 }
90 }
91
92 public void testScopeSystem()
93 throws ArtifactFilterException
94 {
95
96 ScopeFilter filter = new ScopeFilter( Artifact.SCOPE_SYSTEM, null );
97 Set<Artifact> result = filter.filter( artifacts );
98 assertTrue( result.size() > 0 );
99 for ( Artifact artifact : result )
100 {
101 assertEquals( Artifact.SCOPE_SYSTEM, artifact.getScope() );
102 }
103 }
104
105 public void testScopeFilterNull()
106 throws ArtifactFilterException
107 {
108 ScopeFilter filter = new ScopeFilter( null, null );
109 Set<Artifact> result = filter.filter( artifacts );
110 assertEquals( 5, result.size() );
111 }
112
113 public void testScopeFilterEmpty()
114 throws ArtifactFilterException
115 {
116 ScopeFilter filter = new ScopeFilter( "", "" );
117 Set<Artifact> result = filter.filter( artifacts );
118 assertEquals( 5, result.size() );
119 }
120
121 public void testExcludeProvided()
122 throws ArtifactFilterException
123 {
124 ScopeFilter filter = new ScopeFilter( "", Artifact.SCOPE_PROVIDED );
125 Set<Artifact> result = filter.filter( artifacts );
126 assertNotNull( result );
127 assertTrue( result.size() > 0 );
128 assertNotNull( result );
129 assertTrue( result.size() > 0 );
130 for ( Artifact artifact : result )
131 {
132 assertFalse( Artifact.SCOPE_PROVIDED.equalsIgnoreCase( artifact.getScope() ) );
133 }
134 }
135
136 public void testExcludeSystem()
137 throws ArtifactFilterException
138 {
139 ScopeFilter filter = new ScopeFilter( "", Artifact.SCOPE_SYSTEM );
140 Set<Artifact> result = filter.filter( artifacts );
141 assertNotNull( result );
142 assertTrue( result.size() > 0 );
143 for ( Artifact artifact : result )
144 {
145 assertFalse( Artifact.SCOPE_SYSTEM.equalsIgnoreCase( artifact.getScope() ) );
146 }
147 }
148
149 public void testExcludeCompile()
150 throws ArtifactFilterException
151 {
152 ScopeFilter filter = new ScopeFilter( "", Artifact.SCOPE_COMPILE );
153 Set<Artifact> result = filter.filter( artifacts );
154 assertEquals( 2, result.size() );
155 }
156
157 public void testExcludeTest()
158 {
159 try
160 {
161 ScopeFilter filter = new ScopeFilter( "", Artifact.SCOPE_TEST );
162 filter.filter( artifacts );
163 fail( "Expected an Exception" );
164 }
165 catch ( ArtifactFilterException e )
166 {
167
168 }
169 }
170
171 public void testBadScope()
172 {
173 ScopeFilter filter = new ScopeFilter( "cOmpile", "" );
174 try
175 {
176 filter.filter( artifacts );
177 fail( "Expected an Exception" );
178 }
179 catch ( ArtifactFilterException e )
180 {
181
182 }
183 try
184 {
185 filter = new ScopeFilter( "", "coMpile" );
186 filter.filter( artifacts );
187 fail( "Expected an Exception" );
188 }
189 catch ( ArtifactFilterException e )
190 {
191
192 }
193 }
194
195 public void testSettersGetters()
196 {
197 ScopeFilter filter = new ScopeFilter( "include", "exclude" );
198 assertEquals( "include", filter.getIncludeScope() );
199 assertEquals( "exclude", filter.getExcludeScope() );
200
201 filter.setExcludeScope( "a" );
202 filter.setIncludeScope( "b" );
203 assertEquals( "b", filter.getIncludeScope() );
204 assertEquals( "a", filter.getExcludeScope() );
205 }
206 }