View Javadoc
1   package org.apache.maven.shared.jar.identification;
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.maven.shared.jar.AbstractJarAnalyzerTestCase;
23  import org.apache.maven.shared.jar.JarAnalyzer;
24  
25  import java.io.File;
26  
27  
28  /**
29   * JarAnalyzer Taxon Analyzer Test Case
30   *
31   * @todo test the exposers individually instead of in aggregate here (and test the normalize, etc. methods here instead with controlled exposers)
32   */
33  public class JarIdentificationAnalyzerTest
34      extends AbstractJarAnalyzerTestCase
35  {
36      private JarIdentification getJarTaxon( String filename )
37          throws Exception
38      {
39          File jarfile = getSampleJar( filename );
40  
41          JarIdentificationAnalysis analyzer =
42              (JarIdentificationAnalysis) lookup( JarIdentificationAnalysis.class.getName() );
43          JarIdentification taxon = analyzer.analyze( new JarAnalyzer( jarfile ) );
44          assertNotNull( "JarIdentification", taxon );
45  
46          return taxon;
47      }
48  
49      public void testTaxonAnalyzerWithJXR()
50          throws Exception
51      {
52          JarIdentification taxon = getJarTaxon( "jxr.jar" );
53  
54          assertEquals( "identification.groupId", "org.apache.maven", taxon.getGroupId() );
55          assertEquals( "identification.artifactId", "maven-jxr", taxon.getArtifactId() );
56          assertEquals( "identification.version", "1.1-SNAPSHOT", taxon.getVersion() );
57          assertEquals( "identification.name", "Maven JXR", taxon.getName() );
58          assertEquals( "identification.vendor", "Apache Software Foundation", taxon.getVendor() );
59  
60          // TODO assert potentials too
61      }
62  
63      /**
64       * Tests JarAnalyzer with No embedded pom, and no useful manifest.mf information.
65       *
66       * @throws Exception failures
67       */
68      public void testTaxonAnalyzerWithCODEC()
69          throws Exception
70      {
71          JarIdentification taxon = getJarTaxon( "codec.jar" );
72  
73          assertEquals( "identification.groupId", "org.apache.commons.codec", taxon.getGroupId() );
74          assertEquals( "identification.artifactId", "codec", taxon.getArtifactId() );
75          // TODO fix assertion
76          // assertEquals( "identification.version", "codec_release_1_0_0_interim_20030519095102_build", identification.getVersion() );
77          assertEquals( "identification.version", "20030519", taxon.getVersion() );
78          assertEquals( "identification.name", "codec", taxon.getName() );
79          assertNull( "identification.vendor", taxon.getVendor() );
80  
81          // TODO assert potentials too
82      }
83  
84      public void testTaxonAnalyzerWithANT()
85          throws Exception
86      {
87          JarIdentification taxon = getJarTaxon( "ant.jar" );
88  
89          assertEquals( "identification.groupId", "org.apache.tools.ant", taxon.getGroupId() );
90          assertEquals( "identification.artifactId", "ant", taxon.getArtifactId() );
91          assertEquals( "identification.version", "1.6.5", taxon.getVersion() );
92          // TODO fix assertion
93          // assertEquals( "identification.name", "Apache Ant", identification.getName() );
94          assertEquals( "identification.vendor", "Apache Software Foundation", taxon.getVendor() );
95  
96          // TODO assert potentials too
97      }
98  }