View Javadoc

1   package org.apache.maven.archiva.repository.content;
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  import org.apache.commons.lang.StringUtils;
23  import org.apache.maven.archiva.model.ArtifactReference;
24  import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
25  import org.apache.maven.archiva.repository.ManagedRepositoryContent;
26  import org.apache.maven.archiva.repository.layout.LayoutException;
27  
28  import java.io.File;
29  
30  /**
31   * RepositoryRequestTest
32   *
33   * @version $Id: RepositoryRequestTest.java 825452 2009-10-15 09:59:32Z oching $
34   */
35  public class RepositoryRequestTest
36      extends AbstractRepositoryLayerTestCase
37  {
38      public void testInvalidRequestEmptyPath()
39      {
40          assertInvalidRequest( "" );
41      }
42      
43      public void testInvalidRequestSlashOnly()
44      {
45          assertInvalidRequest( "//" );
46      }
47      
48      public void testInvalidRequestNoArtifactId()
49      {
50          assertInvalidRequest( "groupId/jars/-1.0.jar" );
51      }
52  
53      public void testInvalidLegacyRequestBadLocation()
54      {
55          assertInvalidRequest( "org.apache.maven.test/jars/artifactId-1.0.war" );
56      }
57  
58      public void testInvalidRequestTooShort()
59      {
60          assertInvalidRequest( "org.apache.maven.test/artifactId-2.0.jar" );
61      }
62  
63      public void testInvalidDefaultRequestBadLocation()
64      {
65          assertInvalidRequest( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
66      }
67  
68      public void testValidLegacyGanymed()
69          throws Exception
70      {
71          assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210",
72                       null, "jar" );
73      }
74  
75      public void testValidDefaultGanymed()
76          throws Exception
77      {
78          assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed",
79                       "ganymed-ssh2", "build210", null, "jar" );
80      }
81  
82      public void testValidLegacyJavaxComm()
83          throws Exception
84      {
85          assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
86      }
87  
88      public void testValidDefaultJavaxComm()
89          throws Exception
90      {
91          assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", null, "jar" );
92      }
93  
94      public void testValidLegacyJavaxPersistence()
95          throws Exception
96      {
97          assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
98                       "3.0-public_review", null, "jar" );
99      }
100 
101     public void testValidDefaultJavaxPersistence()
102         throws Exception
103     {
104         assertValid( "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
105                      "3.0-public_review", null, "jar" );
106     }
107 
108     public void testValidLegacyMavenTestPlugin()
109         throws Exception
110     {
111         assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", null, "jar" );
112     }
113 
114     public void testValidDefaultMavenTestPlugin()
115         throws Exception
116     {
117         assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin",
118                      "1.8.2", null, "pom" );
119     }
120 
121     public void testValidLegacyCommonsLangJavadoc()
122         throws Exception
123     {
124         assertValid( "commons-lang/javadoc.jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1",
125                      "javadoc", "javadoc" );
126     }
127 
128     public void testValidDefaultCommonsLangJavadoc()
129         throws Exception
130     {
131         assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang",
132                      "2.1", "javadoc", "javadoc" );
133     }
134 
135     public void testValidLegacyDerbyPom()
136         throws Exception
137     {
138         assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
139         // Starting slash should not prevent detection.
140         assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
141     }
142 
143     public void testValidDefaultDerbyPom()
144         throws Exception
145     {
146         assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0",
147                      null, "pom" );
148     }
149 
150     public void testValidLegacyGeronimoEjbSpec()
151         throws Exception
152     {
153         assertValid( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar", "org.apache.geronimo.specs",
154                      "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
155     }
156 
157     public void testValidDefaultGeronimoEjbSpec()
158         throws Exception
159     {
160         assertValid( "org/apache/geronimo/specs/geronimo-ejb_2.1_spec/1.0.1/geronimo-ejb_2.1_spec-1.0.1.jar",
161                      "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
162     }
163 
164     public void testValidLegacyLdapSnapshot()
165         throws Exception
166     {
167         assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients",
168                      "0.9.1-SNAPSHOT", null, "pom" );
169     }
170 
171     public void testValidDefaultLdapSnapshot()
172         throws Exception
173     {
174         assertValid( "directory-clients/ldap-clients/0.9.1-SNAPSHOT/ldap-clients-0.9.1-SNAPSHOT.pom",
175                      "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" );
176     }
177 
178     public void testValidLegacyTestArchSnapshot()
179         throws Exception
180     {
181         assertValid( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", "test-arch",
182                      "2.0.3-SNAPSHOT", null, "pom" );
183     }
184 
185     public void testValidDefaultTestArchSnapshot()
186         throws Exception
187     {
188         assertValid( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch",
189                      "test-arch", "2.0.3-SNAPSHOT", null, "pom" );
190     }
191 
192     public void testValidLegacyOddDottedArtifactId()
193         throws Exception
194     {
195         assertValid( "com.company.department/poms/com.company.department.project-0.2.pom", "com.company.department",
196                      "com.company.department.project", "0.2", null, "pom" );
197     }
198 
199     public void testValidDefaultOddDottedArtifactId()
200         throws Exception
201     {
202         assertValid( "com/company/department/com.company.department.project/0.2/com.company.department.project-0.2.pom",
203                      "com.company.department", "com.company.department.project", "0.2", null, "pom" );
204     }
205 
206     public void testValidLegacyTimestampedSnapshot()
207         throws Exception
208     {
209         assertValid( "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar",
210                      "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
211     }
212 
213     public void testValidDefaultTimestampedSnapshot()
214         throws Exception
215     {
216         assertValid(
217                      "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar",
218                      "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", null, "jar" );
219     }
220 
221     public void testIsSupportFile()
222     {
223         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
224         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
225         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
226         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
227         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
228         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
229 
230         assertFalse( repoRequest.isSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
231         assertFalse( repoRequest.isSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
232         assertFalse( repoRequest.isSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
233         assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
234         assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
235         assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) );
236     }
237 
238     public void testIsMetadata()
239     {
240         assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ));
241         assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/maven-metadata.xml" ));
242 
243         assertFalse( repoRequest.isMetadata( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
244         assertFalse( repoRequest.isMetadata( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
245         assertFalse( repoRequest.isMetadata( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
246         assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
247         assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
248         assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
249     }
250     
251     public void testIsMetadataSupportFile()
252     {
253         assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ));
254         assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml" ));
255         assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.sha1" ));
256         assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.md5" ));
257 
258         assertFalse( repoRequest.isMetadataSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
259         assertFalse( repoRequest.isMetadataSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
260         assertFalse( repoRequest.isMetadataSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
261         assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
262         assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
263         assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
264         assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );        
265     }
266 
267     public void testIsDefault()
268     {
269         assertFalse( repoRequest.isDefault( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
270         assertFalse( repoRequest.isDefault( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
271         assertFalse( repoRequest.isDefault( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
272 
273         assertTrue( repoRequest.isDefault( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
274         assertTrue( repoRequest.isDefault( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
275         assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
276         assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
277         assertTrue( repoRequest.isDefault( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
278         assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml" ) );
279         assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml.sha1" ) );
280         assertTrue( repoRequest.isDefault( "eclipse/jdtcore/maven-metadata.xml.md5" ) );
281 
282         assertFalse( repoRequest.isDefault( null ) );
283         assertFalse( repoRequest.isDefault( "" ) );
284         assertFalse( repoRequest.isDefault( "foo" ) );
285         assertFalse( repoRequest.isDefault( "some.short/path" ) );
286     }
287 
288     public void testIsLegacy()
289     {
290         assertTrue( repoRequest.isLegacy( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
291         assertTrue( repoRequest.isLegacy( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
292         assertTrue( repoRequest.isLegacy( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
293 
294         assertFalse( repoRequest.isLegacy( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
295         assertFalse( repoRequest.isLegacy( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
296         assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
297         assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
298         assertFalse( repoRequest.isLegacy( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
299 
300         assertFalse( repoRequest.isLegacy( null ) );
301         assertFalse( repoRequest.isLegacy( "" ) );
302         assertFalse( repoRequest.isLegacy( "some.short/path" ) );
303     }
304 
305     private ManagedRepositoryContent createManagedRepo( String layout )
306         throws Exception
307     {
308         File repoRoot = getTestFile( "target/test-repo" );
309         return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout );
310     }
311 
312     /**
313      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
314      */
315     public void testToNativePathArtifactDefaultToDefaultDualExtension()
316         throws Exception
317     {
318         ManagedRepositoryContent repository = createManagedRepo( "default" );
319 
320         // Test (artifact) default to default - dual extension
321         assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repoRequest
322             .toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repository ) );
323     }
324 
325     /**
326      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
327      */
328     public void testToNativePathArtifactLegacyToDefaultDualExtension()
329         throws Exception
330     {
331         ManagedRepositoryContent repository = createManagedRepo( "default" );
332 
333         // Test (artifact) legacy to default - dual extension
334         // NOTE: The detection of a dual extension is flawed.
335         assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest
336             .toNativePath( "org.project/zips/example-presentation-3.2.xml.zip", repository ) );
337     }
338 
339     public void testToNativePathMetadataDefaultToDefault()
340         throws Exception
341     {
342         ManagedRepositoryContent repository = createManagedRepo( "default" );
343 
344         // Test (metadata) default to default
345         assertEquals( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", repoRequest
346             .toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1", repository ) );
347     }
348 
349     public void testNativePathPomLegacyToDefault()
350         throws Exception
351     {
352         ManagedRepositoryContent repository = createManagedRepo( "default" );
353 
354         // Test (pom) legacy to default
355         assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom",
356                       repoRequest.toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", repository ) );
357     }
358 
359     public void testNativePathPomLegacyToLegacy()
360         throws Exception
361     {
362         ManagedRepositoryContent repository = createManagedRepo( "legacy" );
363 
364         // Test (pom) legacy to default
365         assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom",
366                       repoRequest.toNativePath( "org.apache.derby/poms/derby-10.2.2.0.pom", repository ) );
367     }
368 
369     public void testNativePathPomLegacyToDefaultEjb()
370         throws Exception
371     {
372         ManagedRepositoryContent repository = createManagedRepo( "default" );
373 
374         // Test (pom) legacy to default
375         assertEquals( "mygroup/myejb/1.0/myejb-1.0.jar",
376                       repoRequest.toNativePath( "mygroup/ejbs/myejb-1.0.jar", repository ) );
377     }
378 
379     public void testNativePathPomLegacyToLegacyEjb()
380         throws Exception
381     {
382         ManagedRepositoryContent repository = createManagedRepo( "legacy" );
383 
384         // Test (pom) legacy to default
385         assertEquals( "mygroup/ejbs/myejb-1.0.jar",
386                       repoRequest.toNativePath( "mygroup/ejbs/myejb-1.0.jar", repository ) );
387     }
388 
389     public void testNativePathPomLegacyToLegacyStrutsModule()
390         throws Exception
391     {
392         ManagedRepositoryContent repository = createManagedRepo( "legacy" );
393 
394         // Test (pom) legacy to default
395         assertEquals( "WebPortal/struts-modules/eventsDB-1.2.3.struts-module",
396                       repoRequest.toNativePath( "WebPortal/struts-modules/eventsDB-1.2.3.struts-module", repository ) );
397     }
398 
399     public void testNativePathSupportFileLegacyToDefault()
400         throws Exception
401     {
402         ManagedRepositoryContent repository = createManagedRepo( "default" );
403 
404         // Test (supportfile) legacy to default
405         assertEquals( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repoRequest
406             .toNativePath( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repository ) );
407     }
408 
409     public void testNativePathBadRequestTooShort()
410         throws Exception
411     {
412         ManagedRepositoryContent repository = createManagedRepo( "default" );
413 
414         // Test bad request path (too short)
415         try
416         {
417             repoRequest.toNativePath( "org.apache.derby/license.txt", repository );
418             fail( "Should have thrown an exception about a too short path." );
419         }
420         catch ( LayoutException e )
421         {
422             // expected path.
423         }
424     }
425 
426     public void testNativePathBadRequestBlank()
427         throws Exception
428     {
429         ManagedRepositoryContent repository = createManagedRepo( "default" );
430 
431         // Test bad request path (too short)
432         try
433         {
434             repoRequest.toNativePath( "", repository );
435             fail( "Should have thrown an exception about an blank request." );
436         }
437         catch ( LayoutException e )
438         {
439             // expected path.
440         }
441     }
442 
443     public void testNativePathBadRequestNull()
444         throws Exception
445     {
446         ManagedRepositoryContent repository = createManagedRepo( "default" );
447 
448         // Test bad request path (too short)
449         try
450         {
451             repoRequest.toNativePath( null, repository );
452             fail( "Should have thrown an exception about an null request." );
453         }
454         catch ( LayoutException e )
455         {
456             // expected path.
457         }
458     }
459 
460     public void testNativePathBadRequestUnknownType()
461         throws Exception
462     {
463         ManagedRepositoryContent repository = createManagedRepo( "default" );
464 
465         // Test bad request path (too short)
466         try
467         {
468             repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/license.txt", repository );
469             fail( "Should have thrown an exception about an invalid type." );
470         }
471         catch ( LayoutException e )
472         {
473             // expected path.
474         }
475     }
476 
477     public void testToNativePathLegacyMetadataDefaultToLegacy()
478         throws Exception
479     {
480         ManagedRepositoryContent repository = createManagedRepo( "legacy" );
481 
482         // Test (metadata) default to legacy
483 
484         // Special Case: This direction is not supported, should throw a LayoutException.
485         try
486         {
487             repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml", repository );
488             fail("Should have thrown a LayoutException, can't translate a maven-metadata.xml to a legacy layout.");
489         }
490         catch(LayoutException e)
491         {
492             // expected path.
493         }
494     }
495 
496     public void testNativePathPomDefaultToLegacy()
497         throws Exception
498     {
499         ManagedRepositoryContent repository = createManagedRepo( "legacy" );
500 
501         // Test (pom) default to legacy
502         assertEquals( "org.apache.derby/poms/derby-10.2.2.0.pom", repoRequest
503             .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", repository ) );
504     }
505 
506     public void testNativePathSupportFileDefaultToLegacy()
507         throws Exception
508     {
509         ManagedRepositoryContent repository = createManagedRepo( "legacy" );
510 
511         // Test (supportfile) default to legacy
512         assertEquals( "org.apache.derby/jars/derby-10.2.2.0.jar.sha1", repoRequest
513             .toNativePath( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.jar.sha1", repository ) );
514     }
515 
516     private void assertValid( String path, String groupId, String artifactId, String version, String classifier,
517                               String type )
518         throws Exception
519     {
520         String expectedId = "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":"
521             + ( classifier != null ? classifier + ":" : "" ) + type;
522 
523         ArtifactReference reference = repoRequest.toArtifactReference( path );
524 
525         assertNotNull( expectedId + " - Should not be null.", reference );
526 
527         assertEquals( expectedId + " - Group ID", groupId, reference.getGroupId() );
528         assertEquals( expectedId + " - Artifact ID", artifactId, reference.getArtifactId() );
529         if ( StringUtils.isNotBlank( classifier ) )
530         {
531             assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() );
532         }
533         assertEquals( expectedId + " - Version ID", version, reference.getVersion() );
534         assertEquals( expectedId + " - Type", type, reference.getType() );
535     }
536 
537     private void assertInvalidRequest( String path )
538     {
539         try
540         {
541             repoRequest.toArtifactReference( path );
542             fail( "Expected a LayoutException on an invalid path [" + path + "]" );
543         }
544         catch ( LayoutException e )
545         {
546             /* expected path */
547         }
548     }
549 
550     private RepositoryRequest repoRequest;
551 
552     @Override
553     protected void setUp()
554         throws Exception
555     {
556         super.setUp();
557 
558         repoRequest = (RepositoryRequest) lookup( RepositoryRequest.class );
559     }
560 }