1 package org.apache.maven.archiva.reporting;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.artifact.Artifact;
20 import org.apache.maven.model.Model;
21 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
22 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.io.Reader;
30 * This class tests the LocationArtifactReportProcessor.
32 public class LocationArtifactReportProcessorTest
33 extends AbstractRepositoryReportsTestCase
35 private ArtifactReportProcessor artifactReportProcessor;
37 private ReportingDatabase reporter = new ReportingDatabase();
39 private MavenXpp3Reader pomReader;
45 artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "artifact-location" );
46 pomReader = new MavenXpp3Reader();
49 public void tearDown()
53 artifactReportProcessor = null;
58 * Test the LocationArtifactReporter when the artifact's physical location matches the location specified
59 * both in the file system pom and in the pom included in the package.
61 public void testPackagedPomLocationArtifactReporterSuccess()
62 throws IOException, XmlPullParserException
64 Artifact artifact = createArtifact( "org.apache.maven", "maven-model", "2.0" );
66 artifactReportProcessor.processArtifact( artifact, null, reporter );
67 assertEquals( 0, reporter.getNumFailures() );
68 assertEquals( 0, reporter.getNumWarnings() );
72 * Test the LocationArtifactReporter when the artifact is in the location specified in the
73 * file system pom (but the jar file does not have a pom included in its package).
75 public void testLocationArtifactReporterSuccess()
76 throws IOException, XmlPullParserException
78 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
80 artifactReportProcessor.processArtifact( artifact, null, reporter );
81 assertEquals( 0, reporter.getNumFailures() );
82 assertEquals( 0, reporter.getNumWarnings() );
86 * Test the LocationArtifactReporter when the artifact is not in the location specified
87 * in the file system pom.
89 public void testLocationArtifactReporterFailure()
90 throws IOException, XmlPullParserException
92 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2" );
94 artifactReportProcessor.processArtifact( artifact, null, reporter );
95 assertEquals( 1, reporter.getNumFailures() );
99 * Test the LocationArtifactReporter when the artifact's physical location does not match the
100 * location in the file system pom but instead matches the specified location in the packaged pom.
102 public void testFsPomArtifactMatchFailure()
103 throws IOException, XmlPullParserException
105 Artifact artifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0" );
107 Artifact pomArtifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0", "pom" );
108 Model model = readPom( repository.pathOf( pomArtifact ) );
109 artifactReportProcessor.processArtifact( artifact, model, reporter );
110 assertEquals( 1, reporter.getNumFailures() );
113 private Model readPom( String path )
114 throws IOException, XmlPullParserException
116 Reader reader = new FileReader( new File( repository.getBasedir(), path ) );
117 Model model = pomReader.read( reader );
118 // hokey inheritence to avoid some errors right now
119 if ( model.getGroupId() == null )
121 model.setGroupId( model.getParent().getGroupId() );
123 if ( model.getVersion() == null )
125 model.setVersion( model.getParent().getVersion() );
131 * Test the LocationArtifactReporter when the artifact's physical location does not match the
132 * location specified in the packaged pom but matches the location specified in the file system pom.
134 public void testPkgPomArtifactMatchFailure()
135 throws IOException, XmlPullParserException
137 Artifact artifact = createArtifact( "org.apache.maven", "maven-monitor", "2.1" );
139 artifactReportProcessor.processArtifact( artifact, null, reporter );
140 assertEquals( 1, reporter.getNumFailures() );
144 * Test the LocationArtifactReporter when the artifact's physical location does not match both the
145 * location specified in the packaged pom and the location specified in the file system pom.
147 public void testBothPomArtifactMatchFailure()
148 throws IOException, XmlPullParserException
150 Artifact artifact = createArtifact( "org.apache.maven", "maven-project", "2.1" );
152 artifactReportProcessor.processArtifact( artifact, null, reporter );
153 assertEquals( 1, reporter.getNumFailures() );