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" );
79 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
81 Model model = readPom( repository.pathOf( pomArtifact ) );
82 artifactReportProcessor.processArtifact( artifact, model, reporter );
83 assertEquals( 0, reporter.getNumFailures() );
84 assertEquals( 0, reporter.getNumWarnings() );
88 * Test the LocationArtifactReporter when the artifact is in the location specified in the
89 * file system pom, but the pom itself is passed in.
91 public void testLocationArtifactReporterSuccessPom()
92 throws IOException, XmlPullParserException
94 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
96 Model model = readPom( repository.pathOf( pomArtifact ) );
97 artifactReportProcessor.processArtifact( pomArtifact, model, reporter );
98 assertEquals( 0, reporter.getNumFailures() );
99 assertEquals( 0, reporter.getNumWarnings() );
103 * Test the LocationArtifactReporter when the artifact is in the location specified in the
104 * file system pom, with a classifier.
106 public void testLocationArtifactReporterSuccessClassifier()
107 throws IOException, XmlPullParserException
109 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "java-source" );
110 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
112 Model model = readPom( repository.pathOf( pomArtifact ) );
113 artifactReportProcessor.processArtifact( artifact, model, reporter );
114 assertEquals( 0, reporter.getNumFailures() );
115 assertEquals( 0, reporter.getNumWarnings() );
119 * Test the LocationArtifactReporter when the artifact is not in the location specified
120 * in the file system pom.
122 public void testLocationArtifactReporterFailure()
123 throws IOException, XmlPullParserException
125 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2" );
126 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2", "pom" );
130 Model model = readPom( repository.pathOf( pomArtifact ) );
131 artifactReportProcessor.processArtifact( artifact, model, reporter );
132 fail( "Should not have passed the artifact" );
134 catch ( IllegalStateException e )
141 * Test the LocationArtifactReporter when the artifact's physical location does not match the
142 * location in the file system pom but instead matches the specified location in the packaged pom.
144 public void testFsPomArtifactMatchFailure()
145 throws IOException, XmlPullParserException
147 Artifact artifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0" );
149 Artifact pomArtifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0", "pom" );
150 Model model = readPom( repository.pathOf( pomArtifact ) );
151 artifactReportProcessor.processArtifact( artifact, model, reporter );
152 assertEquals( 1, reporter.getNumFailures() );
155 private Model readPom( String path )
156 throws IOException, XmlPullParserException
158 Reader reader = new FileReader( new File( repository.getBasedir(), path ) );
159 Model model = pomReader.read( reader );
160 // hokey inheritence to avoid some errors right now
161 if ( model.getGroupId() == null )
163 model.setGroupId( model.getParent().getGroupId() );
165 if ( model.getVersion() == null )
167 model.setVersion( model.getParent().getVersion() );
173 * Test the LocationArtifactReporter when the artifact's physical location does not match the
174 * location specified in the packaged pom but matches the location specified in the file system pom.
176 public void testPkgPomArtifactMatchFailure()
177 throws IOException, XmlPullParserException
179 Artifact artifact = createArtifact( "org.apache.maven", "maven-monitor", "2.1" );
181 artifactReportProcessor.processArtifact( artifact, null, reporter );
182 assertEquals( 1, reporter.getNumFailures() );
186 * Test the LocationArtifactReporter when the artifact's physical location does not match both the
187 * location specified in the packaged pom and the location specified in the file system pom.
189 public void testBothPomArtifactMatchFailure()
190 throws IOException, XmlPullParserException
192 Artifact artifact = createArtifact( "org.apache.maven", "maven-project", "2.1" );
194 artifactReportProcessor.processArtifact( artifact, null, reporter );
195 assertEquals( 1, reporter.getNumFailures() );