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