KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > project > inheritance > DefaultModelInheritanceAssemblerTest


1 package org.apache.maven.project.inheritance;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import junit.framework.TestCase;
20 import org.apache.maven.model.Build;
21 import org.apache.maven.model.DeploymentRepository;
22 import org.apache.maven.model.DistributionManagement;
23 import org.apache.maven.model.Model;
24 import org.apache.maven.model.Parent;
25 import org.apache.maven.model.Plugin;
26 import org.apache.maven.model.PluginExecution;
27 import org.apache.maven.model.Relocation;
28 import org.apache.maven.model.ReportPlugin;
29 import org.apache.maven.model.ReportSet;
30 import org.apache.maven.model.Reporting;
31 import org.apache.maven.model.Repository;
32 import org.apache.maven.model.RepositoryBase;
33 import org.apache.maven.model.Resource;
34 import org.apache.maven.model.Scm;
35 import org.apache.maven.model.Site;
36
37 import java.util.ArrayList JavaDoc;
38 import java.util.Collections JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.List JavaDoc;
41 import java.util.Map JavaDoc;
42
43 /**
44  * @author jdcasey
45  */

46 public class DefaultModelInheritanceAssemblerTest
47     extends TestCase
48 {
49     private ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
50
51     public void testShouldAppendChildPathAdjustmentWithNoChildPartAndNoParentPart()
52     {
53         String JavaDoc parentPath = "";
54         String JavaDoc childPath = null;
55         String JavaDoc pathAdjustment = "../file-management";
56
57         String JavaDoc result =
58             ( (DefaultModelInheritanceAssembler) assembler ).appendPath( parentPath, childPath, pathAdjustment, true );
59
60         System.out.println( "Resulting path is: \'" + result + "\'" );
61
62         assertEquals( "Append with path adjustment failed.", "/file-management", result );
63     }
64
65     public void testShouldAppendChildPathAdjustmentWithNoChildPart()
66     {
67         String JavaDoc parentPath = "http://maven.apache.org/shared/maven-shared-parent";
68         String JavaDoc childPath = null;
69         String JavaDoc pathAdjustment = "../file-management";
70
71         String JavaDoc result =
72             ( (DefaultModelInheritanceAssembler) assembler ).appendPath( parentPath, childPath, pathAdjustment, true );
73
74         System.out.println( "Resulting path is: \'" + result + "\'" );
75
76         assertEquals( "Append with path adjustment failed.", "http://maven.apache.org/shared/file-management", result );
77     }
78
79     public void testShouldAppendPathWithChildPathAdjustment()
80     {
81         String JavaDoc parentPath = "http://maven.apache.org/shared/maven-shared-parent";
82         String JavaDoc childPath = "file-management";
83         String JavaDoc pathAdjustment = "..";
84
85         String JavaDoc result =
86             ( (DefaultModelInheritanceAssembler) assembler ).appendPath( parentPath, childPath, pathAdjustment, true );
87
88         System.out.println( "Resulting path is: \'" + result + "\'" );
89
90         assertEquals( "Append with path adjustment failed.", "http://maven.apache.org/shared/file-management", result );
91     }
92
93     public void testDistributionManagementInheritance()
94     {
95         Model parent = makeBaseModel( "parent" );
96         Model child = makeBaseModel( "child" );
97
98         DistributionManagement distributionManagement = new DistributionManagement();
99         distributionManagement.setDownloadUrl( "downloadUrl" );
100         distributionManagement.setRelocation( new Relocation() );
101         distributionManagement.setStatus( "deployed" );
102
103         DeploymentRepository repository = new DeploymentRepository();
104         repository.setId( "apache.releases" );
105         repository.setUrl( "scp://minotaur.apache.org/www/www.apache.org/dist/java-repository" );
106         repository.setName( "name" );
107         repository.setLayout( "legacy" );
108         distributionManagement.setRepository( repository );
109
110         DeploymentRepository snapshotRepository = new DeploymentRepository();
111         snapshotRepository.setId( "apache.snapshots" );
112         snapshotRepository.setUrl( "scp://minotaur.apache.org/www/cvs.apache.org/repository" );
113         snapshotRepository.setName( "name" );
114         snapshotRepository.setLayout( "legacy" );
115         snapshotRepository.setUniqueVersion( false );
116         distributionManagement.setSnapshotRepository( snapshotRepository );
117
118         Site site = new Site();
119         site.setId( "apache.website" );
120         site.setUrl( "scp://minotaur.apache.org/www/maven.apache.org/" );
121         site.setName( "name3" );
122         distributionManagement.setSite( site );
123
124         parent.setDistributionManagement( distributionManagement );
125
126         assembler.assembleModelInheritance( child, parent );
127
128         DistributionManagement childDistMgmt = child.getDistributionManagement();
129         assertNotNull( "Check distMgmt inherited", childDistMgmt );
130         assertNull( "Check status NOT inherited", childDistMgmt.getStatus() );
131         assertNull( "Check relocation NOT inherited", childDistMgmt.getRelocation() );
132         assertEquals( "Check downloadUrl inherited", distributionManagement.getDownloadUrl(),
133                       childDistMgmt.getDownloadUrl() );
134
135         Site childSite = childDistMgmt.getSite();
136         assertNotNull( "Check site inherited", childSite );
137         assertEquals( "Check id matches", site.getId(), childSite.getId() );
138         assertEquals( "Check name matches", site.getName(), childSite.getName() );
139         assertEquals( "Check url matches with appended path", site.getUrl() + "child", childSite.getUrl() );
140
141         assertRepositoryBase( childDistMgmt.getRepository(), repository );
142         assertRepositoryBase( childDistMgmt.getSnapshotRepository(), snapshotRepository );
143         assertEquals( "Check uniqueVersion is inherited", snapshotRepository.isUniqueVersion(),
144                       childDistMgmt.getSnapshotRepository().isUniqueVersion() );
145     }
146
147     private static void assertRepositoryBase( RepositoryBase childRepository, RepositoryBase repository )
148     {
149         assertNotNull( "Check repository inherited", childRepository );
150         assertEquals( "Check id matches", repository.getId(), childRepository.getId() );
151         assertEquals( "Check name matches", repository.getName(), childRepository.getName() );
152         assertEquals( "Check url matches", repository.getUrl(), childRepository.getUrl() );
153         assertEquals( "Check layout matches", repository.getLayout(), childRepository.getLayout() );
154     }
155
156     public void testShouldOverrideUnitTestExcludesOnly()
157     {
158         Model parent = new Model();
159
160         parent.setGroupId( "test" );
161         parent.setArtifactId( "test" );
162         parent.setVersion( "0.0" );
163
164         Build parentBuild = new Build();
165
166         parentBuild.setSourceDirectory( "src/main/java" );
167         parentBuild.setTestSourceDirectory( "src/test/java" );
168
169         Resource parentResource = new Resource();
170
171         parentResource.setDirectory( "src/main/resources" );
172
173         parentBuild.addResource( parentResource );
174
175         Resource parentUTResource = new Resource();
176
177         parentUTResource.setDirectory( "src/test/resources" );
178
179         parentBuild.addTestResource( parentUTResource );
180
181         parent.setBuild( parentBuild );
182
183         Model child = new Model();
184
185         Parent parentElement = new Parent();
186         parentElement.setArtifactId( parent.getArtifactId() );
187         parentElement.setGroupId( parent.getGroupId() );
188         parentElement.setVersion( parent.getVersion() );
189         child.setParent( parentElement );
190
191         child.setPackaging( "plugin" );
192
193         Build childBuild = new Build();
194         child.setBuild( childBuild );
195
196         assembler.assembleModelInheritance( child, parent );
197
198         assertEquals( "source directory should be from parent", "src/main/java",
199                       child.getBuild().getSourceDirectory() );
200         assertEquals( "unit test source directory should be from parent", "src/test/java",
201                       child.getBuild().getTestSourceDirectory() );
202
203 // TODO: test inheritence/super pom?
204
// List childExcludesTest = child.getBuild().getUnitTest().getExcludes();
205
//
206
// assertTrue( "unit test excludes should have **/*AspectTest.java", childExcludesTest
207
// .contains( "**/*AspectTest.java" ) );
208
// assertTrue( "unit test excludes should have **/*Abstract*.java", childExcludesTest
209
// .contains( "**/*Abstract*.java" ) );
210
//
211

212         List JavaDoc resources = child.getBuild().getResources();
213
214         assertEquals( "build resources inherited from parent should be of size 1", 1, resources.size() );
215         assertEquals( "first resource should have dir == src/main/resources", "src/main/resources",
216                       ( (Resource) resources.get( 0 ) ).getDirectory() );
217
218         List JavaDoc utResources = child.getBuild().getTestResources();
219
220         assertEquals( "UT resources inherited from parent should be of size 1", 1, utResources.size() );
221         assertEquals( "first UT resource should have dir == src/test/resources", "src/test/resources",
222                       ( (Resource) utResources.get( 0 ) ).getDirectory() );
223
224         assertEquals( "plugin", child.getPackaging() );
225         assertEquals( "jar", parent.getPackaging() );
226     }
227
228     /**
229      * <pre>
230      * root
231      * |--artifact1
232      * | |
233      * | |--artifact1-1
234      * |
235      * |--artifact2 (in another directory called a2 so it has it's own scm section)
236      * |
237      * |--artifact2-1
238      * </pre>
239      */

240     public void testScmInheritance()
241         throws Exception JavaDoc
242     {
243         // Make the models
244
Model root = makeScmModel( "root", "scm:foo:/scm-root", "scm:foo:/scm-dev-root", null );
245
246         Model artifact1 = makeScmModel( "artifact1" );
247
248         Model artifact1_1 = makeScmModel( "artifact1-1" );
249
250         Model artifact2 =
251             makeScmModel( "artifact2", "scm:foo:/scm-root/yay-artifact2", "scm:foo:/scm-dev-root/yay-artifact2", null );
252
253         Model artifact2_1 = makeScmModel( "artifact2-1" );
254
255         // Assemble
256
assembler.assembleModelInheritance( artifact1, root );
257
258         assembler.assembleModelInheritance( artifact1_1, artifact1 );
259
260         assembler.assembleModelInheritance( artifact2, root );
261
262         assembler.assembleModelInheritance( artifact2_1, artifact2 );
263
264         // --- -- -
265

266         assertConnection( "scm:foo:/scm-root/artifact1", "scm:foo:/scm-dev-root/artifact1", artifact1 );
267
268         assertConnection( "scm:foo:/scm-root/artifact1/artifact1-1", "scm:foo:/scm-dev-root/artifact1/artifact1-1",
269                           artifact1_1 );
270
271         assertConnection( "scm:foo:/scm-root/yay-artifact2", "scm:foo:/scm-dev-root/yay-artifact2", artifact2 );
272
273         assertConnection( "scm:foo:/scm-root/yay-artifact2/artifact2-1",
274                           "scm:foo:/scm-dev-root/yay-artifact2/artifact2-1", artifact2_1 );
275     }
276
277     public void testScmInheritanceWhereParentHasConnectionAndTheChildDoesnt()
278     {
279         Model parent = makeScmModel( "parent", "scm:foo:bar:/scm-root", null, null );
280
281         Model child = makeScmModel( "child" );
282
283         assembler.assembleModelInheritance( child, parent );
284
285         assertScm( "scm:foo:bar:/scm-root/child", null, null, child.getScm() );
286     }
287
288     public void testScmInheritanceWhereParentHasConnectionAndTheChildDoes()
289     {
290         Model parent = makeScmModel( "parent", "scm:foo:bar:/scm-root", null, null );
291
292         Model child = makeScmModel( "child", "scm:foo:bar:/another-root", null, null );
293
294         assembler.assembleModelInheritance( child, parent );
295
296         assertScm( "scm:foo:bar:/another-root", null, null, child.getScm() );
297     }
298
299     public void testScmInheritanceWhereParentHasDeveloperConnectionAndTheChildDoesnt()
300     {
301         Model parent = makeScmModel( "parent", null, "scm:foo:bar:/scm-dev-root", null );
302
303         Model child = makeScmModel( "child" );
304
305         assembler.assembleModelInheritance( child, parent );
306
307         assertScm( null, "scm:foo:bar:/scm-dev-root/child", null, child.getScm() );
308     }
309
310     public void testScmInheritanceWhereParentHasDeveloperConnectionAndTheChildDoes()
311     {
312         Model parent = makeScmModel( "parent", null, "scm:foo:bar:/scm-dev-root", null );
313
314         Model child = makeScmModel( "child", null, "scm:foo:bar:/another-dev-root", null );
315
316         assembler.assembleModelInheritance( child, parent );
317
318         assertScm( null, "scm:foo:bar:/another-dev-root", null, child.getScm() );
319     }
320
321     public void testScmInheritanceWhereParentHasUrlAndTheChildDoesnt()
322     {
323         Model parent = makeScmModel( "parent", null, null, "http://foo/bar" );
324
325         Model child = makeScmModel( "child" );
326
327         assembler.assembleModelInheritance( child, parent );
328
329         assertScm( null, null, "http://foo/bar/child", child.getScm() );
330     }
331
332     public void testScmInheritanceWhereParentHasUrlAndTheChildDoes()
333     {
334         Model parent = makeScmModel( "parent", null, null, "http://foo/bar/" );
335
336         Model child = makeScmModel( "child", null, null, "http://bar/foo/" );
337
338         assembler.assembleModelInheritance( child, parent );
339
340         assertScm( null, null, "http://bar/foo/", child.getScm() );
341     }
342
343     public void testRepositoryInheritenceWhereParentHasRepositoryAndTheChildDoesnt()
344     {
345         Model parent = makeRepositoryModel( "parent", "central", "http://repo1.maven.org/maven/" );
346
347         List JavaDoc repos = new ArrayList JavaDoc( parent.getRepositories() );
348
349         Model child = makeBaseModel( "child" );
350
351         assembler.assembleModelInheritance( child, parent );
352
353         // TODO: a lot easier if modello generated equals() :)
354
assertRepositories( repos, child.getRepositories() );
355     }
356
357     public void testRepositoryInheritenceWhereParentHasRepositoryAndTheChildHasDifferent()
358     {
359         Model parent = makeRepositoryModel( "parent", "central", "http://repo1.maven.org/maven/" );
360
361         List JavaDoc repos = new ArrayList JavaDoc( parent.getRepositories() );
362
363         Model child = makeRepositoryModel( "child", "workplace", "http://repository.mycompany.com/maven/" );
364
365         repos.addAll( child.getRepositories() );
366
367         assembler.assembleModelInheritance( child, parent );
368
369         // TODO: a lot easier if modello generated equals() :)
370
assertRepositories( repos, child.getRepositories() );
371     }
372
373     public void testRepositoryInheritenceWhereParentHasRepositoryAndTheChildHasSameId()
374     {
375         Model parent = makeRepositoryModel( "parent", "central", "http://repo1.maven.org/maven/" );
376
377         Model child = makeRepositoryModel( "child", "central", "http://repo2.maven.org/maven/" );
378
379         // We want to get the child repository here.
380
List JavaDoc repos = new ArrayList JavaDoc( child.getRepositories() );
381
382         assembler.assembleModelInheritance( child, parent );
383
384         // TODO: a lot easier if modello generated equals() :)
385
assertRepositories( repos, child.getRepositories() );
386     }
387
388     public void testPluginInheritanceWhereParentPluginWithoutInheritFlagAndChildHasNoPlugins()
389     {
390         Model parent = makeBaseModel( "parent" );
391
392         Model child = makeBaseModel( "child" );
393
394         Plugin parentPlugin = new Plugin();
395         parentPlugin.setArtifactId( "maven-testInheritance-plugin" );
396         parentPlugin.setGroupId( "org.apache.maven.plugins" );
397         parentPlugin.setVersion( "1.0" );
398
399         List JavaDoc parentPlugins = Collections.singletonList( parentPlugin );
400
401         Build parentBuild = new Build();
402         parentBuild.setPlugins( parentPlugins );
403
404         parent.setBuild( parentBuild );
405
406         assembler.assembleModelInheritance( child, parent );
407
408         assertPlugins( parentPlugins, child );
409     }
410
411     public void testPluginInheritanceWhereParentPluginWithTrueInheritFlagAndChildHasNoPlugins()
412     {
413         Model parent = makeBaseModel( "parent" );
414
415         Model child = makeBaseModel( "child" );
416
417         Plugin parentPlugin = new Plugin();
418         parentPlugin.setArtifactId( "maven-testInheritance2-plugin" );
419         parentPlugin.setGroupId( "org.apache.maven.plugins" );
420         parentPlugin.setVersion( "1.0" );
421         parentPlugin.setInherited( "true" );
422
423         List JavaDoc parentPlugins = Collections.singletonList( parentPlugin );
424
425         Build parentBuild = new Build();
426         parentBuild.setPlugins( parentPlugins );
427
428         parent.setBuild( parentBuild );
429
430         assembler.assembleModelInheritance( child, parent );
431
432         assertPlugins( parentPlugins, child );
433     }
434
435     public void testPluginInheritanceWhereParentPluginWithFalseInheritFlagAndChildHasNoPlugins()
436     {
437         Model parent = makeBaseModel( "parent" );
438
439         Model child = makeBaseModel( "child" );
440
441         Plugin parentPlugin = new Plugin();
442         parentPlugin.setArtifactId( "maven-testInheritance3-plugin" );
443         parentPlugin.setGroupId( "org.apache.maven.plugins" );
444         parentPlugin.setVersion( "1.0" );
445         parentPlugin.setInherited( "false" );
446
447         List JavaDoc parentPlugins = Collections.singletonList( parentPlugin );
448
449         Build parentBuild = new Build();
450         parentBuild.setPlugins( parentPlugins );
451
452         parent.setBuild( parentBuild );
453
454         assembler.assembleModelInheritance( child, parent );
455
456         assertPlugins( new ArrayList JavaDoc(), child );
457     }
458
459     private void assertPlugins( List JavaDoc expectedPlugins, Model child )
460     {
461         Build childBuild = child.getBuild();
462
463         if ( expectedPlugins != null && !expectedPlugins.isEmpty() )
464         {
465             assertNotNull( childBuild );
466
467             Map JavaDoc childPluginsMap = childBuild.getPluginsAsMap();
468
469             if ( childPluginsMap != null )
470             {
471                 assertEquals( expectedPlugins.size(), childPluginsMap.size() );
472
473                 for ( Iterator JavaDoc it = expectedPlugins.iterator(); it.hasNext(); )
474                 {
475                     Plugin expectedPlugin = (Plugin) it.next();
476
477                     Plugin childPlugin = (Plugin) childPluginsMap.get( expectedPlugin.getKey() );
478
479                     assertPluginsEqual( expectedPlugin, childPlugin );
480                 }
481             }
482             else
483             {
484                 fail( "child plugins collection is null, but expectations map is not." );
485             }
486         }
487         else
488         {
489             assertTrue( childBuild == null || childBuild.getPlugins() == null || childBuild.getPlugins().isEmpty() );
490         }
491     }
492
493     private void assertPluginsEqual( Plugin reference, Plugin test )
494     {
495         assertEquals( "Plugin keys don't match", reference.getKey(), test.getKey() );
496         assertEquals( "Plugin configurations don't match", reference.getConfiguration(), test.getConfiguration() );
497
498         List JavaDoc referenceExecutions = reference.getExecutions();
499         Map JavaDoc testExecutionsMap = test.getExecutionsAsMap();
500
501         if ( referenceExecutions != null && !referenceExecutions.isEmpty() )
502         {
503             assertTrue( "Missing goals specification", ( testExecutionsMap != null && !testExecutionsMap.isEmpty() ) );
504
505             for ( Iterator JavaDoc it = referenceExecutions.iterator(); it.hasNext(); )
506             {
507                 PluginExecution referenceExecution = (PluginExecution) it.next();
508                 PluginExecution testExecution = (PluginExecution) testExecutionsMap.get( referenceExecution.getId() );
509
510                 assertNotNull( "Goal from reference not found in test", testExecution );
511
512                 assertEquals( "Goal IDs don't match", referenceExecution.getId(), testExecution.getId() );
513                 assertEquals( "Goal configurations don't match", referenceExecution.getConfiguration(),
514                               testExecution.getConfiguration() );
515                 assertEquals( "Goal lists don't match", referenceExecution.getGoals(), testExecution.getGoals() );
516             }
517         }
518         else
519         {
520             assertTrue( "Unexpected goals specification",
521                         ( testExecutionsMap == null || testExecutionsMap.isEmpty() ) );
522         }
523     }
524
525     public void testReportingExcludeDefaultsInheritance()
526     {
527         Model parent = makeBaseModel( "parent" );
528
529         Model child = makeBaseModel( "child" );
530
531         Reporting parentBuild = new Reporting();
532         parentBuild.setExcludeDefaults( false );
533         parent.setReporting( parentBuild );
534
535         assembler.assembleModelInheritance( child, parent );
536
537         assertFalse( "Check excludeDefaults is inherited", child.getReporting().isExcludeDefaults() );
538
539         child = makeBaseModel( "child" );
540
541         parentBuild.setExcludeDefaults( true );
542
543         assembler.assembleModelInheritance( child, parent );
544
545         assertTrue( "Check excludeDefaults is inherited", child.getReporting().isExcludeDefaults() );
546     }
547
548     public void testReportInheritanceWhereParentReportWithoutInheritFlagAndChildHasNoReports()
549     {
550         Model parent = makeBaseModel( "parent" );
551
552         Model child = makeBaseModel( "child" );
553
554         ReportPlugin parentReport = new ReportPlugin();
555         parentReport.setArtifactId( "maven-testInheritance-report-plugin" );
556         parentReport.setGroupId( "org.apache.maven.plugins" );
557         parentReport.setVersion( "1.0" );
558
559         List JavaDoc parentPlugins = Collections.singletonList( parentReport );
560
561         Reporting parentBuild = new Reporting();
562         parentBuild.setPlugins( parentPlugins );
563
564         parent.setReporting( parentBuild );
565
566         assembler.assembleModelInheritance( child, parent );
567
568         assertReports( parentPlugins, child );
569     }
570
571     public void testReportInheritanceWhereParentReportWithTrueInheritFlagAndChildHasNoReports()
572     {
573         Model parent = makeBaseModel( "parent" );
574
575         Model child = makeBaseModel( "child" );
576
577         ReportPlugin parentPlugin = new ReportPlugin();
578         parentPlugin.setArtifactId( "maven-testInheritance2-report-plugin" );
579         parentPlugin.setGroupId( "org.apache.maven.plugins" );
580         parentPlugin.setVersion( "1.0" );
581         parentPlugin.setInherited( "true" );
582
583         List JavaDoc parentPlugins = Collections.singletonList( parentPlugin );
584
585         Reporting parentBuild = new Reporting();
586         parentBuild.setPlugins( parentPlugins );
587
588         parent.setReporting( parentBuild );
589
590         assembler.assembleModelInheritance( child, parent );
591
592         assertReports( parentPlugins, child );
593     }
594
595     public void testReportInheritanceWhereParentReportWithFalseInheritFlagAndChildHasNoReports()
596     {
597         Model parent = makeBaseModel( "parent" );
598
599         Model child = makeBaseModel( "child" );
600
601         ReportPlugin parentPlugin = new ReportPlugin();
602         parentPlugin.setArtifactId( "maven-testInheritance3-report-plugin" );
603         parentPlugin.setGroupId( "org.apache.maven.plugins" );
604         parentPlugin.setVersion( "1.0" );
605         parentPlugin.setInherited( "false" );
606
607         List JavaDoc parentPlugins = Collections.singletonList( parentPlugin );
608
609         Reporting parentBuild = new Reporting();
610         parentBuild.setPlugins( parentPlugins );
611
612         parent.setReporting( parentBuild );
613
614         assembler.assembleModelInheritance( child, parent );
615
616         assertReports( new ArrayList JavaDoc(), child );
617     }
618
619     private void assertReports( List JavaDoc expectedPlugins, Model child )
620     {
621         Reporting childBuild = child.getReporting();
622
623         if ( expectedPlugins != null && !expectedPlugins.isEmpty() )
624         {
625             assertNotNull( childBuild );
626
627             Map JavaDoc childPluginsMap = childBuild.getReportPluginsAsMap();
628
629             if ( childPluginsMap != null )
630             {
631                 assertEquals( expectedPlugins.size(), childPluginsMap.size() );
632
633                 for ( Iterator JavaDoc it = expectedPlugins.iterator(); it.hasNext(); )
634                 {
635                     ReportPlugin expectedPlugin = (ReportPlugin) it.next();
636
637                     ReportPlugin childPlugin = (ReportPlugin) childPluginsMap.get( expectedPlugin.getKey() );
638
639                     assertReportsEqual( expectedPlugin, childPlugin );
640                 }
641             }
642             else
643             {
644                 fail( "child plugins collection is null, but expectations map is not." );
645             }
646         }
647         else
648         {
649             assertTrue( childBuild == null || childBuild.getPlugins() == null || childBuild.getPlugins().isEmpty() );
650         }
651     }
652
653     private void assertReportsEqual( ReportPlugin reference, ReportPlugin test )
654     {
655         assertEquals( "Plugin keys don't match", reference.getKey(), test.getKey() );
656         assertEquals( "Plugin configurations don't match", reference.getConfiguration(), test.getConfiguration() );
657
658         List JavaDoc referenceReportSets = reference.getReportSets();
659         Map JavaDoc testReportSetsMap = test.getReportSetsAsMap();
660
661         if ( referenceReportSets != null && !referenceReportSets.isEmpty() )
662         {
663             assertTrue( "Missing goals specification", ( testReportSetsMap != null && !testReportSetsMap.isEmpty() ) );
664
665             for ( Iterator JavaDoc it = referenceReportSets.iterator(); it.hasNext(); )
666             {
667                 ReportSet referenceReportSet = (ReportSet) it.next();
668                 ReportSet testReportSet = (ReportSet) testReportSetsMap.get( referenceReportSet.getId() );
669
670                 assertNotNull( "Goal from reference not found in test", testReportSet );
671
672                 assertEquals( "Goal IDs don't match", referenceReportSet.getId(), testReportSet.getId() );
673                 assertEquals( "Goal configurations don't match", referenceReportSet.getConfiguration(),
674                               testReportSet.getConfiguration() );
675                 assertEquals( "Reports don't match", referenceReportSet.getReports(), testReportSet.getReports() );
676             }
677         }
678         else
679         {
680             assertTrue( "Unexpected goals specification",
681                         ( testReportSetsMap == null || testReportSetsMap.isEmpty() ) );
682         }
683     }
684
685     // ----------------------------------------------------------------------
686
//
687
// ----------------------------------------------------------------------
688

689     private void assertConnection( String JavaDoc expectedConnection, String JavaDoc expectedDeveloperConnection, Model model )
690     {
691         String JavaDoc connection = model.getScm().getConnection();
692
693         assertNotNull( connection );
694
695         assertEquals( expectedConnection, connection );
696
697         String JavaDoc developerConnection = model.getScm().getDeveloperConnection();
698
699         assertNotNull( developerConnection );
700
701         assertEquals( expectedDeveloperConnection, developerConnection );
702     }
703
704     public void assertScm( String JavaDoc connection, String JavaDoc developerConnection, String JavaDoc url, Scm scm )
705     {
706         assertNotNull( scm );
707
708         assertEquals( connection, scm.getConnection() );
709
710         assertEquals( developerConnection, scm.getDeveloperConnection() );
711
712         assertEquals( url, scm.getUrl() );
713     }
714
715     private static Model makeScmModel( String JavaDoc artifactId )
716     {
717         return makeScmModel( artifactId, null, null, null );
718     }
719
720     private static Model makeScmModel( String JavaDoc artifactId, String JavaDoc connection, String JavaDoc developerConnection, String JavaDoc url )
721     {
722         Model model = makeBaseModel( artifactId );
723
724         if ( connection != null || developerConnection != null || url != null )
725         {
726             Scm scm = new Scm();
727
728             scm.setConnection( connection );
729
730             scm.setDeveloperConnection( developerConnection );
731
732             scm.setUrl( url );
733
734             model.setScm( scm );
735         }
736
737         return model;
738     }
739
740     private static Model makeBaseModel( String JavaDoc artifactId )
741     {
742         Model model = new Model();
743
744         model.setModelVersion( "4.0.0" );
745
746         model.setGroupId( "maven" );
747
748         model.setArtifactId( artifactId );
749
750         model.setVersion( "1.0" );
751         return model;
752     }
753
754     private static Model makeRepositoryModel( String JavaDoc artifactId, String JavaDoc id, String JavaDoc url )
755     {
756         Model model = makeBaseModel( artifactId );
757
758         Repository repository = makeRepository( id, url );
759
760         model.setRepositories( new ArrayList JavaDoc( Collections.singletonList( repository ) ) );
761
762         return model;
763     }
764
765     private static Repository makeRepository( String JavaDoc id, String JavaDoc url )
766     {
767         Repository repository = new Repository();
768         repository.setId( id );
769         repository.setUrl( url );
770         return repository;
771     }
772
773     private void assertRepositories( List JavaDoc expected, List JavaDoc actual )
774     {
775         assertEquals( "Repository list sizes don't match", expected.size(), actual.size() );
776
777         for ( Iterator JavaDoc i = expected.iterator(); i.hasNext(); )
778         {
779             Repository expectedRepository = (Repository) i.next();
780             boolean found = false;
781             for ( Iterator JavaDoc j = actual.iterator(); j.hasNext() && !found; )
782             {
783                 Repository actualRepository = (Repository) j.next();
784
785                 if ( actualRepository.getId().equals( expectedRepository.getId() ) )
786                 {
787                     assertEquals( "Repository URLs don't match", expectedRepository.getUrl(),
788                                   actualRepository.getUrl() );
789                     found = true;
790                 }
791             }
792             assertTrue( "Repository with ID " + expectedRepository.getId() + " not found", found );
793         }
794     }
795
796 }
797
Popular Tags