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