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.reporting.model.MetadataResults;
20 import org.apache.maven.artifact.Artifact;
21 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
22 import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
23 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
24 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
25 import org.codehaus.plexus.digest.DigesterException;
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() );
69 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
73 * Test the ChecksumArtifactReportProcessor when the checksum files are invalid.
75 public void testChecksumArtifactReporterFailed()
77 String s = "invalidArtifact";
79 Artifact artifact = createArtifact( "checksumTest", s, s1 );
81 artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
82 assertEquals( 1, reportingDatabase.getNumFailures() );
83 assertEquals( 0, reportingDatabase.getNumWarnings() );
84 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
88 * Test the valid checksum of a metadata file.
89 * The reportingDatabase should report 2 success validation.
91 public void testChecksumMetadataReporterSuccess()
92 throws DigesterException, IOException
94 createMetadataFile( "VALID" );
95 createMetadataFile( "INVALID" );
97 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
99 //Version level metadata
100 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
101 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
103 //Artifact level metadata
104 metadata = new ArtifactRepositoryMetadata( artifact );
105 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
107 //Group level metadata
108 metadata = new GroupRepositoryMetadata( "checksumTest" );
109 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
113 * Test the corrupted checksum of a metadata file.
114 * The reportingDatabase must report 2 failures.
116 public void testChecksumMetadataReporterFailure()
118 Artifact artifact = createArtifact( "checksumTest", "invalidArtifact", "1.0" );
120 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
121 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
123 Iterator failures = reportingDatabase.getMetadataIterator();
124 assertTrue( "check there is a failure", failures.hasNext() );
125 MetadataResults results = (MetadataResults) failures.next();
126 failures = results.getFailures().iterator();
127 assertTrue( "check there is a failure", failures.hasNext() );
131 * Test the conditional when the checksum files of the artifact & metadata do not exist.
133 public void testChecksumFilesDoNotExist()
134 throws DigesterException, IOException
136 createChecksumFile( "VALID" );
137 createMetadataFile( "VALID" );
138 deleteChecksumFiles( "jar" );
140 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
142 artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
143 assertEquals( 1, reportingDatabase.getNumFailures() );
145 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
146 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
148 Iterator failures = reportingDatabase.getMetadataIterator();
149 assertTrue( "check there is a failure", failures.hasNext() );
150 MetadataResults results = (MetadataResults) failures.next();
151 failures = results.getFailures().iterator();
152 assertTrue( "check there is a failure", failures.hasNext() );
154 deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );