View Javadoc
1   package org.apache.maven.model.validation;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.InputStream;
23  import java.util.List;
24  
25  import org.apache.maven.model.Model;
26  import org.apache.maven.model.building.DefaultModelBuildingRequest;
27  import org.apache.maven.model.building.ModelBuildingRequest;
28  import org.apache.maven.model.building.SimpleProblemCollector;
29  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
30  
31  import junit.framework.TestCase;
32  
33  /**
34   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
35   */
36  public class DefaultModelValidatorTest
37      extends TestCase
38  {
39  
40      private ModelValidator validator;
41  
42      private Model read( String pom )
43          throws Exception
44      {
45          String resource = "/poms/validation/" + pom;
46          InputStream is = getClass().getResourceAsStream( resource );
47          assertNotNull( "missing resource: " + resource, is );
48          return new MavenXpp3Reader().read( is );
49      }
50  
51      private SimpleProblemCollector validate( String pom )
52          throws Exception
53      {
54          return validateEffective( pom, ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
55      }
56  
57      private SimpleProblemCollector validateRaw( String pom )
58          throws Exception
59      {
60          return validateRaw( pom, ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
61      }
62  
63      private SimpleProblemCollector validateEffective( String pom, int level )
64          throws Exception
65      {
66          ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel( level );
67  
68          SimpleProblemCollector problems = new SimpleProblemCollector( read( pom ) );
69  
70          validator.validateEffectiveModel( problems.getModel(), request, problems );
71  
72          return problems;
73      }
74  
75      private SimpleProblemCollector validateRaw( String pom, int level )
76          throws Exception
77      {
78          ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel( level );
79  
80          SimpleProblemCollector problems = new SimpleProblemCollector( read( pom ) );
81  
82          validator.validateRawModel( problems.getModel(), request, problems );
83  
84          return problems;
85      }
86  
87      private void assertContains( String msg, String substring )
88      {
89          assertTrue( "\"" + substring + "\" was not found in: " + msg, msg.contains( substring ) );
90      }
91  
92      @Override
93      protected void setUp()
94          throws Exception
95      {
96          super.setUp();
97  
98          validator = new DefaultModelValidator();
99      }
100 
101     @Override
102     protected void tearDown()
103         throws Exception
104     {
105         this.validator = null;
106 
107         super.tearDown();
108     }
109 
110     private void assertViolations( SimpleProblemCollector result, int fatals, int errors, int warnings )
111     {
112         assertEquals( String.valueOf( result.getFatals() ), fatals, result.getFatals().size() );
113         assertEquals( String.valueOf( result.getErrors() ), errors, result.getErrors().size() );
114         assertEquals( String.valueOf( result.getWarnings() ), warnings, result.getWarnings().size() );
115     }
116 
117     public void testMissingModelVersion()
118         throws Exception
119     {
120         SimpleProblemCollector result = validate( "missing-modelVersion-pom.xml" );
121 
122         assertViolations( result, 0, 1, 0 );
123 
124         assertEquals( "'modelVersion' is missing.", result.getErrors().get( 0 ) );
125     }
126 
127     public void testBadModelVersion()
128         throws Exception
129     {
130         SimpleProblemCollector result =
131             validateRaw( "bad-modelVersion.xml", ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
132 
133         assertViolations( result, 1, 0, 0 );
134 
135         assertTrue( result.getFatals().get( 0 ).contains( "modelVersion" ) );
136     }
137 
138     public void testMissingArtifactId()
139         throws Exception
140     {
141         SimpleProblemCollector result = validate( "missing-artifactId-pom.xml" );
142 
143         assertViolations( result, 0, 1, 0 );
144 
145         assertEquals( "'artifactId' is missing.", result.getErrors().get( 0 ) );
146     }
147 
148     public void testMissingGroupId()
149         throws Exception
150     {
151         SimpleProblemCollector result = validate( "missing-groupId-pom.xml" );
152 
153         assertViolations( result, 0, 1, 0 );
154 
155         assertEquals( "'groupId' is missing.", result.getErrors().get( 0 ) );
156     }
157 
158     public void testInvalidIds()
159         throws Exception
160     {
161         SimpleProblemCollector result = validate( "invalid-ids-pom.xml" );
162 
163         assertViolations( result, 0, 2, 0 );
164 
165         assertEquals( "'groupId' with value 'o/a/m' does not match a valid id pattern.", result.getErrors().get( 0 ) );
166 
167         assertEquals( "'artifactId' with value 'm$-do$' does not match a valid id pattern.",
168                       result.getErrors().get( 1 ) );
169     }
170 
171     public void testMissingType()
172         throws Exception
173     {
174         SimpleProblemCollector result = validate( "missing-type-pom.xml" );
175 
176         assertViolations( result, 0, 1, 0 );
177 
178         assertEquals( "'packaging' is missing.", result.getErrors().get( 0 ) );
179     }
180 
181     public void testMissingVersion()
182         throws Exception
183     {
184         SimpleProblemCollector result = validate( "missing-version-pom.xml" );
185 
186         assertViolations( result, 0, 1, 0 );
187 
188         assertEquals( "'version' is missing.", result.getErrors().get( 0 ) );
189     }
190 
191     public void testInvalidAggregatorPackaging()
192         throws Exception
193     {
194         SimpleProblemCollector result = validate( "invalid-aggregator-packaging-pom.xml" );
195 
196         assertViolations( result, 0, 1, 0 );
197 
198         assertTrue( result.getErrors().get( 0 ).contains( "Aggregator projects require 'pom' as packaging." ) );
199     }
200 
201     public void testMissingDependencyArtifactId()
202         throws Exception
203     {
204         SimpleProblemCollector result = validate( "missing-dependency-artifactId-pom.xml" );
205 
206         assertViolations( result, 0, 1, 0 );
207 
208         assertTrue( result.getErrors().get( 0 ).contains( "'dependencies.dependency.artifactId' for groupId:null:jar is missing" ) );
209     }
210 
211     public void testMissingDependencyGroupId()
212         throws Exception
213     {
214         SimpleProblemCollector result = validate( "missing-dependency-groupId-pom.xml" );
215 
216         assertViolations( result, 0, 1, 0 );
217 
218         assertTrue( result.getErrors().get( 0 ).contains( "'dependencies.dependency.groupId' for null:artifactId:jar is missing" ) );
219     }
220 
221     public void testMissingDependencyVersion()
222         throws Exception
223     {
224         SimpleProblemCollector result = validate( "missing-dependency-version-pom.xml" );
225 
226         assertViolations( result, 0, 1, 0 );
227 
228         assertTrue( result.getErrors().get( 0 ).contains( "'dependencies.dependency.version' for groupId:artifactId:jar is missing" ) );
229     }
230 
231     public void testMissingDependencyManagementArtifactId()
232         throws Exception
233     {
234         SimpleProblemCollector result = validate( "missing-dependency-mgmt-artifactId-pom.xml" );
235 
236         assertViolations( result, 0, 1, 0 );
237 
238         assertTrue( result.getErrors().get( 0 ).contains( "'dependencyManagement.dependencies.dependency.artifactId' for groupId:null:jar is missing" ) );
239     }
240 
241     public void testMissingDependencyManagementGroupId()
242         throws Exception
243     {
244         SimpleProblemCollector result = validate( "missing-dependency-mgmt-groupId-pom.xml" );
245 
246         assertViolations( result, 0, 1, 0 );
247 
248         assertTrue( result.getErrors().get( 0 ).contains( "'dependencyManagement.dependencies.dependency.groupId' for null:artifactId:jar is missing" ) );
249     }
250 
251     public void testMissingAll()
252         throws Exception
253     {
254         SimpleProblemCollector result = validate( "missing-1-pom.xml" );
255 
256         assertViolations( result, 0, 4, 0 );
257 
258         List<String> messages = result.getErrors();
259 
260         assertTrue( messages.contains( "\'modelVersion\' is missing." ) );
261         assertTrue( messages.contains( "\'groupId\' is missing." ) );
262         assertTrue( messages.contains( "\'artifactId\' is missing." ) );
263         assertTrue( messages.contains( "\'version\' is missing." ) );
264         // type is inherited from the super pom
265     }
266 
267     public void testMissingPluginArtifactId()
268         throws Exception
269     {
270         SimpleProblemCollector result = validate( "missing-plugin-artifactId-pom.xml" );
271 
272         assertViolations( result, 0, 1, 0 );
273 
274         assertEquals( "'build.plugins.plugin.artifactId' is missing.", result.getErrors().get( 0 ) );
275     }
276 
277     public void testEmptyPluginVersion()
278         throws Exception
279     {
280         SimpleProblemCollector result = validate( "empty-plugin-version.xml" );
281 
282         assertViolations( result, 0, 1, 0 );
283 
284         assertEquals( "'build.plugins.plugin.version' for org.apache.maven.plugins:maven-it-plugin"
285             + " must be a valid version but is ''.", result.getErrors().get( 0 ) );
286     }
287 
288     public void testMissingRepositoryId()
289         throws Exception
290     {
291         SimpleProblemCollector result =
292             validateRaw( "missing-repository-id-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_STRICT );
293 
294         assertViolations( result, 0, 4, 0 );
295 
296         assertEquals( "'repositories.repository.id' is missing.", result.getErrors().get( 0 ) );
297 
298         assertEquals( "'repositories.repository.[null].url' is missing.", result.getErrors().get( 1 ) );
299 
300         assertEquals( "'pluginRepositories.pluginRepository.id' is missing.", result.getErrors().get( 2 ) );
301 
302         assertEquals( "'pluginRepositories.pluginRepository.[null].url' is missing.", result.getErrors().get( 3 ) );
303     }
304 
305     public void testMissingResourceDirectory()
306         throws Exception
307     {
308         SimpleProblemCollector result = validate( "missing-resource-directory-pom.xml" );
309 
310         assertViolations( result, 0, 2, 0 );
311 
312         assertEquals( "'build.resources.resource.directory' is missing.", result.getErrors().get( 0 ) );
313 
314         assertEquals( "'build.testResources.testResource.directory' is missing.", result.getErrors().get( 1 ) );
315     }
316 
317     public void testBadPluginDependencyScope()
318         throws Exception
319     {
320         SimpleProblemCollector result = validate( "bad-plugin-dependency-scope.xml" );
321 
322         assertViolations( result, 0, 3, 0 );
323 
324         assertTrue( result.getErrors().get( 0 ).contains( "test:d" ) );
325 
326         assertTrue( result.getErrors().get( 1 ).contains( "test:e" ) );
327 
328         assertTrue( result.getErrors().get( 2 ).contains( "test:f" ) );
329     }
330 
331     public void testBadDependencyScope()
332         throws Exception
333     {
334         SimpleProblemCollector result = validate( "bad-dependency-scope.xml" );
335 
336         assertViolations( result, 0, 0, 2 );
337 
338         assertTrue( result.getWarnings().get( 0 ).contains( "test:f" ) );
339 
340         assertTrue( result.getWarnings().get( 1 ).contains( "test:g" ) );
341     }
342 
343     public void testBadDependencyManagementScope()
344         throws Exception
345     {
346         SimpleProblemCollector result = validate( "bad-dependency-management-scope.xml" );
347 
348         assertViolations( result, 0, 0, 1 );
349 
350         assertContains( result.getWarnings().get( 0 ), "test:g" );
351     }
352 
353     public void testBadDependencyVersion()
354         throws Exception
355     {
356         SimpleProblemCollector result = validate( "bad-dependency-version.xml" );
357 
358         assertViolations( result, 0, 2, 0 );
359 
360         assertContains( result.getErrors().get( 0 ),
361                         "'dependencies.dependency.version' for test:b:jar must be a valid version" );
362         assertContains( result.getErrors().get( 1 ),
363                         "'dependencies.dependency.version' for test:c:jar must not contain any of these characters" );
364     }
365 
366     public void testDuplicateModule()
367         throws Exception
368     {
369         SimpleProblemCollector result = validate( "duplicate-module.xml" );
370 
371         assertViolations( result, 0, 1, 0 );
372 
373         assertTrue( result.getErrors().get( 0 ).contains( "child" ) );
374     }
375 
376     public void testDuplicateProfileId()
377         throws Exception
378     {
379         SimpleProblemCollector result = validateRaw( "duplicate-profile-id.xml" );
380 
381         assertViolations( result, 0, 1, 0 );
382 
383         assertTrue( result.getErrors().get( 0 ).contains( "non-unique-id" ) );
384     }
385 
386     public void testBadPluginVersion()
387         throws Exception
388     {
389         SimpleProblemCollector result = validate( "bad-plugin-version.xml" );
390 
391         assertViolations( result, 0, 4, 0 );
392 
393         assertContains( result.getErrors().get( 0 ),
394                         "'build.plugins.plugin.version' for test:mip must be a valid version" );
395         assertContains( result.getErrors().get( 1 ),
396                         "'build.plugins.plugin.version' for test:rmv must be a valid version" );
397         assertContains( result.getErrors().get( 2 ),
398                         "'build.plugins.plugin.version' for test:lmv must be a valid version" );
399         assertContains( result.getErrors().get( 3 ),
400                         "'build.plugins.plugin.version' for test:ifsc must not contain any of these characters" );
401     }
402 
403     public void testDistributionManagementStatus()
404         throws Exception
405     {
406         SimpleProblemCollector result = validate( "distribution-management-status.xml" );
407 
408         assertViolations( result, 0, 1, 0 );
409 
410         assertTrue( result.getErrors().get( 0 ).contains( "distributionManagement.status" ) );
411     }
412 
413     public void testIncompleteParent()
414         throws Exception
415     {
416         SimpleProblemCollector result = validateRaw( "incomplete-parent.xml" );
417 
418         assertViolations( result, 3, 0, 0 );
419 
420         assertTrue( result.getFatals().get( 0 ).contains( "parent.groupId" ) );
421         assertTrue( result.getFatals().get( 1 ).contains( "parent.artifactId" ) );
422         assertTrue( result.getFatals().get( 2 ).contains( "parent.version" ) );
423     }
424 
425     public void testHardCodedSystemPath()
426         throws Exception
427     {
428         SimpleProblemCollector result = validateRaw( "hard-coded-system-path.xml" );
429 
430         assertViolations( result, 0, 0, 1 );
431 
432         assertContains( result.getWarnings().get( 0 ),
433                         "'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
434 
435         SimpleProblemCollector result_31 =
436             validateRaw( "hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
437 
438         assertViolations( result_31, 0, 0, 3 );
439 
440         assertContains( result_31.getWarnings().get( 0 ),
441                         "'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
442         assertContains( result_31.getWarnings().get( 1 ),
443                         "'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
444         assertContains( result_31.getWarnings().get( 2 ),
445                         "'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
446 
447     }
448 
449     public void testEmptyModule()
450         throws Exception
451     {
452         SimpleProblemCollector result = validate( "empty-module.xml" );
453 
454         assertViolations( result, 0, 1, 0 );
455 
456         assertTrue( result.getErrors().get( 0 ).contains( "'modules.module[0]' has been specified without a path" ) );
457     }
458 
459     public void testDuplicatePlugin()
460         throws Exception
461     {
462         SimpleProblemCollector result = validateRaw( "duplicate-plugin.xml" );
463 
464         assertViolations( result, 0, 0, 4 );
465 
466         assertTrue( result.getWarnings().get( 0 ).contains( "duplicate declaration of plugin test:duplicate" ) );
467         assertTrue( result.getWarnings().get( 1 ).contains( "duplicate declaration of plugin test:managed-duplicate" ) );
468         assertTrue( result.getWarnings().get( 2 ).contains( "duplicate declaration of plugin profile:duplicate" ) );
469         assertTrue( result.getWarnings().get( 3 ).contains( "duplicate declaration of plugin profile:managed-duplicate" ) );
470     }
471 
472     public void testDuplicatePluginExecution()
473         throws Exception
474     {
475         SimpleProblemCollector result = validateRaw( "duplicate-plugin-execution.xml" );
476 
477         assertViolations( result, 0, 4, 0 );
478 
479         assertContains( result.getErrors().get( 0 ), "duplicate execution with id a" );
480         assertContains( result.getErrors().get( 1 ), "duplicate execution with id default" );
481         assertContains( result.getErrors().get( 2 ), "duplicate execution with id c" );
482         assertContains( result.getErrors().get( 3 ), "duplicate execution with id b" );
483     }
484 
485     public void testReservedRepositoryId()
486         throws Exception
487     {
488         SimpleProblemCollector result = validate( "reserved-repository-id.xml" );
489 
490         assertViolations( result, 0, 0, 4 );
491 
492         assertContains( result.getWarnings().get( 0 ), "'repositories.repository.id'" + " must not be 'local'" );
493         assertContains( result.getWarnings().get( 1 ), "'pluginRepositories.pluginRepository.id' must not be 'local'" );
494         assertContains( result.getWarnings().get( 2 ), "'distributionManagement.repository.id' must not be 'local'" );
495         assertContains( result.getWarnings().get( 3 ),
496                         "'distributionManagement.snapshotRepository.id' must not be 'local'" );
497     }
498 
499     public void testMissingPluginDependencyGroupId()
500         throws Exception
501     {
502         SimpleProblemCollector result = validate( "missing-plugin-dependency-groupId.xml" );
503 
504         assertViolations( result, 0, 1, 0 );
505 
506         assertTrue( result.getErrors().get( 0 ).contains( ":a:" ) );
507     }
508 
509     public void testMissingPluginDependencyArtifactId()
510         throws Exception
511     {
512         SimpleProblemCollector result = validate( "missing-plugin-dependency-artifactId.xml" );
513 
514         assertViolations( result, 0, 1, 0 );
515 
516         assertTrue( result.getErrors().get( 0 ).contains( "test:" ) );
517     }
518 
519     public void testMissingPluginDependencyVersion()
520         throws Exception
521     {
522         SimpleProblemCollector result = validate( "missing-plugin-dependency-version.xml" );
523 
524         assertViolations( result, 0, 1, 0 );
525 
526         assertTrue( result.getErrors().get( 0 ).contains( "test:a" ) );
527     }
528 
529     public void testBadPluginDependencyVersion()
530         throws Exception
531     {
532         SimpleProblemCollector result = validate( "bad-plugin-dependency-version.xml" );
533 
534         assertViolations( result, 0, 1, 0 );
535 
536         assertTrue( result.getErrors().get( 0 ).contains( "test:b" ) );
537     }
538 
539     public void testBadVersion()
540         throws Exception
541     {
542         SimpleProblemCollector result = validate( "bad-version.xml" );
543 
544         assertViolations( result, 0, 0, 1 );
545 
546         assertContains( result.getWarnings().get( 0 ), "'version' must not contain any of these characters" );
547     }
548 
549     public void testBadSnapshotVersion()
550         throws Exception
551     {
552         SimpleProblemCollector result = validate( "bad-snapshot-version.xml" );
553 
554         assertViolations( result, 0, 0, 1 );
555 
556         assertContains( result.getWarnings().get( 0 ), "'version' uses an unsupported snapshot version format" );
557     }
558 
559     public void testBadRepositoryId()
560         throws Exception
561     {
562         SimpleProblemCollector result = validate( "bad-repository-id.xml" );
563 
564         assertViolations( result, 0, 0, 4 );
565 
566         assertContains( result.getWarnings().get( 0 ),
567                         "'repositories.repository.id' must not contain any of these characters" );
568         assertContains( result.getWarnings().get( 1 ),
569                         "'pluginRepositories.pluginRepository.id' must not contain any of these characters" );
570         assertContains( result.getWarnings().get( 2 ),
571                         "'distributionManagement.repository.id' must not contain any of these characters" );
572         assertContains( result.getWarnings().get( 3 ),
573                         "'distributionManagement.snapshotRepository.id' must not contain any of these characters" );
574     }
575 
576     public void testBadDependencyExclusionId()
577         throws Exception
578     {
579         SimpleProblemCollector result =
580             validateEffective( "bad-dependency-exclusion-id.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 );
581 
582         assertViolations( result, 0, 0, 2 );
583 
584         assertContains( result.getWarnings().get( 0 ),
585                         "'dependencies.dependency.exclusions.exclusion.groupId' for gid:aid:jar" );
586         assertContains( result.getWarnings().get( 1 ),
587                         "'dependencies.dependency.exclusions.exclusion.artifactId' for gid:aid:jar" );
588 
589         // MNG-3832: Aether (part of M3+) supports wildcard expressions for exclusions
590 
591         SimpleProblemCollector result_30 = validate( "bad-dependency-exclusion-id.xml" );
592 
593         assertViolations( result_30, 0, 0, 0 );
594 
595     }
596 
597     public void testMissingDependencyExclusionId()
598         throws Exception
599     {
600         SimpleProblemCollector result = validate( "missing-dependency-exclusion-id.xml" );
601 
602         assertViolations( result, 0, 0, 2 );
603 
604         assertContains( result.getWarnings().get( 0 ),
605                         "'dependencies.dependency.exclusions.exclusion.groupId' for gid:aid:jar is missing" );
606         assertContains( result.getWarnings().get( 1 ),
607                         "'dependencies.dependency.exclusions.exclusion.artifactId' for gid:aid:jar is missing" );
608     }
609 
610     public void testBadImportScopeType()
611         throws Exception
612     {
613         SimpleProblemCollector result = validateRaw( "bad-import-scope-type.xml" );
614 
615         assertViolations( result, 0, 0, 1 );
616 
617         assertContains( result.getWarnings().get( 0 ),
618                         "'dependencyManagement.dependencies.dependency.type' for test:a:jar must be 'pom'" );
619     }
620 
621     public void testBadImportScopeClassifier()
622         throws Exception
623     {
624         SimpleProblemCollector result = validateRaw( "bad-import-scope-classifier.xml" );
625 
626         assertViolations( result, 0, 1, 0 );
627 
628         assertContains( result.getErrors().get( 0 ),
629                         "'dependencyManagement.dependencies.dependency.classifier' for test:a:pom:cls must be empty" );
630     }
631 
632     public void testSystemPathRefersToProjectBasedir()
633         throws Exception
634     {
635         SimpleProblemCollector result = validateRaw( "basedir-system-path.xml" );
636 
637         assertViolations( result, 0, 0, 2 );
638 
639         assertContains( result.getWarnings().get( 0 ),
640                         "'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
641         assertContains( result.getWarnings().get( 1 ),
642                         "'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
643 
644         SimpleProblemCollector result_31 =
645             validateRaw( "basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
646 
647         assertViolations( result_31, 0, 0, 4 );
648 
649         assertContains( result_31.getWarnings().get( 0 ),
650                         "'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
651         assertContains( result_31.getWarnings().get( 1 ),
652                         "'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
653         assertContains( result_31.getWarnings().get( 2 ),
654                         "'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
655         assertContains( result_31.getWarnings().get( 3 ),
656                         "'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
657     }
658 
659     public void testInvalidVersionInPluginManagement()
660         throws Exception
661     {
662         SimpleProblemCollector result = validateRaw( "raw-model/missing-plugin-version-pluginManagement.xml" );
663 
664         assertViolations( result, 1, 0, 0 );
665 
666         assertEquals( "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' version of a plugin must be defined. ",
667                       result.getFatals().get( 0 ) );
668 
669     }
670 
671     public void testInvalidGroupIdInPluginManagement()
672         throws Exception
673     {
674         SimpleProblemCollector result = validateRaw( "raw-model/missing-groupId-pluginManagement.xml" );
675 
676         assertViolations( result, 1, 0, 0 );
677 
678         assertEquals( "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. ",
679                       result.getFatals().get( 0 ) );
680 
681     }
682 
683     public void testInvalidArtifactIdInPluginManagement()
684         throws Exception
685     {
686         SimpleProblemCollector result = validateRaw( "raw-model/missing-artifactId-pluginManagement.xml" );
687 
688         assertViolations( result, 1, 0, 0 );
689 
690         assertEquals( "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. ",
691                       result.getFatals().get( 0 ) );
692 
693     }
694 
695     public void testInvalidGroupAndArtifactIdInPluginManagement()
696         throws Exception
697     {
698         SimpleProblemCollector result = validateRaw( "raw-model/missing-ga-pluginManagement.xml" );
699 
700         assertViolations( result, 2, 0, 0 );
701 
702         assertEquals( "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' groupId of a plugin must be defined. ",
703                       result.getFatals().get( 0 ) );
704 
705         assertEquals( "'build.pluginManagement.plugins.plugin.(groupId:artifactId)' artifactId of a plugin must be defined. ",
706                       result.getFatals().get( 1 ) );
707 
708     }
709 
710     public void testMissingReportPluginVersion()
711         throws Exception
712     {
713         SimpleProblemCollector result = validate( "missing-report-version-pom.xml" );
714 
715         assertViolations( result, 0, 0, 0 );
716     }
717 
718     public void testDeprecatedDependencyMetaversionsLatestAndRelease()
719         throws Exception
720     {
721         SimpleProblemCollector result = validateRaw( "deprecated-dependency-metaversions-latest-and-release.xml" );
722 
723         assertViolations( result, 0, 0, 2 );
724 
725         assertContains( result.getWarnings().get( 0 ),
726                         "'dependencies.dependency.version' for test:a:jar is either LATEST or RELEASE (both of them are being deprecated)" );
727         assertContains( result.getWarnings().get( 1 ),
728                         "'dependencies.dependency.version' for test:b:jar is either LATEST or RELEASE (both of them are being deprecated)" );
729     }
730 
731     public void testSelfReferencingDependencyInRawModel()
732         throws Exception
733     {
734         SimpleProblemCollector result = validateRaw( "raw-model/self-referencing.xml" );
735 
736         assertViolations( result, 1, 0, 0 );
737 
738         assertEquals( "'dependencies.dependency[com.example.group:testinvalidpom:0.0.1-SNAPSHOT]' for com.example.group:testinvalidpom:0.0.1-SNAPSHOT is referencing itself.",
739                       result.getFatals().get( 0 ) );
740 
741     }
742 
743     public void testSelfReferencingDependencyWithClassifierInRawModel() throws Exception
744     {
745         SimpleProblemCollector result = validateRaw( "raw-model/self-referencing-classifier.xml" );
746 
747         assertViolations( result, 0, 0, 0 );
748     }
749 
750     public void testCiFriendlySha1()
751         throws Exception
752     {
753         SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-sha1.xml" );
754         assertViolations( result, 0, 0, 0 );
755     }
756 
757     public void testCiFriendlyRevision()
758         throws Exception
759     {
760         SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-revision.xml" );
761         assertViolations( result, 0, 0, 0 );
762     }
763 
764     public void testCiFriendlyChangeList()
765         throws Exception
766     {
767         SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-changelist.xml" );
768         assertViolations( result, 0, 0, 0 );
769     }
770 
771     public void testCiFriendlyAllExpressions()
772         throws Exception
773     {
774         SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-all-expressions.xml" );
775         assertViolations( result, 0, 0, 0 );
776     }
777 
778     public void testCiFriendlyBad()
779         throws Exception
780     {
781         SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly.xml" );
782         assertViolations( result, 0, 0, 1 );
783         assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
784     }
785 
786     public void testCiFriendlyBadSha1Plus()
787         throws Exception
788     {
789         SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly-sha1plus.xml" );
790         assertViolations( result, 0, 0, 1 );
791         assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
792     }
793 
794     public void testCiFriendlyBadSha1Plus2()
795         throws Exception
796     {
797         SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly-sha1plus2.xml" );
798         assertViolations( result, 0, 0, 1 );
799         assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
800     }
801 
802     public void testParentVersionLATEST()
803         throws Exception
804     {
805         SimpleProblemCollector result = validateRaw( "raw-model/bad-parent-version-latest.xml" );
806         assertViolations( result, 0, 0, 1 );
807         assertEquals( "'parent.version' is either LATEST or RELEASE (both of them are being deprecated)", result.getWarnings().get( 0 ) );
808     }
809 
810     public void testParentVersionRELEASE()
811         throws Exception
812     {
813         SimpleProblemCollector result = validateRaw( "raw-model/bad-parent-version-release.xml" );
814         assertViolations( result, 0, 0, 1 );
815         assertEquals( "'parent.version' is either LATEST or RELEASE (both of them are being deprecated)", result.getWarnings().get( 0 ) );
816     }
817 }