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