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 reportDatabase;
43 artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "artifact-location" );
45 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
46 reportDatabase = new ReportingDatabase( reportGroup );
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, reportDatabase );
59 assertEquals( 0, reportDatabase.getNumFailures() );
60 assertEquals( 0, reportDatabase.getNumWarnings() );
61 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
65 * Test the LocationArtifactReporter when the artifact is in the location specified in the
66 * file system pom (but the jar file does not have a pom included in its package).
68 public void testLocationArtifactReporterSuccess()
69 throws IOException, XmlPullParserException
71 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
72 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
74 Model model = readPom( repository.pathOf( pomArtifact ) );
75 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
76 assertEquals( 0, reportDatabase.getNumFailures() );
77 assertEquals( 0, reportDatabase.getNumWarnings() );
78 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
82 * Test the LocationArtifactReporter when the artifact is in the location specified in the
83 * file system pom, but the pom itself is passed in.
85 public void testLocationArtifactReporterSuccessPom()
86 throws IOException, XmlPullParserException
88 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
90 Model model = readPom( repository.pathOf( pomArtifact ) );
91 artifactReportProcessor.processArtifact( pomArtifact, model, reportDatabase );
92 assertEquals( 0, reportDatabase.getNumFailures() );
93 assertEquals( 0, reportDatabase.getNumWarnings() );
94 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
98 * Test the LocationArtifactReporter when the artifact is in the location specified in the
99 * file system pom, with a classifier.
101 public void testLocationArtifactReporterSuccessClassifier()
102 throws IOException, XmlPullParserException
104 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "java-source" );
105 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
107 Model model = readPom( repository.pathOf( pomArtifact ) );
108 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
109 assertEquals( 0, reportDatabase.getNumFailures() );
110 assertEquals( 0, reportDatabase.getNumWarnings() );
111 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
115 * Test the LocationArtifactReporter when the artifact is in the location specified in the
116 * file system pom, with a classifier.
118 public void testLocationArtifactReporterSuccessZip()
119 throws IOException, XmlPullParserException
122 createArtifactWithClassifier( "groupId", "artifactId", "1.0-alpha-1", "distribution-zip", "src" );
123 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
125 Model model = readPom( repository.pathOf( pomArtifact ) );
126 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
127 assertEquals( 0, reportDatabase.getNumFailures() );
128 assertEquals( 0, reportDatabase.getNumWarnings() );
129 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
133 * Test the LocationArtifactReporter when the artifact is in the location specified in the
134 * file system pom, with a classifier.
136 public void testLocationArtifactReporterSuccessTgz()
137 throws IOException, XmlPullParserException
140 createArtifactWithClassifier( "groupId", "artifactId", "1.0-alpha-1", "distribution-tgz", "src" );
141 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "pom" );
143 Model model = readPom( repository.pathOf( pomArtifact ) );
144 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
145 assertEquals( 0, reportDatabase.getNumFailures() );
146 assertEquals( 0, reportDatabase.getNumWarnings() );
147 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
151 * Test the LocationArtifactReporter when the artifact is not in the location specified
152 * in the file system pom.
154 public void testLocationArtifactReporterFailure()
155 throws IOException, XmlPullParserException
157 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2" );
158 Artifact pomArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-2", "pom" );
160 Model model = readPom( repository.pathOf( pomArtifact ) );
161 artifactReportProcessor.processArtifact( artifact, model, reportDatabase );
163 assertEquals( 1, reportDatabase.getNumFailures() );
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, reportDatabase );
178 assertEquals( 1, reportDatabase.getNumFailures() );
181 private Model readPom( String path )
182 throws IOException, XmlPullParserException
184 Reader reader = new FileReader( new File( repository.getBasedir(), path ) );
185 Model model = new MavenXpp3Reader().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, reportDatabase );
208 assertEquals( 1, reportDatabase.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, reportDatabase );
221 assertEquals( 1, reportDatabase.getNumFailures() );