]> source.dussan.org Git - archiva.git/blob
90278fdf2552109cd167c220908415a29d6401ac
[archiva.git] /
1 package org.apache.maven.archiva.reporting.database;
2
3 /*
4  * Copyright 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 junit.framework.TestCase;
20
21 import org.apache.maven.archiva.reporting.model.ArtifactResults;
22 import org.apache.maven.archiva.reporting.model.MetadataResults;
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.artifact.DefaultArtifact;
25 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
26 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
27 import org.apache.maven.artifact.versioning.VersionRange;
28
29 /**
30  * Test for {@link ReportingDatabase}.
31  * 
32  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
33  * @version $Id$
34  */
35 public class ReportingDatabaseTest
36     extends TestCase
37 {
38     private Artifact artifact;
39     private String processor, problem, reason;
40     private ReportingDatabase reportingDatabase;
41     private RepositoryMetadata metadata;
42
43     protected void setUp()
44         throws Exception
45     {
46         super.setUp();
47         artifact = new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1.0" ), "scope", "type",
48                                         "classifier", null );
49         processor = "processor";
50         problem = "problem";
51         reason = "reason";
52         reportingDatabase = new ReportingDatabase( null );
53
54         metadata = new ArtifactRepositoryMetadata( artifact );
55     }
56
57     public void testAddNoticeArtifactStringStringString()
58     {
59         reportingDatabase.addNotice( artifact, processor, problem, reason );
60         ArtifactResults artifactResults = reportingDatabase.getArtifactResults( artifact );
61
62         assertEquals( 1, reportingDatabase.getNumNotices() );
63         assertEquals( 1, artifactResults.getNotices().size() );
64
65         reportingDatabase.addNotice( artifact, processor, problem, reason );
66         artifactResults = reportingDatabase.getArtifactResults( artifact );
67
68         assertEquals( 1, reportingDatabase.getNumNotices() );
69         assertEquals( 1, artifactResults.getNotices().size() );
70     }
71
72     public void testAddWarningArtifactStringStringString()
73     {
74         reportingDatabase.addWarning( artifact, processor, problem, reason );
75         ArtifactResults artifactResults = reportingDatabase.getArtifactResults( artifact );
76
77         assertEquals( 1, reportingDatabase.getNumWarnings() );
78         assertEquals( 1, artifactResults.getWarnings().size() );
79
80         reportingDatabase.addWarning( artifact, processor, problem, reason );
81         artifactResults = reportingDatabase.getArtifactResults( artifact );
82
83         assertEquals( 1, reportingDatabase.getNumWarnings() );
84         assertEquals( 1, artifactResults.getWarnings().size() );
85     }
86
87     public void testAddFailureArtifactStringStringString()
88     {
89         reportingDatabase.addFailure( artifact, processor, problem, reason );
90         ArtifactResults artifactResults = reportingDatabase.getArtifactResults( artifact );
91
92         assertEquals( 1, reportingDatabase.getNumFailures() );
93         assertEquals( 1, artifactResults.getFailures().size() );
94
95         reportingDatabase.addFailure( artifact, processor, problem, reason );
96         artifactResults = reportingDatabase.getArtifactResults( artifact );
97
98         assertEquals( 1, reportingDatabase.getNumFailures() );
99         assertEquals( 1, artifactResults.getFailures().size() );
100     }
101
102     public void testAddNoticeRepositoryMetadataStringStringString()
103     {
104         reportingDatabase.addNotice( metadata, processor, problem, reason );
105         MetadataResults metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
106
107         assertEquals( 1, reportingDatabase.getNumNotices() );
108         assertEquals( 1, metadataResults.getNotices().size() );
109
110         reportingDatabase.addNotice( metadata, processor, problem, reason );
111         metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
112
113         assertEquals( 1, reportingDatabase.getNumNotices() );
114         assertEquals( 1, metadataResults.getNotices().size() );
115     }
116
117     public void testAddWarningRepositoryMetadataStringStringString()
118     {
119         reportingDatabase.addWarning( metadata, processor, problem, reason );
120         MetadataResults metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
121
122         assertEquals( 1, reportingDatabase.getNumWarnings() );
123         assertEquals( 1, metadataResults.getWarnings().size() );
124
125         reportingDatabase.addWarning( metadata, processor, problem, reason );
126         metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
127
128         assertEquals( 1, reportingDatabase.getNumWarnings() );
129         assertEquals( 1, metadataResults.getWarnings().size() );
130     }
131
132     public void testAddFailureRepositoryMetadataStringStringString()
133     {
134         reportingDatabase.addFailure( metadata, processor, problem, reason );
135         MetadataResults metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
136
137         assertEquals( 1, reportingDatabase.getNumFailures() );
138         assertEquals( 1, metadataResults.getFailures().size() );
139
140         reportingDatabase.addFailure( metadata, processor, problem, reason );
141         metadataResults = reportingDatabase.getMetadataResults( metadata, System.currentTimeMillis() );
142
143         assertEquals( 1, reportingDatabase.getNumFailures() );
144         assertEquals( 1, metadataResults.getFailures().size() );
145     }
146 }