]> source.dussan.org Git - archiva.git/blob
1cfdc47099de23ae28480b5d183c0bea693d71e4
[archiva.git] /
1 package org.apache.archiva.maven.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  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  */
20
21 import org.apache.archiva.common.filelock.FileLockManager;
22 import org.apache.archiva.common.utils.FileUtils;
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.FileType;
25 import org.apache.archiva.configuration.FileTypes;
26 import org.apache.archiva.maven.repository.MavenManagedRepository;
27 import org.apache.archiva.maven.repository.metadata.storage.ArtifactMappingProvider;
28 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
29 import org.apache.archiva.repository.ManagedRepositoryContent;
30 import org.apache.archiva.repository.RepositoryContentProvider;
31 import org.apache.archiva.repository.content.ItemSelector;
32 import org.apache.archiva.repository.content.LayoutException;
33 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
34 import org.apache.commons.lang3.StringUtils;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.springframework.context.ApplicationContext;
39 import org.springframework.test.context.ContextConfiguration;
40
41 import javax.inject.Inject;
42 import javax.inject.Named;
43 import java.io.IOException;
44 import java.net.URISyntaxException;
45 import java.nio.file.Path;
46 import java.nio.file.Paths;
47 import java.util.List;
48
49 import static org.junit.Assert.*;
50
51 /**
52  * RepositoryRequestTest
53  */
54 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
55 @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml",
56     "classpath:/spring-context-repo-request-test.xml" } )
57 public class MavenRepositoryRequestInfoTest
58 {
59
60     @Inject
61     protected ApplicationContext applicationContext;
62
63     @Inject
64     FileTypes fileTypes;
65
66     @Inject
67     @Named( "archivaConfiguration#repo-request-test" )
68     private ArchivaConfiguration archivaConfiguration;
69
70     @Inject
71     List<? extends ArtifactMappingProvider> artifactMappingProviders;
72
73     @Inject
74     @Named( "repositoryPathTranslator#maven2" )
75     RepositoryPathTranslator pathTranslator;
76
77     @Inject
78     FileLockManager fileLockManager;
79
80     @Inject
81     MavenContentHelper mavenContentHelper;
82
83     private MavenRepositoryRequestInfo repoRequest;
84
85
86     protected MavenManagedRepository createRepository( String id, String name, Path location ) throws IOException {
87         MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, location.getParent().toAbsolutePath());
88         repo.setLocation( location.toAbsolutePath().toUri() );
89         return repo;
90     }
91
92     private Path getRepositoryPath(String repoName) {
93         try
94         {
95             return Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/" + repoName ).toURI( ) );
96         }
97         catch ( URISyntaxException e )
98         {
99             throw new RuntimeException( "Could not resolve repository path " + e.getMessage( ), e );
100         }
101     }
102
103     @Before
104     public void setUp()
105         throws Exception
106     {
107
108         Path repoDir = getRepositoryPath( "default-repository" );
109         MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", repoDir );
110
111         FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 );
112         fileType.addPattern( "**/*.xml" );
113         assertEquals( FileTypes.ARTIFACTS, fileType.getId() );
114
115         fileTypes.afterConfigurationChange( null, "fileType", null );
116
117         ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent(repository, fileTypes, fileLockManager);
118         //repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, "default" );
119         repository.setContent(repoContent);
120         repoContent.setMavenContentHelper( mavenContentHelper );
121         repoContent.setArtifactMappingProviders( artifactMappingProviders );
122         repoContent.setPathTranslator( pathTranslator );
123
124         repoRequest = new MavenRepositoryRequestInfo(repository);
125     }
126
127     @Test
128     public void testInvalidRequestEmptyPath()
129     {
130         assertInvalidRequest( "" );
131     }
132
133     @Test
134     public void testInvalidRequestSlashOnly()
135     {
136         assertInvalidRequest( "//" );
137     }
138
139     @Test
140     public void testInvalidRequestNoArtifactId()
141     {
142         assertInvalidRequest( "groupId/jars/-1.0.jar" );
143     }
144
145
146     @Test
147     public void testInvalidRequestTooShort()
148     {
149         assertInvalidRequest( "org.apache.maven.test/artifactId-2.0.jar" );
150     }
151
152     @Test
153     public void testInvalidDefaultRequestBadLocation()
154     {
155         assertInvalidRequest( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
156     }
157
158     @Test( expected = LayoutException.class )
159     public void testValidLegacyGanymed()
160         throws Exception
161     {
162         assertValid( "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar", "ch.ethz.ganymed", "ganymed-ssh2", "build210",
163                      "build210", null, "jar" );
164     }
165
166     @Test
167     public void testValidDefaultGanymed()
168         throws Exception
169     {
170         assertValid( "ch/ethz/ganymed/ganymed-ssh2/build210/ganymed-ssh2-build210.jar", "ch.ethz.ganymed",
171                      "ganymed-ssh2", "build210", "build210", null, "jar" );
172     }
173
174     @Test( expected = LayoutException.class )
175     public void testValidLegacyJavaxComm()
176         throws Exception
177     {
178         assertValid( "javax/jars/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", "3.0-u1", null, "jar" );
179     }
180
181     @Test
182     public void testValidDefaultJavaxComm()
183         throws Exception
184     {
185         assertValid( "javax/comm/3.0-u1/comm-3.0-u1.jar", "javax", "comm", "3.0-u1", "3.0-u1", null, "jar" );
186     }
187
188     @Test( expected = LayoutException.class )
189     public void testValidLegacyJavaxPersistence()
190         throws Exception
191     {
192         assertValid( "javax.persistence/jars/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
193                      "3.0-public_review", "3.0-public_review", null, "jar" );
194     }
195
196     @Test
197     public void testValidDefaultJavaxPersistence()
198         throws Exception
199     {
200         assertValid( "javax/persistence/ejb/3.0-public_review/ejb-3.0-public_review.jar", "javax.persistence", "ejb",
201                      "3.0-public_review", "3.0-public_review",null, "jar" );
202     }
203
204     @Test( expected = LayoutException.class )
205     public void testValidLegacyMavenTestPlugin()
206         throws Exception
207     {
208         assertValid( "maven/jars/maven-test-plugin-1.8.2.jar", "maven", "maven-test-plugin", "1.8.2", "1.8.2",null, "jar" );
209     }
210
211     @Test
212     public void testValidDefaultMavenTestPlugin()
213         throws Exception
214     {
215         assertValid( "maven/maven-test-plugin/1.8.2/maven-test-plugin-1.8.2.pom", "maven", "maven-test-plugin", "1.8.2", "1.8.2",
216                      null, "pom" );
217     }
218
219     @Test( expected = LayoutException.class )
220     public void testValidLegacyCommonsLangJavadoc()
221         throws Exception
222     {
223         assertValid( "commons-lang/javadoc.jars/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang", "2.1", "2.1",
224                      "javadoc", "javadoc" );
225     }
226
227     @Test
228     public void testValidDefaultCommonsLangJavadoc()
229         throws Exception
230     {
231         assertValid( "commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar", "commons-lang", "commons-lang",
232                      "2.1", "2.1","javadoc", "javadoc" );
233     }
234
235     @Test( expected = LayoutException.class )
236     public void testValidLegacyDerbyPom()
237         throws Exception
238     {
239         assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", "10.2.2.0",null, "pom" );
240         // Starting slash should not prevent detection.
241         assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", "10.2.2.0",null,
242                      "pom" );
243     }
244
245     @Test
246     public void testValidDefaultDerbyPom()
247         throws Exception
248     {
249         assertValid( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", "10.2.2.0",
250                      null, "pom" );
251     }
252
253     @Test( expected = LayoutException.class )
254     public void testValidLegacyGeronimoEjbSpec()
255         throws Exception
256     {
257         assertValid( "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar", "org.apache.geronimo.specs",
258                      "geronimo-ejb_2.1_spec", "1.0.1", "1.0.1",null, "jar" );
259     }
260
261     @Test
262     public void testValidDefaultGeronimoEjbSpec()
263         throws Exception
264     {
265         assertValid( "org/apache/geronimo/specs/geronimo-ejb_2.1_spec/1.0.1/geronimo-ejb_2.1_spec-1.0.1.jar",
266                      "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", "1.0.1",null, "jar" );
267     }
268
269     @Test( expected = LayoutException.class )
270     public void testValidLegacyLdapSnapshot()
271         throws Exception
272     {
273         assertValid( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom", "directory-clients", "ldap-clients",
274                      "0.9.1-SNAPSHOT", "0.9.1-SNAPSHOT",null, "pom" );
275     }
276
277     @Test
278     public void testValidDefaultLdapSnapshot()
279         throws Exception
280     {
281         assertValid( "directory-clients/ldap-clients/0.9.1-SNAPSHOT/ldap-clients-0.9.1-SNAPSHOT.pom",
282                      "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", "0.9.1-SNAPSHOT",null, "pom" );
283     }
284
285     @Test( expected = LayoutException.class )
286     public void testValidLegacyTestArchSnapshot()
287         throws Exception
288     {
289         assertValid( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch", "test-arch",
290                      "2.0.3-SNAPSHOT", "2.0.3-SNAPSHOT",null, "pom" );
291     }
292
293     @Test
294     public void testValidDefaultTestArchSnapshot()
295         throws Exception
296     {
297         assertValid( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.pom", "test.maven-arch",
298                      "test-arch", "2.0.3-SNAPSHOT", "2.0.3-SNAPSHOT",null, "pom" );
299     }
300
301     @Test( expected = LayoutException.class )
302     public void testValidLegacyOddDottedArtifactId()
303         throws Exception
304     {
305         assertValid( "com.company.department/poms/com.company.department.project-0.2.pom", "com.company.department",
306                      "com.company.department.project", "0.2", "0.2",null, "pom" );
307     }
308
309     @Test
310     public void testValidDefaultOddDottedArtifactId()
311         throws Exception
312     {
313         assertValid( "com/company/department/com.company.department.project/0.2/com.company.department.project-0.2.pom",
314                      "com.company.department", "com.company.department.project", "0.2", "0.2",null, "pom" );
315     }
316
317     @Test( expected = LayoutException.class )
318     public void testValidLegacyTimestampedSnapshot()
319         throws Exception
320     {
321         assertValid( "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar",
322                      "org.apache.archiva.test", "redonkulous", "3.1-beta-1-20050831.101112-42", "3.1-beta-1-20050831.101112-42", null, "jar" );
323     }
324
325     @Test
326     public void testValidDefaultTimestampedSnapshot()
327         throws Exception
328     {
329         assertValid(
330             "org/apache/archiva/test/redonkulous/3.1-beta-1-SNAPSHOT/redonkulous-3.1-beta-1-20050831.101112-42.jar",
331             "org.apache.archiva.test", "redonkulous", "3.1-beta-1-SNAPSHOT", "3.1-beta-1-20050831.101112-42", null, "jar" );
332     }
333
334     @Test
335     public void testIsSupportFile()
336     {
337         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.sha1" ) );
338         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.md5" ) );
339         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.asc" ) );
340         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
341         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
342         assertTrue( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
343
344         assertFalse( repoRequest.isSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
345         assertFalse(
346             repoRequest.isSupportFile( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
347         assertFalse( repoRequest.isSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
348         assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
349         assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
350         assertFalse( repoRequest.isSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) );
351     }
352
353     @Test
354     public void testIsMetadata()
355     {
356         assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
357         assertTrue( repoRequest.isMetadata( "org/apache/derby/derby/maven-metadata.xml" ) );
358
359         assertFalse( repoRequest.isMetadata( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
360         assertFalse(
361             repoRequest.isMetadata( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
362         assertFalse( repoRequest.isMetadata( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
363         assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
364         assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
365         assertFalse( repoRequest.isMetadata( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
366     }
367
368     @Test
369     public void testIsMetadataSupportFile()
370     {
371         assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml" ) );
372         assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml" ) );
373         assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.sha1" ) );
374         assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/maven-metadata.xml.md5" ) );
375
376         assertFalse( repoRequest.isMetadataSupportFile( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
377         assertFalse( repoRequest.isMetadataSupportFile(
378             "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
379         assertFalse(
380             repoRequest.isMetadataSupportFile( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
381         assertFalse( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
382         assertFalse(
383             repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
384         assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
385         assertTrue( repoRequest.isMetadataSupportFile( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.md5" ) );
386     }
387
388     @Test
389     public void testIsDefault()
390     {
391         assertNotEquals( "default", repoRequest.getLayout( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
392         assertNotEquals("default", repoRequest.getLayout( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
393         assertNotEquals("default", repoRequest.getLayout( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
394
395         assertEquals("default", repoRequest.getLayout( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
396         assertEquals("default", repoRequest.getLayout( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
397         assertEquals("default", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
398         assertEquals("default", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
399         assertEquals("default", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
400         assertEquals("default", repoRequest.getLayout( "eclipse/jdtcore/maven-metadata.xml" ) );
401         assertEquals("default", repoRequest.getLayout( "eclipse/jdtcore/maven-metadata.xml.sha1" ) );
402         assertEquals("default", repoRequest.getLayout( "eclipse/jdtcore/maven-metadata.xml.md5" ) );
403
404         assertNotEquals("default", repoRequest.getLayout( null ) );
405         assertNotEquals("default", repoRequest.getLayout( "" ) );
406         assertNotEquals("default", repoRequest.getLayout( "foo" ) );
407         assertNotEquals("default", repoRequest.getLayout( "some.short/path" ) );
408     }
409
410     @Test
411     public void testIsLegacy()
412     {
413         assertEquals("legacy", repoRequest.getLayout( "test.maven-arch/poms/test-arch-2.0.3-SNAPSHOT.pom" ) );
414         assertEquals("legacy", repoRequest.getLayout( "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom" ) );
415         assertEquals("legacy", repoRequest.getLayout( "commons-lang/jars/commons-lang-2.1-javadoc.jar" ) );
416
417         assertNotEquals("legacy", repoRequest.getLayout( "test/maven-arch/test-arch/2.0.3-SNAPSHOT/test-arch-2.0.3-SNAPSHOT.jar" ) );
418         assertNotEquals("legacy", repoRequest.getLayout( "org/apache/archiva/archiva-api/1.0/archiva-api-1.0.xml.zip" ) );
419         assertNotEquals("legacy", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz" ) );
420         assertNotEquals("legacy", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/derby-10.2.2.0-bin.tar.gz.pgp" ) );
421         assertNotEquals("legacy", repoRequest.getLayout( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1" ) );
422
423         assertNotEquals("legacy", repoRequest.getLayout( null ) );
424         assertNotEquals("legacy", repoRequest.getLayout( "" ) );
425         assertNotEquals("legacy", repoRequest.getLayout( "some.short/path" ) );
426     }
427
428     private ManagedRepositoryContent createManagedRepo( String layout )
429         throws Exception
430     {
431         Path repoRoot = Paths.get( FileUtils.getBasedir() + "/target/test-repo" );
432         return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout );
433     }
434
435     /**
436      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
437      */
438     @Test
439     public void testToNativePathArtifactDefaultToDefaultDualExtension()
440         throws Exception
441     {
442         ManagedRepositoryContent repository = createManagedRepo( "default" );
443
444         // Test (artifact) default to default - dual extension
445         assertEquals( "/org/project/example-presentation/3.2/example-presentation-3.2.xml.zip",
446                       repoRequest.toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip") );
447     }
448
449
450     @Test
451     public void testToNativePathMetadataDefaultToDefault()
452         throws Exception
453     {
454         ManagedRepositoryContent repository = createManagedRepo( "default" );
455
456         // Test (metadata) default to default
457         assertEquals( "/org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1",
458                       repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/maven-metadata.xml.sha1") );
459     }
460
461
462     @Test
463     public void testNativePathBadRequestTooShort()
464         throws Exception
465     {
466         ManagedRepositoryContent repository = createManagedRepo( "default" );
467
468         // Test bad request path (too short)
469         try
470         {
471             repoRequest.toNativePath( "org.apache.derby/license.txt");
472             fail( "Should have thrown an exception about a too short path." );
473         }
474         catch ( LayoutException e )
475         {
476             // expected path.
477         }
478     }
479
480     @Test
481     public void testNativePathBadRequestBlank()
482         throws Exception
483     {
484         ManagedRepositoryContent repository = createManagedRepo( "default" );
485
486         // Test bad request path (too short)
487         try
488         {
489             repoRequest.toNativePath( "");
490             fail( "Should have thrown an exception about an blank request." );
491         }
492         catch ( LayoutException e )
493         {
494             // expected path.
495         }
496     }
497
498     @Test
499     public void testNativePathBadRequestNull()
500         throws Exception
501     {
502         ManagedRepositoryContent repository = createManagedRepo( "default" );
503
504         // Test bad request path (too short)
505         try
506         {
507             repoRequest.toNativePath( null);
508             fail( "Should have thrown an exception about an null request." );
509         }
510         catch ( LayoutException e )
511         {
512             // expected path.
513         }
514     }
515
516     @Test
517     public void testNativePathBadRequestUnknownType()
518         throws Exception
519     {
520         ManagedRepositoryContent repository = createManagedRepo( "default" );
521
522         // Test bad request path (too short)
523         try
524         {
525             repoRequest.toNativePath( "org/apache/derby/derby/10.2.2.0/license.txt");
526             fail( "Should have thrown an exception about an invalid type." );
527         }
528         catch ( LayoutException e )
529         {
530             // expected path.
531         }
532     }
533
534
535     private void assertValid( String path, String groupId, String artifactId, String version, String artifactVersion, String classifier,
536                               String type )
537         throws Exception
538     {
539         String expectedId =
540             "ArtifactReference - " + groupId + ":" + artifactId + ":" + version + ":" + ( classifier != null ?
541                 classifier + ":" : "" ) + type;
542
543         ItemSelector reference = repoRequest.toItemSelector( path );
544
545         assertNotNull( expectedId + " - Should not be null.", reference );
546
547         assertEquals( expectedId + " - Group ID", groupId, reference.getNamespace() );
548         assertEquals( expectedId + " - Artifact ID", artifactId, reference.getArtifactId() );
549         assertEquals( expectedId + " - Artifact Version", artifactVersion, reference.getArtifactVersion( ) );
550         if ( StringUtils.isNotBlank( classifier ) )
551         {
552             assertEquals( expectedId + " - Classifier", classifier, reference.getClassifier() );
553         }
554         assertEquals( expectedId + " - Version ID", version, reference.getVersion() );
555         assertEquals( expectedId + " - Type", type, reference.getType() );
556     }
557
558     private void assertInvalidRequest( String path )
559     {
560         try
561         {
562             repoRequest.toItemSelector( path );
563             fail( "Expected a LayoutException on an invalid path [" + path + "]" );
564         }
565         catch ( LayoutException e )
566         {
567             /* expected path */
568         }
569     }
570
571     protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, Path location,
572                                                                        String layout )
573         throws Exception
574     {
575         MavenManagedRepository repo = MavenManagedRepository.newLocalInstance( id, name, archivaConfiguration.getRepositoryBaseDir());
576         repo.setLocation( location.toAbsolutePath().toUri() );
577         repo.setLayout( layout );
578
579         RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
580
581         ManagedRepositoryContent repoContent =
582             provider.createManagedContent( repo );
583
584         return repoContent;
585     }
586
587 }