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