1 package org.apache.archiva.repository.maven.content;
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
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
21 import org.apache.archiva.metadata.maven.model.MavenArtifactFacet;
22 import org.apache.archiva.metadata.model.ArtifactMetadata;
23 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
24 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
25 import org.apache.archiva.repository.maven.metadata.storage.Maven2RepositoryPathTranslator;
26 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.springframework.test.context.ContextConfiguration;
31 import java.util.Collections;
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertFalse;
37 * ArtifactExtensionMappingTest
41 @RunWith ( ArchivaSpringJUnit4ClassRunner.class )
42 @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
43 public class ArtifactExtensionMappingTest
45 private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator(
46 Collections.<ArtifactMappingProvider>emptyList() );
49 public void testIsMavenPlugin()
51 assertMavenPlugin( "maven-test-plugin" );
52 assertMavenPlugin( "maven-clean-plugin" );
53 assertMavenPlugin( "cobertura-maven-plugin" );
54 assertMavenPlugin( "maven-project-info-reports-plugin" );
55 assertMavenPlugin( "silly-name-for-a-maven-plugin" );
57 assertNotMavenPlugin( "maven-plugin-api" );
58 assertNotMavenPlugin( "foo-lib" );
59 assertNotMavenPlugin( "another-maven-plugin-api" );
60 assertNotMavenPlugin( "secret-maven-plugin-2" );
63 private void assertMavenPlugin( String artifactId )
65 assertEquals( "Should be detected as maven plugin: <" + artifactId + ">", "maven-plugin", getTypeFromArtifactId(
69 private String getTypeFromArtifactId( String artifactId )
71 ArtifactMetadata artifact = pathTranslator.getArtifactFromId( null, "groupId", artifactId, "1.0",
72 artifactId + "-1.0.jar" );
73 MavenArtifactFacet facet = (MavenArtifactFacet) artifact.getFacet( MavenArtifactFacet.FACET_ID );
74 return facet.getType();
77 private void assertNotMavenPlugin( String artifactId )
79 assertFalse( "Should NOT be detected as maven plugin: <" + artifactId + ">", "maven-plugin".equals(
80 getTypeFromArtifactId( artifactId ) ) );