1 package org.apache.maven.repository.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.repository.metadata.ArtifactRepositoryMetadata;
24 import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
25 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
26 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
27 import org.apache.maven.artifact.versioning.VersionRange;
30 import java.util.Iterator;
33 * This class tests the ChecksumArtifactReporter.
34 * It extends the AbstractChecksumArtifactReporterTest class.
36 public class ChecksumArtifactReporterTest
37 extends AbstractChecksumArtifactReporterTest
39 private ArtifactReportProcessor artifactReportProcessor;
41 private ArtifactReporter reporter = new MockArtifactReporter();
43 private MetadataReportProcessor metadataReportProcessor;
45 public ChecksumArtifactReporterTest()
54 artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" );
55 metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" );
58 public void tearDown()
65 * Test creation of artifact with checksum files.
67 public void testCreateChecksumFile()
69 assertTrue( createChecksumFile( "VALID" ) );
70 assertTrue( createChecksumFile( "INVALID" ) );
74 * Test creation of metadata file together with its checksums.
76 public void testCreateMetadataFile()
78 assertTrue( createMetadataFile( "VALID" ) );
79 assertTrue( createMetadataFile( "INVALID" ) );
83 * Test the ChecksumArtifactReporter when the checksum files are valid.
85 public void testChecksumArtifactReporterSuccess()
89 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
90 VersionRange version = VersionRange.createFromVersion( "1.0" );
92 new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
94 artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
95 assertTrue( reporter.getSuccesses() == 2 );
96 //System.out.println( "1 - SUCCESS ---> " + reporter.getSuccesses() );
106 * Test the ChecksumArtifactReporter when the checksum files are invalid.
108 public void testChecksumArtifactReporterFailed()
113 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
114 VersionRange version = VersionRange.createFromVersion( "1.0" );
116 new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
118 artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
119 assertTrue( reporter.getFailures() == 2 );
120 //System.out.println( "2 - FAILURES ---> " + reporter.getFailures() );
122 catch ( Exception e )
129 * Test the valid checksum of a metadata file.
130 * The reporter should report 2 success validation.
132 public void testChecksumMetadataReporterSuccess()
137 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
138 VersionRange version = VersionRange.createFromVersion( "1.0" );
140 new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
142 //Version level metadata
143 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
144 metadataReportProcessor.processMetadata( metadata, repository, reporter );
146 //Artifact level metadata
147 metadata = new ArtifactRepositoryMetadata( artifact );
148 metadataReportProcessor.processMetadata( metadata, repository, reporter );
150 //Group level metadata
151 metadata = new GroupRepositoryMetadata( "checksumTest" );
152 metadataReportProcessor.processMetadata( metadata, repository, reporter );
154 Iterator iter = reporter.getRepositoryMetadataSuccessIterator();
155 //System.out.println( "3 - META SUCCESS ---> " + iter.hasNext() );
156 assertTrue( "check if there is a success", iter.hasNext() );
159 catch ( Exception e )
166 * Test the corrupted checksum of a metadata file.
167 * The reporter must report 2 failures.
169 public void testChecksumMetadataReporterFailure()
174 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
175 VersionRange version = VersionRange.createFromVersion( "1.0" );
177 new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
179 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
180 metadataReportProcessor.processMetadata( metadata, repository, reporter );
182 //System.out.println("reporter.getFailures() ---> " + reporter.getFailures());
184 Iterator iter = reporter.getRepositoryMetadataFailureIterator();
185 //System.out.println( "4 - META FAILURE ---> " + iter.hasNext() );
186 assertTrue( "check if there is a failure", iter.hasNext() );
189 catch ( Exception e )
196 * Test the checksum of an artifact located in a remote location.
198 /* public void testChecksumArtifactRemote()
200 ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType );
201 VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion );
202 Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version, remoteArtifactScope,
203 remoteArtifactType, "", handler );
204 ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl,
205 new DefaultRepositoryLayout() );
207 artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
208 if ( reporter.getFailures() == 2 )
209 assertTrue( reporter.getFailures() == 2 );
211 if ( reporter.getSuccesses() == 2 )
212 assertTrue( reporter.getSuccesses() == 2 );
218 * Test the checksum of a metadata file located in a remote location.
220 /* public void testChecksumMetadataRemote()
225 ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType );
226 VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion );
227 Artifact artifact = new DefaultArtifact( remoteArtifactGroup, remoteArtifactId, version,
228 remoteArtifactScope, remoteArtifactType, "", handler );
229 ArtifactRepository repository = new DefaultArtifactRepository( remoteRepoId, remoteRepoUrl,
230 new DefaultRepositoryLayout() );
232 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
234 metadataReportProcessor.processMetadata( metadata, repository, reporter );
235 Iterator iter = reporter.getRepositoryMetadataFailureIterator();
236 if ( iter.hasNext() )
237 assertTrue( "check if there is a failure", iter.hasNext() );
239 iter = reporter.getRepositoryMetadataSuccessIterator();
240 if ( iter.hasNext() )
241 assertTrue( "check if there is a success", iter.hasNext() );
244 catch ( Exception e )
252 * Test deletion of the test directories created.
254 public void testDeleteChecksumFiles()
256 assertTrue( deleteChecksumFiles( "jar" ) );
260 * Test deletion of the test directories created.
262 public void testDeleteTestDirectory()
264 assertTrue( deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) ) );
268 * Test the conditional when the checksum files of the artifact & metadata do not exist.
270 public void testChecksumFilesDoNotExist()
272 createChecksumFile( "VALID" );
273 createMetadataFile( "VALID" );
274 boolean b = deleteChecksumFiles( "jar" );
278 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
279 VersionRange version = VersionRange.createFromVersion( "1.0" );
281 new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
283 artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
284 //System.out.println( "5 - ART FAILURE ---> " + reporter.getFailures() );
285 assertTrue( reporter.getFailures() == 2 );
287 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
288 metadataReportProcessor.processMetadata( metadata, repository, reporter );
290 Iterator iter = reporter.getRepositoryMetadataFailureIterator();
291 //System.out.println( "5 - META FAILURE ---> " + iter.hasNext() );
292 assertTrue( "check if there is a failure", iter.hasNext() );
295 catch ( Exception e )
300 b = deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );