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