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.archiva.reporting.model.MetadataResults;
21 import org.apache.maven.artifact.Artifact;
22 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
23 import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
24 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
25 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
28 import java.io.IOException;
29 import java.util.Iterator;
32 * This class tests the ChecksumArtifactReportProcessor.
33 * It extends the AbstractChecksumArtifactReporterTestCase class.
35 public class ChecksumArtifactReporterTest
36 extends AbstractChecksumArtifactReporterTestCase
38 private ArtifactReportProcessor artifactReportProcessor;
40 private ReportingDatabase reporter = new ReportingDatabase();
42 private MetadataReportProcessor metadataReportProcessor;
48 artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" );
49 metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" );
53 * Test the ChecksumArtifactReportProcessor when the checksum files are valid.
55 public void testChecksumArtifactReporterSuccess()
56 throws DigesterException, IOException
58 createChecksumFile( "VALID" );
59 createChecksumFile( "INVALID" );
61 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
63 artifactReportProcessor.processArtifact( artifact, null, reporter );
64 assertEquals( 0, reporter.getNumFailures() );
65 assertEquals( 0, reporter.getNumWarnings() );
69 * Test the ChecksumArtifactReportProcessor when the checksum files are invalid.
71 public void testChecksumArtifactReporterFailed()
73 String s = "invalidArtifact";
75 Artifact artifact = createArtifact( "checksumTest", s, s1 );
77 artifactReportProcessor.processArtifact( artifact, null, reporter );
78 assertEquals( 1, reporter.getNumFailures() );
79 assertEquals( 0, reporter.getNumWarnings() );
83 * Test the valid checksum of a metadata file.
84 * The reporter should report 2 success validation.
86 public void testChecksumMetadataReporterSuccess()
87 throws DigesterException, IOException
89 createMetadataFile( "VALID" );
90 createMetadataFile( "INVALID" );
92 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
94 //Version level metadata
95 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
96 metadataReportProcessor.processMetadata( metadata, repository, reporter );
98 //Artifact level metadata
99 metadata = new ArtifactRepositoryMetadata( artifact );
100 metadataReportProcessor.processMetadata( metadata, repository, reporter );
102 //Group level metadata
103 metadata = new GroupRepositoryMetadata( "checksumTest" );
104 metadataReportProcessor.processMetadata( metadata, repository, reporter );
108 * Test the corrupted checksum of a metadata file.
109 * The reporter must report 2 failures.
111 public void testChecksumMetadataReporterFailure()
113 Artifact artifact = createArtifact( "checksumTest", "invalidArtifact", "1.0" );
115 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
116 metadataReportProcessor.processMetadata( metadata, repository, reporter );
118 Iterator failures = reporter.getMetadataIterator();
119 assertTrue( "check there is a failure", failures.hasNext() );
120 MetadataResults results = (MetadataResults) failures.next();
121 failures = results.getFailures().iterator();
122 assertTrue( "check there is a failure", failures.hasNext() );
126 * Test the conditional when the checksum files of the artifact & metadata do not exist.
128 public void testChecksumFilesDoNotExist()
129 throws DigesterException, IOException
131 createChecksumFile( "VALID" );
132 createMetadataFile( "VALID" );
133 deleteChecksumFiles( "jar" );
135 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
137 artifactReportProcessor.processArtifact( artifact, null, reporter );
138 assertEquals( 1, reporter.getNumFailures() );
140 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
141 metadataReportProcessor.processMetadata( metadata, repository, reporter );
143 Iterator failures = reporter.getMetadataIterator();
144 assertTrue( "check there is a failure", failures.hasNext() );
145 MetadataResults results = (MetadataResults) failures.next();
146 failures = results.getFailures().iterator();
147 assertTrue( "check there is a failure", failures.hasNext() );
149 deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );