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.Iterator;
25 import java.util.List;
28 * Test the legacy artifact discoverer.
30 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
33 public class LegacyArtifactDiscovererTest
34 extends AbstractArtifactDiscovererTest
36 protected String getLayout()
41 protected File getRepositoryFile()
43 return getTestFile( "src/test/legacy-repository" );
46 public void testDefaultExcludes()
47 throws DiscovererException
49 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
50 assertNotNull( "Check artifacts not null", artifacts );
51 boolean found = false;
52 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
54 DiscovererPath dPath = (DiscovererPath) i.next();
56 String path = dPath.getPath();
58 if ( path.indexOf( ".svn" ) >= 0 )
61 assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() );
64 assertTrue( "Check exclusion was found", found );
66 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
68 Artifact a = (Artifact) i.next();
69 assertFalse( "Check not .svn", a.getFile().getPath().indexOf( ".svn" ) >= 0 );
73 public void testStandardExcludes()
74 throws DiscovererException
76 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
77 assertNotNull( "Check artifacts not null", artifacts );
78 boolean found = false;
79 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
81 DiscovererPath dPath = (DiscovererPath) i.next();
83 String path = dPath.getPath();
85 if ( "KEYS".equals( path ) )
88 assertEquals( "Check comment", "Artifact was in the specified list of exclusions", dPath.getComment() );
91 assertTrue( "Check exclusion was found", found );
93 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
95 Artifact a = (Artifact) i.next();
96 assertFalse( "Check not KEYS", "KEYS".equals( a.getFile().getName() ) );
100 public void testBlacklistedExclude()
101 throws DiscovererException
103 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, "javax.sql/**", false );
104 assertNotNull( "Check artifacts not null", artifacts );
105 boolean found = false;
106 for ( Iterator i = discoverer.getExcludedPathsIterator(); i.hasNext() && !found; )
108 DiscovererPath dPath = (DiscovererPath) i.next();
110 String path = dPath.getPath();
112 if ( "javax.sql/jars/jdbc-2.0.jar".equals( path.replace( '\\', '/' ) ) )
115 assertEquals( "Check comment is about blacklisting", "Artifact was in the specified list of exclusions",
116 dPath.getComment() );
119 assertTrue( "Check exclusion was found", found );
121 assertFalse( "Check jdbc not included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
124 public void testKickoutWithShortPath()
125 throws DiscovererException
127 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
128 assertNotNull( "Check artifacts not null", artifacts );
129 boolean found = false;
130 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
132 DiscovererPath dPath = (DiscovererPath) i.next();
134 String path = dPath.getPath();
136 if ( "invalid/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) )
139 assertEquals( "Check reason for kickout",
140 "Path does not match a legacy repository path for an artifact", dPath.getComment() );
143 assertTrue( "Check kickout was found", found );
145 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
147 Artifact a = (Artifact) i.next();
148 assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) );
152 public void testKickoutWithLongPath()
153 throws DiscovererException
155 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
156 assertNotNull( "Check artifacts not null", artifacts );
157 boolean found = false;
158 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
160 DiscovererPath dPath = (DiscovererPath) i.next();
162 String path = dPath.getPath();
164 if ( "invalid/jars/1.0/invalid-1.0.jar".equals( path.replace( '\\', '/' ) ) )
167 assertEquals( "Check reason for kickout",
168 "Path does not match a legacy repository path for an artifact", dPath.getComment() );
171 assertTrue( "Check kickout was found", found );
173 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
175 Artifact a = (Artifact) i.next();
176 assertFalse( "Check not invalid-1.0.jar", "invalid-1.0.jar".equals( a.getFile().getName() ) );
180 public void testKickoutWithInvalidType()
181 throws DiscovererException
183 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
184 assertNotNull( "Check artifacts not null", artifacts );
185 boolean found = false;
186 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
188 DiscovererPath dPath = (DiscovererPath) i.next();
190 String path = dPath.getPath();
192 if ( "invalid/foo/invalid-1.0.foo".equals( path.replace( '\\', '/' ) ) )
195 assertEquals( "Check reason for kickout", "Path artifact type does not corresspond to an artifact type",
196 dPath.getComment() );
199 assertTrue( "Check kickout was found", found );
201 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
203 Artifact a = (Artifact) i.next();
204 assertFalse( "Check not invalid-1.0.foo", "invalid-1.0.foo".equals( a.getFile().getName() ) );
208 public void testKickoutWithNoExtension()
209 throws DiscovererException
211 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
212 assertNotNull( "Check artifacts not null", artifacts );
213 boolean found = false;
214 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
216 DiscovererPath dPath = (DiscovererPath) i.next();
218 String path = dPath.getPath();
220 if ( "invalid/jars/no-extension".equals( path.replace( '\\', '/' ) ) )
223 assertEquals( "Check reason for kickout", "Path filename does not have an extension",
224 dPath.getComment() );
227 assertTrue( "Check kickout was found", found );
229 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
231 Artifact a = (Artifact) i.next();
232 assertFalse( "Check not 'no-extension'", "no-extension".equals( a.getFile().getName() ) );
236 public void testKickoutWithWrongExtension()
237 throws DiscovererException
239 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
240 assertNotNull( "Check artifacts not null", artifacts );
241 boolean found = false;
242 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
244 DiscovererPath dPath = (DiscovererPath) i.next();
246 String path = dPath.getPath();
248 if ( "invalid/jars/invalid-1.0.rar".equals( path.replace( '\\', '/' ) ) )
251 assertEquals( "Check reason for kickout", "Path type does not match the extension",
252 dPath.getComment() );
255 assertTrue( "Check kickout was found", found );
257 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
259 Artifact a = (Artifact) i.next();
260 assertFalse( "Check not 'invalid-1.0.rar'", "invalid-1.0.rar".equals( a.getFile().getName() ) );
264 public void testKickoutWithNoVersion()
265 throws DiscovererException
267 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
268 assertNotNull( "Check artifacts not null", artifacts );
269 boolean found = false;
270 for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
272 DiscovererPath dPath = (DiscovererPath) i.next();
274 String path = dPath.getPath();
276 if ( "invalid/jars/invalid.jar".equals( path.replace( '\\', '/' ) ) )
279 assertEquals( "Check reason for kickout", "Path filename version is empty", dPath.getComment() );
282 assertTrue( "Check kickout was found", found );
284 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
286 Artifact a = (Artifact) i.next();
287 assertFalse( "Check not 'invalid.jar'", "invalid.jar".equals( a.getFile().getName() ) );
291 public void testInclusion()
292 throws DiscovererException
294 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
295 assertNotNull( "Check artifacts not null", artifacts );
297 assertTrue( "Check normal included",
298 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) );
301 public void testTextualVersion()
302 throws DiscovererException
304 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
305 assertNotNull( "Check artifacts not null", artifacts );
307 assertTrue( "Check normal included",
308 artifacts.contains( createArtifact( "org.apache.maven", "testing", "UNKNOWN" ) ) );
311 public void testArtifactWithClassifier()
312 throws DiscovererException
314 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
315 assertNotNull( "Check artifacts not null", artifacts );
317 assertTrue( "Check normal included",
318 artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) );
321 public void testJavaSourcesInclusion()
322 throws DiscovererException
324 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
325 assertNotNull( "Check artifacts not null", artifacts );
327 assertTrue( "Check normal included", artifacts.contains(
328 createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) );
331 public void testDistributionInclusion()
332 throws DiscovererException
334 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
335 assertNotNull( "Check artifacts not null", artifacts );
337 assertTrue( "Check zip included",
338 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) );
340 assertTrue( "Check tar.gz included",
341 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) );
344 public void testSnapshotInclusion()
345 throws DiscovererException
347 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
348 assertNotNull( "Check artifacts not null", artifacts );
350 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
351 assertTrue( "Check snapshot included",
352 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
355 public void testSnapshotExclusion()
356 throws DiscovererException
358 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, false );
359 assertNotNull( "Check artifacts not null", artifacts );
361 assertTrue( "Check normal included", artifacts.contains( createArtifact( "javax.sql", "jdbc", "2.0" ) ) );
362 assertFalse( "Check snapshot included",
363 artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0-20050611.112233-1" ) ) );
366 public void testFileSet()
367 throws DiscovererException
369 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
370 assertNotNull( "Check artifacts not null", artifacts );
372 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
374 Artifact artifact = (Artifact) i.next();
375 assertNotNull( "Check file is set", artifact.getFile() );
379 public void testRepositorySet()
380 throws MalformedURLException, DiscovererException
382 List artifacts = discoverer.discoverArtifacts( repository, TEST_OPERATION, null, true );
383 assertNotNull( "Check artifacts not null", artifacts );
385 String url = repository.getUrl();
386 for ( Iterator i = artifacts.iterator(); i.hasNext(); )
388 Artifact artifact = (Artifact) i.next();
389 assertNotNull( "Check repository set", artifact.getRepository() );
390 assertEquals( "Check repository url is correct", url, artifact.getRepository().getUrl() );
394 public void testWrongArtifactPackaging()
395 throws ComponentLookupException, DiscovererException
399 discoverer.buildArtifact( "org.apache.maven.test/jars/artifactId-1.0.jar.md5" );
401 fail( "Artifact should be null for wrong package extension" );
403 catch ( DiscovererException e )
409 public void testNoArtifactId()
410 throws DiscovererException
414 discoverer.buildArtifact( "groupId/jars/-1.0.jar" );
416 fail( "Artifact should be null when artifactId is missing" );
418 catch ( DiscovererException e )
425 discoverer.buildArtifact( "groupId/jars/1.0.jar" );
427 fail( "Artifact should be null when artifactId is missing" );
429 catch ( DiscovererException e )
435 public void testNoType()
436 throws ComponentLookupException, DiscovererException
440 discoverer.buildArtifact( "invalid/invalid/1/invalid-1" );
442 fail( "Artifact should be null for no type" );
444 catch ( DiscovererException e )
450 public void testSnapshot()
451 throws ComponentLookupException, DiscovererException
453 String testPath = "org.apache.maven.test/jars/maven-model-1.0-SNAPSHOT.jar";
455 Artifact artifact = discoverer.buildArtifact( testPath );
457 assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-SNAPSHOT" ), artifact );
460 public void testFinal()
461 throws ComponentLookupException, DiscovererException
463 String testPath = "org.apache.maven.test/jars/maven-model-1.0-final-20060606.jar";
465 Artifact artifact = discoverer.buildArtifact( testPath );
467 assertEquals( createArtifact( "org.apache.maven.test", "maven-model", "1.0-final-20060606" ), artifact );
470 public void testNormal()
471 throws ComponentLookupException, DiscovererException
473 String testPath = "javax.sql/jars/jdbc-2.0.jar";
475 Artifact artifact = discoverer.buildArtifact( testPath );
477 assertEquals( createArtifact( "javax.sql", "jdbc", "2.0" ), artifact );