1 package org.apache.maven.archiva.reporting.processor;
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.apache.maven.archiva.reporting.group.ReportGroup;
23 import org.apache.maven.archiva.reporting.processor.ArtifactReportProcessor;
24 import org.apache.maven.archiva.reporting.AbstractRepositoryReportsTestCase;
25 import org.apache.maven.archiva.reporting.database.ReportingDatabase;
26 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
29 import java.io.FileReader;
30 import java.io.IOException;
31 import java.io.Reader;
34 * This class tests the LocationArtifactReportProcessor.
36 public class LocationArtifactReportProcessorTest
37 extends AbstractRepositoryReportsTestCase
39 private ArtifactReportProcessor artifactReportProcessor;
41 private ReportingDatabase reportDatabase;
47 artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "artifact-location" );
49 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
50 reportDatabase = new ReportingDatabase( reportGroup );
54 * Test the LocationArtifactReporter when the artifact's physical location matches the location specified
55 * both in the file system pom and in the pom included in the package.
57 public void testPackagedPomLocationArtifactReporterSuccess()
58 throws IOException, XmlPullParserException
60 Artifact artifact = createArtifact( "org.apache.maven", "maven-model", "2.0" );
62 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
63 assertEquals( 0, reportDatabase.getNumFailures() );
64 assertEquals( 0, reportDatabase.getNumWarnings() );
65 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
69 * Test the LocationArtifactReporter when the artifact is in the location specified in the
70 * file system pom (but the jar file does not have a pom included in its package).
72 public void testLocationArtifactReporterSuccess()
73 throws IOException, XmlPullParserException
75 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
76 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
78 Model model = readPom( repository.pathOf( pomArtifact ) );
79 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
80 assertEquals( 0, reportDatabase.getNumFailures() );
81 assertEquals( 0, reportDatabase.getNumWarnings() );
82 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
86 * Test the LocationArtifactReporter when the artifact is in the location specified in the
87 * file system pom, but the pom itself is passed in.
89 public void testLocationArtifactReporterSuccessPom()
90 throws IOException, XmlPullParserException
92 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
94 Model model = readPom( repository.pathOf( pomArtifact ) );
95 artifactReportProcessor.processArtifact( pomArtifact, model, reportDatabase );
96 assertEquals( 0, reportDatabase.getNumFailures() );
97 assertEquals( 0, reportDatabase.getNumWarnings() );
98 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
102 * Test the LocationArtifactReporter when the artifact is in the location specified in the
103 * file system pom, with a classifier.
105 public void testLocationArtifactReporterSuccessClassifier()
106 throws IOException, XmlPullParserException
108 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "java-source" );
109 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
111 Model model = readPom( repository.pathOf( pomArtifact ) );
112 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
113 assertEquals( 0, reportDatabase.getNumFailures() );
114 assertEquals( 0, reportDatabase.getNumWarnings() );
115 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
119 * Test the LocationArtifactReporter when the artifact is in the location specified in the
120 * file system pom, with a classifier.
122 public void testLocationArtifactReporterSuccessZip()
123 throws IOException, XmlPullParserException
126 createArtifactWithClassifier( "groupId", "artifactId", "1.0-alpha-1", "distribution-zip", "src" );
127 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
129 Model model = readPom( repository.pathOf( pomArtifact ) );
130 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
131 assertEquals( 0, reportDatabase.getNumFailures() );
132 assertEquals( 0, reportDatabase.getNumWarnings() );
133 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
137 * Test the LocationArtifactReporter when the artifact is in the location specified in the
138 * file system pom, with a classifier.
140 public void testLocationArtifactReporterSuccessTgz()
141 throws IOException, XmlPullParserException
144 createArtifactWithClassifier( "groupId", "artifactId", "1.0-alpha-1", "distribution-tgz", "src" );
145 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
147 Model model = readPom( repository.pathOf( pomArtifact ) );
148 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
149 assertEquals( 0, reportDatabase.getNumFailures() );
150 assertEquals( 0, reportDatabase.getNumWarnings() );
151 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
155 * Test the LocationArtifactReporter when the artifact is not in the location specified
156 * in the file system pom.
158 public void testLocationArtifactReporterFailure()
159 throws IOException, XmlPullParserException
161 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2" );
162 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2", "pom" );
164 Model model = readPom( repository.pathOf( pomArtifact ) );
165 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
167 assertEquals( 1, reportDatabase.getNumFailures() );
171 * Test the LocationArtifactReporter when the artifact's physical location does not match the
172 * location in the file system pom but instead matches the specified location in the packaged pom.
174 public void testFsPomArtifactMatchFailure()
175 throws IOException, XmlPullParserException
177 Artifact artifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0" );
179 Artifact pomArtifact = createArtifact( "org.apache.maven", "maven-archiver", "2.0", "pom" );
180 Model model = readPom( repository.pathOf( pomArtifact ) );
181 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
182 assertEquals( 1, reportDatabase.getNumFailures() );
185 private Model readPom( String path )
186 throws IOException, XmlPullParserException
188 Reader reader = new FileReader( new File( repository.getBasedir(), path ) );
189 Model model = new MavenXpp3Reader().read( reader );
190 // hokey inheritence to avoid some errors right now
191 if ( model.getGroupId() == null )
193 model.setGroupId( model.getParent().getGroupId() );
195 if ( model.getVersion() == null )
197 model.setVersion( model.getParent().getVersion() );
203 * Test the LocationArtifactReporter when the artifact's physical location does not match the
204 * location specified in the packaged pom but matches the location specified in the file system pom.
206 public void testPkgPomArtifactMatchFailure()
207 throws IOException, XmlPullParserException
209 Artifact artifact = createArtifact( "org.apache.maven", "maven-monitor", "2.1" );
211 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
212 assertEquals( 1, reportDatabase.getNumFailures() );
216 * Test the LocationArtifactReporter when the artifact's physical location does not match both the
217 * location specified in the packaged pom and the location specified in the file system pom.
219 public void testBothPomArtifactMatchFailure()
220 throws IOException, XmlPullParserException
222 Artifact artifact = createArtifact( "org.apache.maven", "maven-project", "2.1" );
224 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
225 assertEquals( 1, reportDatabase.getNumFailures() );