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