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();
50 * Test the LocationArtifactReporter when the artifact's physical location matches the location specified
51 * both in the file system pom and in the pom included in the package.
53 public void testPackagedPomLocationArtifactReporterSuccess()
54 throws IOException, XmlPullParserException
56 Artifact artifact = createArtifact( "org.apache.maven", "maven-model", "2.0" );
58 artifactReportProcessor.processArtifact( artifact, null, reporter );
59 assertEquals( 0, reporter.getNumFailures() );
60 assertEquals( 0, reporter.getNumWarnings() );
64 * Test the LocationArtifactReporter when the artifact is in the location specified in the
65 * file system pom (but the jar file does not have a pom included in its package).
67 public void testLocationArtifactReporterSuccess()
68 throws IOException, XmlPullParserException
70 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
71 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
73 Model model = readPom( repository.pathOf( pomArtifact ) );
74 artifactReportProcessor.processArtifact( artifact, model, reporter );
75 assertEquals( 0, reporter.getNumFailures() );
76 assertEquals( 0, reporter.getNumWarnings() );
80 * Test the LocationArtifactReporter when the artifact is in the location specified in the
81 * file system pom, but the pom itself is passed in.
83 public void testLocationArtifactReporterSuccessPom()
84 throws IOException, XmlPullParserException
86 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
88 Model model = readPom( repository.pathOf( pomArtifact ) );
89 artifactReportProcessor.processArtifact( pomArtifact, model, reporter );
90 assertEquals( 0, reporter.getNumFailures() );
91 assertEquals( 0, reporter.getNumWarnings() );
95 * Test the LocationArtifactReporter when the artifact is in the location specified in the
96 * file system pom, with a classifier.
98 public void testLocationArtifactReporterSuccessClassifier()
99 throws IOException, XmlPullParserException
101 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "java-source" );
102 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
104 Model model = readPom( repository.pathOf( pomArtifact ) );
105 artifactReportProcessor.processArtifact( artifact, model, reporter );
106 assertEquals( 0, reporter.getNumFailures() );
107 assertEquals( 0, reporter.getNumWarnings() );
111 * Test the LocationArtifactReporter when the artifact is in the location specified in the
112 * file system pom, with a classifier.
114 public void testLocationArtifactReporterSuccessZip()
115 throws IOException, XmlPullParserException
118 createArtifactWithClassifier( "groupId", "artifactId", "1.0-alpha-1", "distribution-zip", "src" );
119 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
121 Model model = readPom( repository.pathOf( pomArtifact ) );
122 artifactReportProcessor.processArtifact( artifact, model, reporter );
123 assertEquals( 0, reporter.getNumFailures() );
124 assertEquals( 0, reporter.getNumWarnings() );
128 * Test the LocationArtifactReporter when the artifact is in the location specified in the
129 * file system pom, with a classifier.
131 public void testLocationArtifactReporterSuccessTgz()
132 throws IOException, XmlPullParserException
135 createArtifactWithClassifier( "groupId", "artifactId", "1.0-alpha-1", "distribution-tgz", "src" );
136 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
138 Model model = readPom( repository.pathOf( pomArtifact ) );
139 artifactReportProcessor.processArtifact( artifact, model, reporter );
140 assertEquals( 0, reporter.getNumFailures() );
141 assertEquals( 0, reporter.getNumWarnings() );
145 * Test the LocationArtifactReporter when the artifact is not in the location specified
146 * in the file system pom.
148 public void testLocationArtifactReporterFailure()
149 throws IOException, XmlPullParserException
151 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2" );
152 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2", "pom" );
156 Model model = readPom( repository.pathOf( pomArtifact ) );
157 artifactReportProcessor.processArtifact( artifact, model, reporter );
158 fail( "Should not have passed the artifact" );
160 catch ( IllegalStateException e )
167 * Test the LocationArtifactReporter when the artifact's physical location does not match the
168 * location in the file system pom but instead matches the specified location in the packaged pom.
170 public void testFsPomArtifactMatchFailure()
171 throws IOException, XmlPullParserException
173 Artifact artifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0" );
175 Artifact pomArtifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0", "pom" );
176 Model model = readPom( repository.pathOf( pomArtifact ) );
177 artifactReportProcessor.processArtifact( artifact, model, reporter );
178 assertEquals( 1, reporter.getNumFailures() );
181 private Model readPom( String path )
182 throws IOException, XmlPullParserException
184 Reader reader = new FileReader( new File( repository.getBasedir(), path ) );
185 Model model = pomReader.read( reader );
186 // hokey inheritence to avoid some errors right now
187 if ( model.getGroupId() == null )
189 model.setGroupId( model.getParent().getGroupId() );
191 if ( model.getVersion() == null )
193 model.setVersion( model.getParent().getVersion() );
199 * Test the LocationArtifactReporter when the artifact's physical location does not match the
200 * location specified in the packaged pom but matches the location specified in the file system pom.
202 public void testPkgPomArtifactMatchFailure()
203 throws IOException, XmlPullParserException
205 Artifact artifact = createArtifact( "org.apache.maven", "maven-monitor", "2.1" );
207 artifactReportProcessor.processArtifact( artifact, null, reporter );
208 assertEquals( 1, reporter.getNumFailures() );
212 * Test the LocationArtifactReporter when the artifact's physical location does not match both the
213 * location specified in the packaged pom and the location specified in the file system pom.
215 public void testBothPomArtifactMatchFailure()
216 throws IOException, XmlPullParserException
218 Artifact artifact = createArtifact( "org.apache.maven", "maven-project", "2.1" );
220 artifactReportProcessor.processArtifact( artifact, null, reporter );
221 assertEquals( 1, reporter.getNumFailures() );