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 reportingDatabase;
42 private MetadataReportProcessor metadataReportProcessor;
48 artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" );
49 metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" );
51 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
52 reportingDatabase = new ReportingDatabase( reportGroup );
56 * Test the ChecksumArtifactReportProcessor when the checksum files are valid.
58 public void testChecksumArtifactReporterSuccess()
59 throws DigesterException, IOException
61 createChecksumFile( "VALID" );
62 createChecksumFile( "INVALID" );
64 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
66 artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
67 assertEquals( 0, reportingDatabase.getNumFailures() );
68 assertEquals( 0, reportingDatabase.getNumWarnings() );
72 * Test the ChecksumArtifactReportProcessor when the checksum files are invalid.
74 public void testChecksumArtifactReporterFailed()
76 String s = "invalidArtifact";
78 Artifact artifact = createArtifact( "checksumTest", s, s1 );
80 artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
81 assertEquals( 1, reportingDatabase.getNumFailures() );
82 assertEquals( 0, reportingDatabase.getNumWarnings() );
86 * Test the valid checksum of a metadata file.
87 * The reportingDatabase should report 2 success validation.
89 public void testChecksumMetadataReporterSuccess()
90 throws DigesterException, IOException
92 createMetadataFile( "VALID" );
93 createMetadataFile( "INVALID" );
95 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
97 //Version level metadata
98 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
99 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
101 //Artifact level metadata
102 metadata = new ArtifactRepositoryMetadata( artifact );
103 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
105 //Group level metadata
106 metadata = new GroupRepositoryMetadata( "checksumTest" );
107 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
111 * Test the corrupted checksum of a metadata file.
112 * The reportingDatabase must report 2 failures.
114 public void testChecksumMetadataReporterFailure()
116 Artifact artifact = createArtifact( "checksumTest", "invalidArtifact", "1.0" );
118 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
119 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
121 Iterator failures = reportingDatabase.getMetadataIterator();
122 assertTrue( "check there is a failure", failures.hasNext() );
123 MetadataResults results = (MetadataResults) failures.next();
124 failures = results.getFailures().iterator();
125 assertTrue( "check there is a failure", failures.hasNext() );
129 * Test the conditional when the checksum files of the artifact & metadata do not exist.
131 public void testChecksumFilesDoNotExist()
132 throws DigesterException, IOException
134 createChecksumFile( "VALID" );
135 createMetadataFile( "VALID" );
136 deleteChecksumFiles( "jar" );
138 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
140 artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
141 assertEquals( 1, reportingDatabase.getNumFailures() );
143 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
144 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
146 Iterator failures = reportingDatabase.getMetadataIterator();
147 assertTrue( "check there is a failure", failures.hasNext() );
148 MetadataResults results = (MetadataResults) failures.next();
149 failures = results.getFailures().iterator();
150 assertTrue( "check there is a failure", failures.hasNext() );
152 deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );