| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
package org.apache.maven.shared.jar.identification; |
| 20 |
|
| 21 |
import javax.inject.Inject; |
| 22 |
|
| 23 |
import java.io.File; |
| 24 |
|
| 25 |
import org.apache.maven.shared.jar.AbstractJarAnalyzerTestCase; |
| 26 |
import org.apache.maven.shared.jar.JarAnalyzer; |
| 27 |
import org.codehaus.plexus.testing.PlexusTest; |
| 28 |
import org.junit.jupiter.api.Test; |
| 29 |
|
| 30 |
import static org.junit.jupiter.api.Assertions.assertEquals; |
| 31 |
import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 32 |
import static org.junit.jupiter.api.Assertions.assertNull; |
| 33 |
|
| 34 |
/** |
| 35 |
* JarAnalyzer Taxon Analyzer Test Case |
| 36 |
* TODO test the exposers individually instead of in aggregate here (and test the normalize, etc. methods here instead with controlled exposers) |
| 37 |
*/ |
| 38 |
@PlexusTest |
| 39 |
class JarIdentificationAnalyzerTest extends AbstractJarAnalyzerTestCase { |
| 40 |
|
| 41 |
@Inject |
| 42 |
JarIdentificationAnalysis analyzer; |
| 43 |
|
| 44 |
private JarIdentification getJarTaxon(String filename) throws Exception { |
| 45 |
File jarfile = getSampleJar(filename); |
| 46 |
JarIdentification taxon = analyzer.analyze(new JarAnalyzer(jarfile)); |
| 47 |
assertNotNull(taxon, "JarIdentification"); |
| 48 |
return taxon; |
| 49 |
} |
| 50 |
|
| 51 |
@Test |
| 52 |
void testTaxonAnalyzerWithJXR() throws Exception { |
| 53 |
JarIdentification taxon = getJarTaxon("jxr.jar"); |
| 54 |
|
| 55 |
assertEquals("org.apache.maven", taxon.getGroupId(), "identification.groupId"); |
| 56 |
assertEquals("maven-jxr", taxon.getArtifactId(), "identification.artifactId"); |
| 57 |
assertEquals("1.1-SNAPSHOT", taxon.getVersion(), "identification.version"); |
| 58 |
assertEquals("Maven JXR", taxon.getName(), "identification.name"); |
| 59 |
assertEquals("Apache Software Foundation", taxon.getVendor(), "identification.vendor"); |
| 60 |
|
| 61 |
// TODO assert potentials too |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Tests JarAnalyzer with No embedded pom, and no useful manifest.mf information. |
| 66 |
* |
| 67 |
* @throws Exception failures |
| 68 |
*/ |
| 69 |
@Test |
| 70 |
void testTaxonAnalyzerWithCODEC() throws Exception { |
| 71 |
JarIdentification taxon = getJarTaxon("codec.jar"); |
| 72 |
|
| 73 |
assertEquals("org.apache.commons.codec", taxon.getGroupId(), "identification.groupId"); |
| 74 |
assertEquals("codec", taxon.getArtifactId(), "identification.artifactId"); |
| 75 |
// TODO fix assertion |
| 76 |
// assertEquals( "identification.version", "codec_release_1_0_0_interim_20030519095102_build", |
| 77 |
// identification.getVersion() ); |
| 78 |
assertEquals("20030519", taxon.getVersion(), "identification.version"); |
| 79 |
assertEquals("codec", taxon.getName(), "identification.name"); |
| 80 |
assertNull(taxon.getVendor(), "identification.vendor"); |
| 81 |
|
| 82 |
// TODO assert potentials too |
| 83 |
} |
| 84 |
|
| 85 |
@Test |
| 86 |
void testTaxonAnalyzerWithANT() throws Exception { |
| 87 |
JarIdentification taxon = getJarTaxon("ant.jar"); |
| 88 |
|
| 89 |
assertEquals("org.apache.tools.ant", taxon.getGroupId(), "identification.groupId"); |
| 90 |
assertEquals("ant", taxon.getArtifactId(), "identification.artifactId"); |
| 91 |
assertEquals("1.6.5", taxon.getVersion(), "identification.version"); |
| 92 |
// TODO fix assertion |
| 93 |
// assertEquals( "identification.name", "Apache Ant", identification.getName() ); |
| 94 |
assertEquals("Apache Software Foundation", taxon.getVendor(), "identification.vendor"); |
| 95 |
|
| 96 |
// TODO assert potentials too |
| 97 |
} |
| 98 |
} |