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.artifact.Artifact;
20 import org.apache.maven.artifact.factory.ArtifactFactory;
21 import org.apache.maven.model.Dependency;
22 import org.apache.maven.model.Model;
24 import java.util.Iterator;
29 public class DependencyArtifactReportProcessorTest
30 extends AbstractRepositoryReportsTestCase
32 private static final String VALID_GROUP_ID = "groupId";
34 private static final String VALID_ARTIFACT_ID = "artifactId";
36 private static final String VALID_VERSION = "1.0-alpha-1";
38 private ArtifactReporter reporter;
42 private ArtifactReportProcessor processor;
44 private ArtifactFactory artifactFactory;
46 private static final String INVALID = "invalid";
48 protected void setUp()
52 reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE );
54 processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "dependency" );
56 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
59 public void testArtifactFoundButNoDirectDependencies()
60 throws ReportProcessorException
62 Artifact artifact = createValidArtifact();
63 processor.processArtifact( model, artifact, reporter, repository );
64 assertEquals( 1, reporter.getNumSuccesses() );
65 assertEquals( 0, reporter.getNumFailures() );
66 assertEquals( 0, reporter.getNumWarnings() );
69 private Artifact createValidArtifact()
71 return artifactFactory.createProjectArtifact( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
74 public void testArtifactNotFound()
75 throws ReportProcessorException
77 Artifact artifact = artifactFactory.createProjectArtifact( INVALID, INVALID, INVALID );
78 processor.processArtifact( model, artifact, reporter, repository );
79 assertEquals( 0, reporter.getNumSuccesses() );
80 assertEquals( 1, reporter.getNumFailures() );
81 assertEquals( 0, reporter.getNumWarnings() );
82 Iterator failures = reporter.getArtifactFailureIterator();
83 ArtifactResult result = (ArtifactResult) failures.next();
84 assertEquals( ArtifactReporter.ARTIFACT_NOT_FOUND, result.getReason() );
87 public void testValidArtifactWithNullDependency()
88 throws ReportProcessorException
90 Artifact artifact = createValidArtifact();
92 Dependency dependency = createValidDependency();
93 model.addDependency( dependency );
95 processor.processArtifact( model, artifact, reporter, repository );
96 assertEquals( 2, reporter.getNumSuccesses() );
97 assertEquals( 0, reporter.getNumFailures() );
98 assertEquals( 0, reporter.getNumWarnings() );
101 private Dependency createValidDependency()
103 return createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
106 public void testValidArtifactWithValidSingleDependency()
107 throws ReportProcessorException
109 Artifact artifact = createValidArtifact();
111 Dependency dependency = createValidDependency();
112 model.addDependency( dependency );
114 processor.processArtifact( model, artifact, reporter, repository );
115 assertEquals( 2, reporter.getNumSuccesses() );
116 assertEquals( 0, reporter.getNumFailures() );
117 assertEquals( 0, reporter.getNumWarnings() );
120 public void testValidArtifactWithValidMultipleDependencies()
121 throws ReportProcessorException
123 Dependency dependency = createValidDependency();
124 model.addDependency( dependency );
125 model.addDependency( dependency );
126 model.addDependency( dependency );
127 model.addDependency( dependency );
128 model.addDependency( dependency );
130 Artifact artifact = createValidArtifact();
131 processor.processArtifact( model, artifact, reporter, repository );
132 assertEquals( 6, reporter.getNumSuccesses() );
133 assertEquals( 0, reporter.getNumFailures() );
134 assertEquals( 0, reporter.getNumWarnings() );
137 public void testValidArtifactWithAnInvalidDependency()
138 throws ReportProcessorException
140 Dependency dependency = createValidDependency();
141 model.addDependency( dependency );
142 model.addDependency( dependency );
143 model.addDependency( dependency );
144 model.addDependency( dependency );
145 model.addDependency( createDependency( INVALID, INVALID, INVALID ) );
147 Artifact artifact = createValidArtifact();
148 processor.processArtifact( model, artifact, reporter, repository );
149 assertEquals( 5, reporter.getNumSuccesses() );
150 assertEquals( 1, reporter.getNumFailures() );
151 assertEquals( 0, reporter.getNumWarnings() );
153 Iterator failures = reporter.getArtifactFailureIterator();
154 ArtifactResult result = (ArtifactResult) failures.next();
155 assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
158 public void testValidArtifactWithInvalidDependencyGroupId()
159 throws ReportProcessorException
161 Artifact artifact = createValidArtifact();
163 Dependency dependency = createDependency( INVALID, VALID_ARTIFACT_ID, VALID_VERSION );
164 model.addDependency( dependency );
166 processor.processArtifact( model, artifact, reporter, repository );
167 assertEquals( 1, reporter.getNumSuccesses() );
168 assertEquals( 1, reporter.getNumFailures() );
169 assertEquals( 0, reporter.getNumWarnings() );
171 Iterator failures = reporter.getArtifactFailureIterator();
172 ArtifactResult result = (ArtifactResult) failures.next();
173 assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
176 private Dependency createDependency( String o, String valid, String s )
178 Dependency dependency = new Dependency();
179 dependency.setGroupId( o );
180 dependency.setArtifactId( valid );
181 dependency.setVersion( s );
185 public void testValidArtifactWithInvalidDependencyArtifactId()
186 throws ReportProcessorException
188 Artifact artifact = createValidArtifact();
190 Dependency dependency = createDependency( VALID_GROUP_ID, INVALID, VALID_VERSION );
191 model.addDependency( dependency );
193 processor.processArtifact( model, artifact, reporter, repository );
194 assertEquals( 1, reporter.getNumSuccesses() );
195 assertEquals( 1, reporter.getNumFailures() );
196 assertEquals( 0, reporter.getNumWarnings() );
198 Iterator failures = reporter.getArtifactFailureIterator();
199 ArtifactResult result = (ArtifactResult) failures.next();
200 assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
203 public void testValidArtifactWithIncorrectDependencyVersion()
204 throws ReportProcessorException
206 Artifact artifact = createValidArtifact();
208 Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, INVALID );
209 model.addDependency( dependency );
211 processor.processArtifact( model, artifact, reporter, repository );
212 assertEquals( 1, reporter.getNumSuccesses() );
213 assertEquals( 1, reporter.getNumFailures() );
214 assertEquals( 0, reporter.getNumWarnings() );
216 Iterator failures = reporter.getArtifactFailureIterator();
217 ArtifactResult result = (ArtifactResult) failures.next();
218 assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
221 public void testValidArtifactWithInvalidDependencyVersion()
222 throws ReportProcessorException
224 Artifact artifact = createValidArtifact();
226 Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[" );
227 model.addDependency( dependency );
229 processor.processArtifact( model, artifact, reporter, repository );
230 assertEquals( 1, reporter.getNumSuccesses() );
231 assertEquals( 1, reporter.getNumFailures() );
232 assertEquals( 0, reporter.getNumWarnings() );
234 Iterator failures = reporter.getArtifactFailureIterator();
235 ArtifactResult result = (ArtifactResult) failures.next();
236 assertEquals( ArtifactReporter.DEPENDENCY_INVALID_VERSION, result.getReason() );