]> source.dussan.org Git - archiva.git/blob
5a9ac742245d3f4101afc486f0f08578cf0e8681
[archiva.git] /
1 package org.apache.maven.archiva.reporting.reporter;
2
3 /*
4  * Copyright 2005-2006 The Apache Software Foundation.
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
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;
31
32 import java.io.File;
33 import java.io.IOException;
34 import java.util.Iterator;
35
36 /**
37  * This class tests the ChecksumArtifactReportProcessor.
38  * It extends the AbstractChecksumArtifactReporterTestCase class.
39  */
40 public class ChecksumArtifactReporterTest
41     extends AbstractChecksumArtifactReporterTestCase
42 {
43     private ArtifactReportProcessor artifactReportProcessor;
44
45     private ReportingDatabase reportingDatabase;
46
47     private MetadataReportProcessor metadataReportProcessor;
48
49     public void setUp()
50         throws Exception
51     {
52         super.setUp();
53         artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "checksum" );
54         metadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE, "checksum-metadata" );
55
56         ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
57         reportingDatabase = new ReportingDatabase( reportGroup );
58     }
59
60     /**
61      * Test the ChecksumArtifactReportProcessor when the checksum files are valid.
62      */
63     public void testChecksumArtifactReporterSuccess()
64         throws DigesterException, IOException
65     {
66         createChecksumFile( "VALID" );
67         createChecksumFile( "INVALID" );
68
69         Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
70
71         artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
72         assertEquals( 0, reportingDatabase.getNumFailures() );
73         assertEquals( 0, reportingDatabase.getNumWarnings() );
74         assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
75     }
76
77     /**
78      * Test the ChecksumArtifactReportProcessor when the checksum files are invalid.
79      */
80     public void testChecksumArtifactReporterFailed()
81     {
82         String s = "invalidArtifact";
83         String s1 = "1.0";
84         Artifact artifact = createArtifact( "checksumTest", s, s1 );
85
86         artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
87         assertEquals( 1, reportingDatabase.getNumFailures() );
88         assertEquals( 0, reportingDatabase.getNumWarnings() );
89         assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
90     }
91
92     /**
93      * Test the valid checksum of a metadata file.
94      * The reportingDatabase should report 2 success validation.
95      */
96     public void testChecksumMetadataReporterSuccess()
97         throws DigesterException, IOException
98     {
99         createMetadataFile( "VALID" );
100         createMetadataFile( "INVALID" );
101
102         Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
103
104         //Version level metadata
105         RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
106         metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
107
108         //Artifact level metadata
109         metadata = new ArtifactRepositoryMetadata( artifact );
110         metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
111
112         //Group level metadata
113         metadata = new GroupRepositoryMetadata( "checksumTest" );
114         metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
115     }
116
117     /**
118      * Test the corrupted checksum of a metadata file.
119      * The reportingDatabase must report 2 failures.
120      */
121     public void testChecksumMetadataReporterFailure()
122     {
123         Artifact artifact = createArtifact( "checksumTest", "invalidArtifact", "1.0" );
124
125         RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
126         metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
127
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() );
133     }
134
135     /**
136      * Test the conditional when the checksum files of the artifact & metadata do not exist.
137      */
138     public void testChecksumFilesDoNotExist()
139         throws DigesterException, IOException
140     {
141         createChecksumFile( "VALID" );
142         createMetadataFile( "VALID" );
143         deleteChecksumFiles( "jar" );
144
145         Artifact artifact = createArtifact( "checksumTest", "validArtifact", "1.0" );
146
147         artifactReportProcessor.processArtifact( artifact, null, reportingDatabase );
148         assertEquals( 1, reportingDatabase.getNumFailures() );
149
150         RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
151         metadataReportProcessor.processMetadata( metadata, repository, reportingDatabase );
152
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() );
158
159         deleteTestDirectory( new File( repository.getBasedir() + "checksumTest" ) );
160     }
161 }