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.archiva.digest.DigesterException;
20 import org.apache.maven.artifact.Artifact;
21 import org.apache.maven.artifact.DefaultArtifact;
22 import org.apache.maven.artifact.handler.ArtifactHandler;
23 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
24 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
25 import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
26 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
27 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
28 import org.apache.maven.artifact.versioning.VersionRange;
31 import java.io.IOException;
32 import java.util.Iterator;
35 * This class tests the ChecksumArtifactReporter.
36 * It extends the AbstractChecksumArtifactReporterTestCase class.
38 public class ChecksumArtifactReporterTest
39 extends AbstractChecksumArtifactReporterTestCase
41 private ArtifactReportProcessor artifactReportProcessor;
43 private ArtifactReporter reporter = new DefaultArtifactReporter();
45 private MetadataReportProcessor metadataReportProcessor;
51 artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" );
52 metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" );
56 * Test the ChecksumArtifactReporter when the checksum files are valid.
58 public void testChecksumArtifactReporterSuccess()
59 throws ReportProcessorException, IOException, DigesterException
61 createChecksumFile( "VALID" );
62 createChecksumFile( "INVALID" );
64 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
65 VersionRange version = VersionRange.createFromVersion( "1.0" );
67 new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
69 artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
70 assertEquals( 2, reporter.getNumSuccesses() );
74 * Test the ChecksumArtifactReporter when the checksum files are invalid.
76 public void testChecksumArtifactReporterFailed()
77 throws ReportProcessorException
79 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
80 VersionRange version = VersionRange.createFromVersion( "1.0" );
82 new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
84 artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
85 assertEquals( 2, reporter.getNumFailures() );
89 * Test the valid checksum of a metadata file.
90 * The reporter should report 2 success validation.
92 public void testChecksumMetadataReporterSuccess()
93 throws ReportProcessorException, DigesterException, IOException
95 createMetadataFile( "VALID" );
96 createMetadataFile( "INVALID" );
98 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
99 VersionRange version = VersionRange.createFromVersion( "1.0" );
101 new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
103 //Version level metadata
104 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
105 metadataReportProcessor.processMetadata( metadata, repository, reporter );
107 //Artifact level metadata
108 metadata = new ArtifactRepositoryMetadata( artifact );
109 metadataReportProcessor.processMetadata( metadata, repository, reporter );
111 //Group level metadata
112 metadata = new GroupRepositoryMetadata( "checksumTest" );
113 metadataReportProcessor.processMetadata( metadata, repository, reporter );
115 Iterator iter = reporter.getRepositoryMetadataSuccessIterator();
116 assertTrue( "check if there is a success", iter.hasNext() );
120 * Test the corrupted checksum of a metadata file.
121 * The reporter must report 2 failures.
123 public void testChecksumMetadataReporterFailure()
124 throws ReportProcessorException
126 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
127 VersionRange version = VersionRange.createFromVersion( "1.0" );
129 new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler );
131 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
132 metadataReportProcessor.processMetadata( metadata, repository, reporter );
134 Iterator iter = reporter.getRepositoryMetadataFailureIterator();
135 assertTrue( "check if there is a failure", iter.hasNext() );
139 * Test the conditional when the checksum files of the artifact & metadata do not exist.
141 public void testChecksumFilesDoNotExist()
142 throws ReportProcessorException, DigesterException, IOException
144 createChecksumFile( "VALID" );
145 createMetadataFile( "VALID" );
146 deleteChecksumFiles( "jar" );
148 ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
149 VersionRange version = VersionRange.createFromVersion( "1.0" );
151 new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler );
153 artifactReportProcessor.processArtifact( null, artifact, reporter, repository );
154 assertEquals( 2, reporter.getNumFailures() );
156 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
157 metadataReportProcessor.processMetadata( metadata, repository, reporter );
159 Iterator iter = reporter.getRepositoryMetadataFailureIterator();
160 assertTrue( "check if there is a failure", iter.hasNext() );
162 deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );