1 package org.apache.maven.archiva.reporting.reporter;
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.archiva.reporting.group.ReportGroup;
21 import org.apache.maven.archiva.reporting.processor.ArtifactReportProcessor;
22 import org.apache.maven.archiva.reporting.processor.MetadataReportProcessor;
23 import org.apache.maven.archiva.reporting.reporter.AbstractChecksumArtifactReporterTestCase;
24 import org.apache.maven.archiva.reporting.database.ReportingDatabase;
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
27 import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;
28 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
29 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
30 import org.codehaus.plexus.digest.DigesterException;
33 import java.io.IOException;
34 import java.util.Iterator;
37 * This class tests the ChecksumArtifactReportProcessor.
38 * It extends the AbstractChecksumArtifactReporterTestCase class.
40 public class ChecksumArtifactReporterTest
41 extends AbstractChecksumArtifactReporterTestCase
43 private ArtifactReportProcessor artifactReportProcessor;
45 private ReportingDatabase reportingDatabase;
47 private MetadataReportProcessor metadataReportProcessor;
53 artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" );
54 metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" );
56 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
57 reportingDatabase = new ReportingDatabase( reportGroup );
61 * Test the ChecksumArtifactReportProcessor when the checksum files are valid.
63 public void testChecksumArtifactReporterSuccess()
64 throws DigesterException, IOException
66 createChecksumFile( "VALID" );
67 createChecksumFile( "INVALID" );
69 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
71 artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
72 assertEquals( 0, reportingDatabase.getNumFailures() );
73 assertEquals( 0, reportingDatabase.getNumWarnings() );
74 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
78 * Test the ChecksumArtifactReportProcessor when the checksum files are invalid.
80 public void testChecksumArtifactReporterFailed()
82 String s = "invalidArtifact";
84 Artifact artifact = createArtifact( "checksumTest", s, s1 );
86 artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
87 assertEquals( 1, reportingDatabase.getNumFailures() );
88 assertEquals( 0, reportingDatabase.getNumWarnings() );
89 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
93 * Test the valid checksum of a metadata file.
94 * The reportingDatabase should report 2 success validation.
96 public void testChecksumMetadataReporterSuccess()
97 throws DigesterException, IOException
99 createMetadataFile( "VALID" );
100 createMetadataFile( "INVALID" );
102 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
104 //Version level metadata
105 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
106 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
108 //Artifact level metadata
109 metadata = new ArtifactRepositoryMetadata( artifact );
110 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
112 //Group level metadata
113 metadata = new GroupRepositoryMetadata( "checksumTest" );
114 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
118 * Test the corrupted checksum of a metadata file.
119 * The reportingDatabase must report 2 failures.
121 public void testChecksumMetadataReporterFailure()
123 Artifact artifact = createArtifact( "checksumTest", "invalidArtifact", "1.0" );
125 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
126 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
128 Iterator failures = reportingDatabase.getMetadataIterator();
129 assertTrue( "check there is a failure", failures.hasNext() );
130 MetadataResults results = (MetadataResults) failures.next();
131 failures = results.getFailures().iterator();
132 assertTrue( "check there is a failure", failures.hasNext() );
136 * Test the conditional when the checksum files of the artifact & metadata do not exist.
138 public void testChecksumFilesDoNotExist()
139 throws DigesterException, IOException
141 createChecksumFile( "VALID" );
142 createMetadataFile( "VALID" );
143 deleteChecksumFiles( "jar" );
145 Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
147 artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
148 assertEquals( 1, reportingDatabase.getNumFailures() );
150 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
151 metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
153 Iterator failures = reportingDatabase.getMetadataIterator();
154 assertTrue( "check there is a failure", failures.hasNext() );
155 MetadataResults results = (MetadataResults) failures.next();
156 failures = results.getFailures().iterator();
157 assertTrue( "check there is a failure", failures.hasNext() );
159 deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );