View Javadoc
1   package org.apache.archiva.repository.content.maven2;
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   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * ArtifactExtensionMappingTest
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  }