1 package org.apache.maven.archiva.discovery;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.artifact.Artifact;
20 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
23 import java.net.MalformedURLException;
24 import java.util.Collections;
25 import java.util.Iterator;
26 import java.util.List;
29 * Test the legacy artifact discoverer.
31 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
32 * @version $Id:LegacyArtifactDiscovererTest.java 437105 2006-08-26 17:22:22 +1000 (Sat, 26 Aug 2006) brett $
34 public class LegacyArtifactDiscovererTest
35 extends AbstractArtifactDiscovererTest
37 private static final List JAVAX_SQL_BLACKLIST = Collections.singletonList( "javax.sql/**" );
39 protected String getLayout()
44 protected File getRepositoryFile()
46 return getTestFile( "src/test/legacy-repository" );
49 public void testDefaultExcludes()
50 throws DiscovererException
52 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
53 assertNotNull( "Check artifacts not null", artifacts );
54 boolean found = false;
55 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
57 DiscovererPath dPath = (DiscovererPath) i.next();
59 String path = dPath.getPath();
61 if ( path.indexOf( ".svn" ) >= 0 )
64 assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() );
67 assertTrue( "Check exclusion was found", found );
69 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
71 Artifact a = (Artifact) i.next();
72 assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 );
76 public void testStandardExcludes()
77 throws DiscovererException
79 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
80 assertNotNull( "Check artifacts not null", artifacts );
81 boolean found = false;
82 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
84 DiscovererPath dPath = (DiscovererPath) i.next();
86 String path = dPath.getPath();
88 if ( "KEYS".equals( path ) )
91 assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() );
94 assertTrue( "Check exclusion was found", found );
96 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
98 Artifact a = (Artifact) i.next();
99 assertFalse( "Check not KEYS", "KEYS".equals( a.getFile().getName() ) );
103 public void testBlacklistedExclude()
104 throws DiscovererException
106 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, JAVAX_SQL_BLACKLIST, false );
107 assertNotNull( "Check artifacts not null", artifacts );
108 boolean found = false;
109 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
111 DiscovererPath dPath = (DiscovererPath) i.next();
113 String path = dPath.getPath();
115 if ( "javax.sql/jars/jdbc-2.0.jar".equals( path.replace( '\\', '/' ) ) )
118 assertEquals( "Check comment is about blacklisting", "Artifact was in the specified list of exclusions",
119 dPath.getComment() );
122 assertTrue( "Check exclusion was found", found );
124 assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
127 public void testKickoutWithShortPath()
128 throws DiscovererException
130 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
131 assertNotNull( "Check artifacts not null", artifacts );
132 boolean found = false;
133 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
135 DiscovererPath dPath = (DiscovererPath) i.next();
137 String path = dPath.getPath();
139 if ( "invalid/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) )
142 assertEquals( "Check reason for kickout",
143 "Path does not match a legacy repository path for an artifact", dPath.getComment() );
146 assertTrue( "Check kickout was found", found );
148 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
150 Artifact a = (Artifact) i.next();
151 assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) );
155 public void testKickoutWithLongPath()
156 throws DiscovererException
158 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
159 assertNotNull( "Check artifacts not null", artifacts );
160 boolean found = false;
161 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
163 DiscovererPath dPath = (DiscovererPath) i.next();
165 String path = dPath.getPath();
167 if ( "invalid/jars/1.0/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) )
170 assertEquals( "Check reason for kickout",
171 "Path does not match a legacy repository path for an artifact", dPath.getComment() );
174 assertTrue( "Check kickout was found", found );
176 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
178 Artifact a = (Artifact) i.next();
179 assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) );
183 public void testKickoutWithInvalidType()
184 throws DiscovererException
186 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
187 assertNotNull( "Check artifacts not null", artifacts );
188 boolean found = false;
189 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
191 DiscovererPath dPath = (DiscovererPath) i.next();
193 String path = dPath.getPath();
195 if ( "invalid/foo/invalid-1.0.foo".equals( path.replace( '\\', '/' ) ) )
198 assertEquals( "Check reason for kickout", "Path artifact type does not corresspond to an artifact type",
199 dPath.getComment() );
202 assertTrue( "Check kickout was found", found );
204 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
206 Artifact a = (Artifact) i.next();
207 assertFalse( "Check not invalid-1.0.foo", "invalid-1.0.foo".equals( a.getFile().getName() ) );
211 public void testKickoutWithNoExtension()
212 throws DiscovererException
214 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
215 assertNotNull( "Check artifacts not null", artifacts );
216 boolean found = false;
217 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
219 DiscovererPath dPath = (DiscovererPath) i.next();
221 String path = dPath.getPath();
223 if ( "invalid/jars/no-extension".equals( path.replace( '\\', '/' ) ) )
226 assertEquals( "Check reason for kickout", "Path filename does not have an extension",
227 dPath.getComment() );
230 assertTrue( "Check kickout was found", found );
232 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
234 Artifact a = (Artifact) i.next();
235 assertFalse( "Check not 'no-extension'", "no-extension".equals( a.getFile().getName() ) );
239 public void testKickoutWithWrongExtension()
240 throws DiscovererException
242 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
243 assertNotNull( "Check artifacts not null", artifacts );
244 boolean found = false;
245 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
247 DiscovererPath dPath = (DiscovererPath) i.next();
249 String path = dPath.getPath();
251 if ( "invalid/jars/invalid-1.0.rar".equals( path.replace( '\\', '/' ) ) )
254 assertEquals( "Check reason for kickout", "Path type does not match the extension",
255 dPath.getComment() );
258 assertTrue( "Check kickout was found", found );
260 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
262 Artifact a = (Artifact) i.next();
263 assertFalse( "Check not 'invalid-1.0.rar'", "invalid-1.0.rar".equals( a.getFile().getName() ) );
267 public void testKickoutWithNoVersion()
268 throws DiscovererException
270 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
271 assertNotNull( "Check artifacts not null", artifacts );
272 boolean found = false;
273 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
275 DiscovererPath dPath = (DiscovererPath) i.next();
277 String path = dPath.getPath();
279 if ( "invalid/jars/invalid.jar".equals( path.replace( '\\', '/' ) ) )
282 assertEquals( "Check reason for kickout", "Path filename version is empty", dPath.getComment() );
285 assertTrue( "Check kickout was found", found );
287 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
289 Artifact a = (Artifact) i.next();
290 assertFalse( "Check not 'invalid.jar'", "invalid.jar".equals( a.getFile().getName() ) );
294 public void testInclusion()
295 throws DiscovererException
297 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
298 assertNotNull( "Check artifacts not null", artifacts );
300 assertTrue( "Check normal included",
301 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) );
304 public void testTextualVersion()
305 throws DiscovererException
307 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
308 assertNotNull( "Check artifacts not null", artifacts );
310 assertTrue( "Check normal included",
311 artifacts.contains( createArtifact( "org.apache.maven", "testing", "UNKNOWN" ) ) );
314 public void testArtifactWithClassifier()
315 throws DiscovererException
317 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
318 assertNotNull( "Check artifacts not null", artifacts );
320 assertTrue( "Check normal included",
321 artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) );
324 public void testJavaSourcesInclusion()
325 throws DiscovererException
327 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
328 assertNotNull( "Check artifacts not null", artifacts );
330 assertTrue( "Check normal included", artifacts.contains(
331 createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) );
334 public void testDistributionInclusion()
335 throws DiscovererException
337 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
338 assertNotNull( "Check artifacts not null", artifacts );
340 assertTrue( "Check zip included",
341 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) );
343 assertTrue( "Check tar.gz included",
344 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) );
347 public void testSnapshotInclusion()
348 throws DiscovererException
350 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
351 assertNotNull( "Check artifacts not null", artifacts );
353 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
354 assertTrue( "Check snapshot included",
355 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
358 public void testSnapshotExclusion()
359 throws DiscovererException
361 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
362 assertNotNull( "Check artifacts not null", artifacts );
364 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
365 assertFalse( "Check snapshot included",
366 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
369 public void testFileSet()
370 throws DiscovererException
372 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
373 assertNotNull( "Check artifacts not null", artifacts );
375 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
377 Artifact artifact = (Artifact) i.next();
378 assertNotNull( "Check file is set", artifact.getFile() );
382 public void testRepositorySet()
383 throws MalformedURLException, DiscovererException
385 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
386 assertNotNull( "Check artifacts not null", artifacts );
388 String url = repository.getUrl();
389 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
391 Artifact artifact = (Artifact) i.next();
392 assertNotNull( "Check repository set", artifact.getRepository() );
393 assertEquals( "Check repository url is correct", url, artifact.getRepository().getUrl() );
397 public void testWrongArtifactPackaging()
398 throws ComponentLookupException, DiscovererException
402 discoverer.buildArtifact( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" );
404 fail( "Artifact should be null for wrong package extension" );
406 catch ( DiscovererException e )
412 public void testNoArtifactId()
413 throws DiscovererException
417 discoverer.buildArtifact( "groupId/jars/-1.0.jar" );
419 fail( "Artifact should be null when artifactId is missing" );
421 catch ( DiscovererException e )
428 discoverer.buildArtifact( "groupId/jars/1.0.jar" );
430 fail( "Artifact should be null when artifactId is missing" );
432 catch ( DiscovererException e )
438 public void testNoType()
439 throws ComponentLookupException, DiscovererException
443 discoverer.buildArtifact( "invalid/invalid/1/invalid-1" );
445 fail( "Artifact should be null for no type" );
447 catch ( DiscovererException e )
453 public void testSnapshot()
454 throws ComponentLookupException, DiscovererException
456 String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar";
458 Artifact artifact = discoverer.buildArtifact( testPath );
460 assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-SNAPSHOT" ), artifact );
463 public void testFinal()
464 throws ComponentLookupException, DiscovererException
466 String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar";
468 Artifact artifact = discoverer.buildArtifact( testPath );
470 assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-final-20060606" ), artifact );
473 public void testNormal()
474 throws ComponentLookupException, DiscovererException
476 String testPath = "javax.sql/jars/jdbc-2.0.jar";
478 Artifact artifact = discoverer.buildArtifact( testPath );
480 assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );