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.artifact.DefaultArtifact;
21 import org.apache.maven.artifact.handler.ArtifactHandler;
22 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
23 import org.apache.maven.artifact.versioning.VersionRange;
24 import org.apache.maven.model.Model;
25 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
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 ArtifactReporter reporter = new DefaultArtifactReporter();
43 private MavenXpp3Reader pomReader;
49 artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "artifact-location" );
50 pomReader = new MavenXpp3Reader();
53 public void tearDown()
57 artifactReportProcessor = null;
62 * Test the LocationArtifactReporter when the artifact's physical location matches the location specified
63 * both in the file system pom and in the pom included in the package.
65 public void testPackagedPomLocationArtifactReporterSuccess()
66 throws ReportProcessorException, IOException, XmlPullParserException
68 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
69 VersionRange version = VersionRange.createFromVersion( "2.0" );
71 new DefaultArtifact( "org.apache.maven", "maven-model", version, "compile", "jar", "", handler );
73 String path = "org/apache/maven/maven-model/2.0/maven-model-2.0.pom";
74 Model model = readPom( path );
76 artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
77 assertEquals( 1, reporter.getNumSuccesses() );
81 * Test the LocationArtifactReporter when the artifact is in the location specified in the
82 * file system pom (but the jar file does not have a pom included in its package).
84 public void testLocationArtifactReporterSuccess()
85 throws ReportProcessorException, IOException, XmlPullParserException
87 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
88 VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" );
89 Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler );
91 String path = "groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom";
92 Model model = readPom( path );
94 artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
95 assertEquals( 1, reporter.getNumSuccesses() );
99 * Test the LocationArtifactReporter when the artifact is not in the location specified
100 * in the file system pom.
102 public void testLocationArtifactReporterFailure()
103 throws IOException, XmlPullParserException, ReportProcessorException
105 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
106 VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" );
107 Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler );
109 String path = "groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom";
110 Model model = readPom( path );
112 artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
113 assertEquals( 1, reporter.getNumFailures() );
117 * Test the LocationArtifactReporter when the artifact's physical location does not match the
118 * location in the file system pom but instead matches the specified location in the packaged pom.
120 public void testFsPomArtifactMatchFailure()
121 throws IOException, ReportProcessorException, XmlPullParserException
123 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
124 VersionRange version = VersionRange.createFromVersion( "2.0" );
126 new DefaultArtifact( "org.apache.maven", "maven-archiver", version, "compile", "jar", "", handler );
128 String path = "org/apache/maven/maven-archiver/2.0/maven-archiver-2.0.pom";
129 Model model = readPom( path );
131 artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
132 assertEquals( 1, reporter.getNumFailures() );
135 private Model readPom( String path )
136 throws IOException, XmlPullParserException
138 Reader reader = new FileReader( new File( repository.getBasedir(), path ) );
139 Model model = pomReader.read( reader );
140 // hokey inheritence to avoid some errors right now
141 if ( model.getGroupId() == null )
143 model.setGroupId( model.getParent().getGroupId() );
145 if ( model.getVersion() == null )
147 model.setVersion( model.getParent().getVersion() );
153 * Test the LocationArtifactReporter when the artifact's physical location does not match the
154 * location specified in the packaged pom but matches the location specified in the file system pom.
156 public void testPkgPomArtifactMatchFailure()
157 throws IOException, XmlPullParserException, ReportProcessorException
159 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
160 VersionRange version = VersionRange.createFromVersion( "2.1" );
162 new DefaultArtifact( "org.apache.maven", "maven-monitor", version, "compile", "jar", "", handler );
164 String path = "org/apache/maven/maven-monitor/2.1/maven-monitor-2.1.pom";
165 Model model = readPom( path );
167 artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
168 assertEquals( 1, reporter.getNumFailures() );
172 * Test the LocationArtifactReporter when the artifact's physical location does not match both the
173 * location specified in the packaged pom and the location specified in the file system pom.
175 public void testBothPomArtifactMatchFailure()
176 throws IOException, XmlPullParserException, ReportProcessorException
178 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
179 VersionRange version = VersionRange.createFromVersion( "2.1" );
181 new DefaultArtifact( "org.apache.maven", "maven-project", version, "compile", "jar", "", handler );
183 String path = "org/apache/maven/maven-project/2.1/maven-project-2.1.pom";
184 Model model = readPom( path );
186 artifactReportProcessor.processArtifact( model, artifact, reporter, repository );
187 assertEquals( 1, reporter.getNumFailures() );