1 package org.apache.archiva.repository.content.maven2;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.archiva.metadata.model.ArtifactMetadata;
23 import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
24 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
25 import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
26 import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
27 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.springframework.test.context.ContextConfiguration;
31
32 import java.util.Collections;
33
34 import static org.junit.Assert.assertEquals;
35 import static org.junit.Assert.assertFalse;
36
37
38
39
40
41
42 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
43 @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
44 public class ArtifactExtensionMappingTest
45 {
46 private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator(
47 Collections.<ArtifactMappingProvider>emptyList() );
48
49 @Test
50 public void testIsMavenPlugin()
51 {
52 assertMavenPlugin( "maven-test-plugin" );
53 assertMavenPlugin( "maven-clean-plugin" );
54 assertMavenPlugin( "cobertura-maven-plugin" );
55 assertMavenPlugin( "maven-project-info-reports-plugin" );
56 assertMavenPlugin( "silly-name-for-a-maven-plugin" );
57
58 assertNotMavenPlugin( "maven-plugin-api" );
59 assertNotMavenPlugin( "foo-lib" );
60 assertNotMavenPlugin( "another-maven-plugin-api" );
61 assertNotMavenPlugin( "secret-maven-plugin-2" );
62 }
63
64 private void assertMavenPlugin( String artifactId )
65 {
66 assertEquals( "Should be detected as maven plugin: <" + artifactId + ">", "maven-plugin", getTypeFromArtifactId(
67 artifactId ) );
68 }
69
70 private String getTypeFromArtifactId( String artifactId )
71 {
72 ArtifactMetadata artifact = pathTranslator.getArtifactFromId( null, "groupId", artifactId, "1.0",
73 artifactId + "-1.0.jar" );
74 MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID );
75 return facet.getType();
76 }
77
78 private void assertNotMavenPlugin( String artifactId )
79 {
80 assertFalse( "Should NOT be detected as maven plugin: <" + artifactId + ">", "maven-plugin".equals(
81 getTypeFromArtifactId( artifactId ) ) );
82 }
83 }