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.project;
20  
21  import javax.inject.Inject;
22  
23  import java.io.File;
24  import java.util.ArrayList;
25  import java.util.Arrays;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.Properties;
29  
30  import org.apache.maven.MavenTestHelper;
31  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
32  import org.apache.maven.bridge.MavenRepositorySystem;
33  import org.apache.maven.model.Model;
34  import org.apache.maven.model.Plugin;
35  import org.apache.maven.model.PluginExecution;
36  import org.apache.maven.model.Profile;
37  import org.apache.maven.model.ReportPlugin;
38  import org.apache.maven.model.ReportSet;
39  import org.apache.maven.model.building.ModelBuildingRequest;
40  import org.apache.maven.project.harness.PomTestWrapper;
41  import org.codehaus.plexus.testing.PlexusTest;
42  import org.eclipse.aether.DefaultRepositorySystemSession;
43  import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
44  import org.eclipse.aether.repository.LocalRepository;
45  import org.junit.jupiter.api.BeforeEach;
46  import org.junit.jupiter.api.Test;
47  
48  import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
49  import static org.hamcrest.MatcherAssert.assertThat;
50  import static org.hamcrest.Matchers.endsWith;
51  import static org.hamcrest.Matchers.lessThan;
52  import static org.hamcrest.Matchers.startsWith;
53  import static org.junit.jupiter.api.Assertions.assertEquals;
54  import static org.junit.jupiter.api.Assertions.assertFalse;
55  import static org.junit.jupiter.api.Assertions.assertNotEquals;
56  import static org.junit.jupiter.api.Assertions.assertNotNull;
57  import static org.junit.jupiter.api.Assertions.assertNull;
58  import static org.junit.jupiter.api.Assertions.assertSame;
59  import static org.junit.jupiter.api.Assertions.assertThrows;
60  import static org.junit.jupiter.api.Assertions.assertTrue;
61  
62  @PlexusTest
63  class PomConstructionTest {
64      private static String BASE_DIR = "src/test";
65  
66      private static String BASE_POM_DIR = BASE_DIR + "/resources-project-builder";
67  
68      private static String BASE_MIXIN_DIR = BASE_DIR + "/resources-mixins";
69  
70      @Inject
71      private DefaultProjectBuilder projectBuilder;
72  
73      @Inject
74      private MavenRepositorySystem repositorySystem;
75  
76      private File testDirectory;
77  
78      @BeforeEach
79      void setUp() throws Exception {
80          testDirectory = new File(getBasedir(), BASE_POM_DIR);
81          new File(getBasedir(), BASE_MIXIN_DIR);
82          EmptyLifecycleBindingsInjector.useEmpty();
83      }
84  
85      /**
86       * Will throw exception if url is empty. MNG-4050
87       *
88       * @throws Exception in case of issue
89       */
90      @Test
91      void testEmptyUrl() throws Exception {
92          buildPom("empty-distMng-repo-url");
93      }
94  
95      /**
96       * Tests that modules is not overridden by profile
97       *
98       * @throws Exception in case of issue
99       */
100     /* MNG-786*/
101     @Test
102     void testProfileModules() throws Exception {
103         PomTestWrapper pom = buildPom("profile-module", "a");
104         assertEquals("test-prop", pom.getValue("properties[1]/b")); // verifies profile applied
105         assertEquals(4, ((List<?>) pom.getValue("modules")).size());
106         assertEquals("module-2", pom.getValue("modules[1]"));
107         assertEquals("module-1", pom.getValue("modules[2]"));
108         assertEquals("module-3", pom.getValue("modules[3]"));
109         assertEquals("module-4", pom.getValue("modules[4]"));
110     }
111 
112     /**
113      * Will throw an exception if it doesn't find parent(s) in build
114      *
115      * @throws Exception in case of issue
116      */
117     @Test
118     void testParentInheritance() throws Exception {
119         buildPom("parent-inheritance/sub");
120     }
121 
122     /*MNG-3995*/
123     @Test
124     void testExecutionConfigurationJoin() throws Exception {
125         PomTestWrapper pom = buildPom("execution-configuration-join");
126         assertEquals(2, ((List<?>) pom.getValue("build/plugins[1]/executions[1]/configuration[1]/fileset[1]")).size());
127     }
128 
129     /*MNG-3803*/
130     @Test
131     void testPluginConfigProperties() throws Exception {
132         PomTestWrapper pom = buildPom("plugin-config-properties");
133         assertEquals(
134                 "my.property", pom.getValue("build/plugins[1]/configuration[1]/systemProperties[1]/property[1]/name"));
135     }
136 
137     /*MNG-3900*/
138     @Test
139     void testProfilePropertiesInterpolation() throws Exception {
140         PomTestWrapper pom = buildPom("profile-properties-interpolation", "interpolation-profile");
141         assertEquals("PASSED", pom.getValue("properties[1]/test"));
142         assertEquals("PASSED", pom.getValue("properties[1]/property"));
143     }
144 
145     /*MNG-7750*/
146     private void checkBuildPluginWithArtifactId(
147             List<Plugin> plugins, String artifactId, String expectedId, String expectedConfig) {
148         Plugin plugin = plugins.stream()
149                 .filter(p -> p.getArtifactId().equals(artifactId))
150                 .findFirst()
151                 .orElse(null);
152         assertNotNull(plugin, "Unable to find plugin with artifactId: " + artifactId);
153         List<PluginExecution> pluginExecutions = plugin.getExecutions();
154         PluginExecution pluginExecution = pluginExecutions.stream()
155                 .filter(pe -> pe.getId().equals(expectedId))
156                 .findFirst()
157                 .orElse(null);
158         assertNotNull(pluginExecution, "Wrong id for \"" + artifactId + "\"");
159 
160         String config = pluginExecution.getConfiguration().toString();
161         assertTrue(
162                 config.contains(expectedConfig),
163                 "Wrong config for \"" + artifactId + "\": (" + config + ") does not contain :" + expectedConfig);
164     }
165 
166     private boolean isActiveProfile(MavenProject project, Profile activeProfile) {
167         return project.getActiveProfiles().stream().anyMatch(p -> p.getId().equals(activeProfile.getId()));
168     }
169 
170     @Test
171     void testBuildPluginInterpolation() throws Exception {
172         PomTestWrapper pom = buildPom("plugin-interpolation-build", "activeProfile");
173         Model originalModel = pom.getMavenProject().getOriginalModel();
174 
175         // =============================================
176         assertEquals("||${project.basedir}||", originalModel.getProperties().get("prop-outside"));
177 
178         List<Plugin> outsidePlugins = originalModel.getBuild().getPlugins();
179         assertEquals(1, outsidePlugins.size());
180 
181         checkBuildPluginWithArtifactId(
182                 outsidePlugins,
183                 "plugin-all-profiles",
184                 "Outside ||${project.basedir}||",
185                 "<plugin-all-profiles-out>Outside ||${project.basedir}||</plugin-all-profiles-out>");
186 
187         // =============================================
188         Profile activeProfile = originalModel.getProfiles().stream()
189                 .filter(profile -> profile.getId().equals("activeProfile"))
190                 .findFirst()
191                 .orElse(null);
192         assertNotNull(activeProfile, "Unable to find the activeProfile");
193 
194         assertTrue(
195                 isActiveProfile(pom.getMavenProject(), activeProfile),
196                 "The activeProfile should be active in the maven project");
197 
198         assertEquals("||${project.basedir}||", activeProfile.getProperties().get("prop-active"));
199 
200         List<Plugin> activeProfilePlugins = activeProfile.getBuild().getPlugins();
201         assertEquals(2, activeProfilePlugins.size(), "Number of active profile plugins");
202 
203         checkBuildPluginWithArtifactId(
204                 activeProfilePlugins,
205                 "plugin-all-profiles",
206                 "Active all ||${project.basedir}||",
207                 "<plugin-all-profiles-in>Active all ||${project.basedir}||</plugin-all-profiles-in>");
208 
209         checkBuildPluginWithArtifactId(
210                 activeProfilePlugins,
211                 "only-active-profile",
212                 "Active only ||${project.basedir}||",
213                 "<plugin-in-active-profile-only>Active only ||${project.basedir}||</plugin-in-active-profile-only>");
214 
215         // =============================================
216 
217         Profile inactiveProfile = originalModel.getProfiles().stream()
218                 .filter(profile -> profile.getId().equals("inactiveProfile"))
219                 .findFirst()
220                 .orElse(null);
221         assertNotNull(inactiveProfile, "Unable to find the inactiveProfile");
222 
223         assertFalse(
224                 isActiveProfile(pom.getMavenProject(), inactiveProfile),
225                 "The inactiveProfile should NOT be active in the maven project");
226 
227         assertEquals("||${project.basedir}||", inactiveProfile.getProperties().get("prop-inactive"));
228 
229         List<Plugin> inactiveProfilePlugins = inactiveProfile.getBuild().getPlugins();
230         assertEquals(2, inactiveProfilePlugins.size(), "Number of active profile plugins");
231 
232         checkBuildPluginWithArtifactId(
233                 inactiveProfilePlugins,
234                 "plugin-all-profiles",
235                 "Inactive all ||${project.basedir}||",
236                 "<plugin-all-profiles-ina>Inactive all ||${project.basedir}||</plugin-all-profiles-ina>");
237 
238         checkBuildPluginWithArtifactId(
239                 inactiveProfilePlugins,
240                 "only-inactive-profile",
241                 "Inactive only ||${project.basedir}||",
242                 "<plugin-in-inactive-only>Inactive only ||${project.basedir}||</plugin-in-inactive-only>");
243     }
244 
245     private void checkReportPluginWithArtifactId(
246             List<ReportPlugin> plugins, String artifactId, String expectedId, String expectedConfig) {
247         ReportPlugin plugin = plugins.stream()
248                 .filter(p -> p.getArtifactId().equals(artifactId))
249                 .findFirst()
250                 .orElse(null);
251         assertNotNull(plugin, "Unable to find plugin with artifactId: " + artifactId);
252         List<ReportSet> pluginReportSets = plugin.getReportSets();
253         ReportSet reportSet = pluginReportSets.stream()
254                 .filter(rs -> rs.getId().equals(expectedId))
255                 .findFirst()
256                 .orElse(null);
257         assertNotNull(reportSet, "Wrong id for \"" + artifactId + "\"");
258 
259         String config = reportSet.getConfiguration().toString();
260         assertTrue(
261                 config.contains(expectedConfig),
262                 "Wrong config for \"" + artifactId + "\": (" + config + ") does not contain :" + expectedConfig);
263     }
264 
265     @Test
266     void testReportingPluginInterpolation() throws Exception {
267         PomTestWrapper pom = buildPom("plugin-interpolation-reporting", "activeProfile");
268         Model originalModel = pom.getMavenProject().getOriginalModel();
269 
270         // =============================================
271         assertEquals("||${project.basedir}||", originalModel.getProperties().get("prop-outside"));
272 
273         List<ReportPlugin> outsidePlugins = originalModel.getReporting().getPlugins();
274         assertEquals(1, outsidePlugins.size(), "Wrong number of plugins found");
275 
276         checkReportPluginWithArtifactId(
277                 outsidePlugins,
278                 "plugin-all-profiles",
279                 "Outside ||${project.basedir}||",
280                 "<plugin-all-profiles-out>Outside ||${project.basedir}||</plugin-all-profiles-out>");
281 
282         // =============================================
283         Profile activeProfile = originalModel.getProfiles().stream()
284                 .filter(profile -> profile.getId().equals("activeProfile"))
285                 .findFirst()
286                 .orElse(null);
287         assertNotNull(activeProfile, "Unable to find the activeProfile");
288 
289         assertTrue(
290                 isActiveProfile(pom.getMavenProject(), activeProfile),
291                 "The activeProfile should be active in the maven project");
292 
293         assertEquals("||${project.basedir}||", activeProfile.getProperties().get("prop-active"));
294 
295         List<ReportPlugin> activeProfilePlugins = activeProfile.getReporting().getPlugins();
296         assertEquals(2, activeProfilePlugins.size(), "The activeProfile should be active in the maven project");
297 
298         checkReportPluginWithArtifactId(
299                 activeProfilePlugins,
300                 "plugin-all-profiles",
301                 "Active all ||${project.basedir}||",
302                 "<plugin-all-profiles-in>Active all ||${project.basedir}||</plugin-all-profiles-in>");
303 
304         checkReportPluginWithArtifactId(
305                 activeProfilePlugins,
306                 "only-active-profile",
307                 "Active only ||${project.basedir}||",
308                 "<plugin-in-active-profile-only>Active only ||${project.basedir}||</plugin-in-active-profile-only>");
309 
310         // =============================================
311 
312         Profile inactiveProfile = originalModel.getProfiles().stream()
313                 .filter(profile -> profile.getId().equals("inactiveProfile"))
314                 .findFirst()
315                 .orElse(null);
316         assertNotNull(inactiveProfile, "Unable to find the inactiveProfile");
317 
318         assertFalse(
319                 isActiveProfile(pom.getMavenProject(), inactiveProfile),
320                 "The inactiveProfile should NOT be active in the maven project");
321 
322         assertEquals("||${project.basedir}||", inactiveProfile.getProperties().get("prop-inactive"));
323 
324         List<ReportPlugin> inactiveProfilePlugins =
325                 inactiveProfile.getReporting().getPlugins();
326         assertEquals(2, inactiveProfilePlugins.size(), "Number of active profile plugins");
327 
328         checkReportPluginWithArtifactId(
329                 inactiveProfilePlugins,
330                 "plugin-all-profiles",
331                 "Inactive all ||${project.basedir}||",
332                 "<plugin-all-profiles-ina>Inactive all ||${project.basedir}||</plugin-all-profiles-ina>");
333 
334         checkReportPluginWithArtifactId(
335                 inactiveProfilePlugins,
336                 "only-inactive-profile",
337                 "Inactive only ||${project.basedir}||",
338                 "<plugin-in-inactive-only>Inactive only ||${project.basedir}||</plugin-in-inactive-only>");
339     }
340 
341     // Some better conventions for the test poms needs to be created and each of these tests
342     // that represent a verification of a specification item needs to be a couple lines at most.
343     // The expressions help a lot, but we need a clean to pick up a directory of POMs, automatically load
344     // them into a resolver, create the expression to extract the data to validate the Model, and the URI
345     // to validate the properties. We also need a way to navigate from the Tex specification documents to
346     // the test in question and vice versa. A little Eclipse plugin would do the trick.
347     public void testThatExecutionsWithoutIdsAreMergedAndTheChildWins() throws Exception {
348         PomTestWrapper tester = buildPom("micromailer");
349         assertModelEquals(tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]");
350     }
351 
352     /*MNG-
353     public void testDependencyScope()
354         throws Exception
355     {
356         PomTestWrapper pom = buildPom( "dependency-scope/sub" );
357 
358     }*/
359 
360     /*MNG- 4010*/
361     @Test
362     void testDuplicateExclusionsDependency() throws Exception {
363         PomTestWrapper pom = buildPom("duplicate-exclusions-dependency/sub");
364         assertEquals(1, ((List<?>) pom.getValue("dependencies[1]/exclusions")).size());
365     }
366 
367     /*MNG- 4008*/
368     @Test
369     void testMultipleFilters() throws Exception {
370         PomTestWrapper pom = buildPom("multiple-filters");
371         assertEquals(4, ((List<?>) pom.getValue("build/filters")).size());
372     }
373 
374     /* MNG-4005: postponed to 3.1
375     public void testValidationErrorUponNonUniqueDependencyKey()
376         throws Exception
377     {
378         try
379         {
380             buildPom( "unique-dependency-key/deps" );
381             fail( "Non-unique dependency keys did not cause validation error" );
382         }
383         catch ( ProjectBuildingException e )
384         {
385             // expected
386         }
387     }
388 
389     @Test
390     public void testValidationErrorUponNonUniqueDependencyManagementKey()
391         throws Exception
392     {
393         try
394         {
395             buildPom( "unique-dependency-key/dep-mgmt" );
396             fail( "Non-unique dependency keys did not cause validation error" );
397         }
398         catch ( ProjectBuildingException e )
399         {
400             // expected
401         }
402     }
403 
404     @Test
405     public void testValidationErrorUponNonUniqueDependencyKeyInProfile()
406         throws Exception
407     {
408         try
409         {
410             buildPom( "unique-dependency-key/deps-in-profile" );
411             fail( "Non-unique dependency keys did not cause validation error" );
412         }
413         catch ( ProjectBuildingException e )
414         {
415             // expected
416         }
417     }
418 
419     @Test
420     public void testValidationErrorUponNonUniqueDependencyManagementKeyInProfile()
421         throws Exception
422     {
423         try
424         {
425             buildPom( "unique-dependency-key/dep-mgmt-in-profile" );
426             fail( "Non-unique dependency keys did not cause validation error" );
427         }
428         catch ( ProjectBuildingException e )
429         {
430             // expected
431         }
432     }
433     */
434 
435     @Test
436     void testDuplicateDependenciesCauseLastDeclarationToBePickedInLenientMode() throws Exception {
437         PomTestWrapper pom = buildPom("unique-dependency-key/deps", true, null, null);
438         assertEquals(1, ((List<?>) pom.getValue("dependencies")).size());
439         assertEquals("0.2", pom.getValue("dependencies[1]/version"));
440     }
441 
442     /* MNG-3567*/
443     @Test
444     void testParentInterpolation() throws Exception {
445         PomTestWrapper pom = buildPom("parent-interpolation/sub");
446         pom = new PomTestWrapper(pom.getMavenProject().getParent());
447         assertEquals("1.3.0-SNAPSHOT", pom.getValue("build/plugins[1]/version"));
448     }
449 
450     /*
451     public void testMaven()
452         throws Exception
453     {
454         PomTestWrapper pom =  buildPomFromMavenProject( "maven-build/sub/pom.xml", null );
455 
456         for( String s: pom.getMavenProject().getTestClasspathElements() )
457         {
458             System.out.println( s );
459         }
460 
461     }
462     */
463 
464     /* MNG-3567*/
465     @Test
466     void testPluginManagementInherited() throws Exception {
467         PomTestWrapper pom = buildPom("pluginmanagement-inherited/sub");
468         assertEquals("1.0-alpha-21", pom.getValue("build/plugins[1]/version"));
469     }
470 
471     /* MNG-2174*/
472     @Test
473     void testPluginManagementDependencies() throws Exception {
474         PomTestWrapper pom = buildPom("plugin-management-dependencies/sub", "test");
475         assertEquals("1.0-alpha-21", pom.getValue("build/plugins[1]/version"));
476         assertEquals("1.0", pom.getValue("build/plugins[1]/dependencies[1]/version"));
477     }
478 
479     /* MNG-3877*/
480     @Test
481     void testReportingInterpolation() throws Exception {
482         PomTestWrapper pom = buildPom("reporting-interpolation");
483         assertEquals(
484                 createPath(Arrays.asList(
485                         System.getProperty("user.dir"),
486                         "src",
487                         "test",
488                         "resources-project-builder",
489                         "reporting-interpolation",
490                         "target",
491                         "site")),
492                 pom.getValue("reporting/outputDirectory"));
493     }
494 
495     @Test
496     void testPluginOrder() throws Exception {
497         PomTestWrapper pom = buildPom("plugin-order");
498         assertEquals("plexus-component-metadata", pom.getValue("build/plugins[1]/artifactId"));
499         assertEquals("maven-surefire-plugin", pom.getValue("build/plugins[2]/artifactId"));
500     }
501 
502     @Test
503     void testErroneousJoiningOfDifferentPluginsWithEqualDependencies() throws Exception {
504         PomTestWrapper pom = buildPom("equal-plugin-deps");
505         assertEquals("maven-it-plugin-a", pom.getValue("build/plugins[1]/artifactId"));
506         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/dependencies")).size());
507         assertEquals("maven-it-plugin-b", pom.getValue("build/plugins[2]/artifactId"));
508         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/dependencies")).size());
509     }
510 
511     /** MNG-3821 */
512     @Test
513     void testErroneousJoiningOfDifferentPluginsWithEqualExecutionIds() throws Exception {
514         PomTestWrapper pom = buildPom("equal-plugin-exec-ids");
515         assertEquals("maven-it-plugin-a", pom.getValue("build/plugins[1]/artifactId"));
516         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
517         assertEquals("maven-it-plugin-b", pom.getValue("build/plugins[2]/artifactId"));
518         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
519         assertEquals("maven-it-plugin-a", pom.getValue("reporting/plugins[1]/artifactId"));
520         assertEquals(1, ((List<?>) pom.getValue("reporting/plugins[1]/reportSets")).size());
521         assertEquals("maven-it-plugin-b", pom.getValue("reporting/plugins[2]/artifactId"));
522         assertEquals(1, ((List<?>) pom.getValue("reporting/plugins[1]/reportSets")).size());
523     }
524 
525     /** MNG-3998 */
526     @Test
527     void testExecutionConfiguration() throws Exception {
528         PomTestWrapper pom = buildPom("execution-configuration");
529         assertEquals(2, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
530         assertEquals("src/main/mdo/nexus.xml", (pom.getValue("build/plugins[1]/executions[1]/configuration[1]/model")));
531         assertEquals(
532                 "src/main/mdo/security.xml", (pom.getValue("build/plugins[1]/executions[2]/configuration[1]/model")));
533     }
534 
535     /*
536         public void testPluginConfigDuplicate()
537         throws Exception
538     {
539         PomTestWrapper pom = buildPom( "plugin-config-duplicate/dup" );
540     }
541     */
542     @Test
543     void testSingleConfigurationInheritance() throws Exception {
544         PomTestWrapper pom = buildPom("single-configuration-inheritance");
545 
546         assertEquals(2, ((List<?>) pom.getValue("build/plugins[1]/executions[1]/configuration[1]/rules")).size());
547         assertEquals(
548                 "2.0.6",
549                 pom.getValue(
550                         "build/plugins[1]/executions[1]/configuration[1]/rules[1]/requireMavenVersion[1]/version"));
551         assertEquals(
552                 "[1.4,)",
553                 pom.getValue("build/plugins[1]/executions[1]/configuration[1]/rules[1]/requireJavaVersion[1]/version"));
554     }
555 
556     @Test
557     void testConfigWithPluginManagement() throws Exception {
558         PomTestWrapper pom = buildPom("config-with-plugin-mng");
559         assertEquals(2, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
560         assertEquals(
561                 "src/main/mdo/security.xml", pom.getValue("build/plugins[1]/executions[2]/configuration[1]/model"));
562         assertEquals("1.0.8", pom.getValue("build/plugins[1]/executions[1]/configuration[1]/version"));
563     }
564 
565     /** MNG-3965 */
566     @Test
567     void testExecutionConfigurationSubcollections() throws Exception {
568         PomTestWrapper pom = buildPom("execution-configuration-subcollections");
569         assertEquals(
570                 2,
571                 ((List<?>) pom.getValue("build/plugins[1]/executions[1]/configuration[1]/rules[1]/bannedDependencies"))
572                         .size());
573     }
574 
575     /** MNG-3985 */
576     @Test
577     void testMultipleRepositories() throws Exception {
578         PomTestWrapper pom = buildPom("multiple-repos/sub");
579         assertEquals(2, ((List<?>) pom.getValue("repositories")).size());
580     }
581 
582     /** MNG-3965 */
583     @Test
584     void testMultipleExecutionIds() throws Exception {
585         PomTestWrapper pom = buildPom("dual-execution-ids/sub");
586         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
587     }
588 
589     /** MNG-3997 */
590     @Test
591     void testConsecutiveEmptyElements() throws Exception {
592         buildPom("consecutive_empty_elements");
593     }
594 
595     @Test
596     void testOrderOfGoalsFromPluginExecutionWithoutPluginManagement() throws Exception {
597         PomTestWrapper pom = buildPom("plugin-exec-goals-order/wo-plugin-mgmt");
598         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/executions[1]/goals")).size());
599         assertEquals("b", pom.getValue("build/plugins[1]/executions[1]/goals[1]"));
600         assertEquals("a", pom.getValue("build/plugins[1]/executions[1]/goals[2]"));
601         assertEquals("d", pom.getValue("build/plugins[1]/executions[1]/goals[3]"));
602         assertEquals("c", pom.getValue("build/plugins[1]/executions[1]/goals[4]"));
603         assertEquals("e", pom.getValue("build/plugins[1]/executions[1]/goals[5]"));
604     }
605 
606     /* MNG-3886*/
607     @Test
608     void testOrderOfGoalsFromPluginExecutionWithPluginManagement() throws Exception {
609         PomTestWrapper pom = buildPom("plugin-exec-goals-order/w-plugin-mgmt");
610         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/executions[1]/goals")).size());
611         assertEquals("b", pom.getValue("build/plugins[1]/executions[1]/goals[1]"));
612         assertEquals("a", pom.getValue("build/plugins[1]/executions[1]/goals[2]"));
613         assertEquals("d", pom.getValue("build/plugins[1]/executions[1]/goals[3]"));
614         assertEquals("c", pom.getValue("build/plugins[1]/executions[1]/goals[4]"));
615         assertEquals("e", pom.getValue("build/plugins[1]/executions[1]/goals[5]"));
616     }
617 
618     @Test
619     void testOrderOfPluginExecutionsWithoutPluginManagement() throws Exception {
620         PomTestWrapper pom = buildPom("plugin-exec-order/wo-plugin-mgmt");
621         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
622         assertEquals("b", pom.getValue("build/plugins[1]/executions[1]/id"));
623         assertEquals("a", pom.getValue("build/plugins[1]/executions[2]/id"));
624         assertEquals("d", pom.getValue("build/plugins[1]/executions[3]/id"));
625         assertEquals("c", pom.getValue("build/plugins[1]/executions[4]/id"));
626         assertEquals("e", pom.getValue("build/plugins[1]/executions[5]/id"));
627     }
628 
629     /* MNG-3887 */
630     @Test
631     void testOrderOfPluginExecutionsWithPluginManagement() throws Exception {
632         PomTestWrapper pom = buildPom("plugin-exec-order/w-plugin-mgmt");
633         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
634         assertEquals("b", pom.getValue("build/plugins[1]/executions[1]/id"));
635         assertEquals("a", pom.getValue("build/plugins[1]/executions[2]/id"));
636         assertEquals("d", pom.getValue("build/plugins[1]/executions[3]/id"));
637         assertEquals("c", pom.getValue("build/plugins[1]/executions[4]/id"));
638         assertEquals("e", pom.getValue("build/plugins[1]/executions[5]/id"));
639     }
640 
641     @Test
642     void testMergeOfPluginExecutionsWhenChildInheritsPluginVersion() throws Exception {
643         PomTestWrapper pom = buildPom("plugin-exec-merging-wo-version/sub");
644         assertEquals(4, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
645     }
646 
647     /* MNG-3943*/
648     @Test
649     void testMergeOfPluginExecutionsWhenChildAndParentUseDifferentPluginVersions() throws Exception {
650         PomTestWrapper pom = buildPom("plugin-exec-merging-version-insensitive/sub");
651         assertEquals(4, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
652     }
653 
654     @Test
655     void testInterpolationWithXmlMarkup() throws Exception {
656         PomTestWrapper pom = buildPom("xml-markup-interpolation");
657         assertEquals("<?xml version='1.0'?>Tom&Jerry", pom.getValue("properties/xmlTest"));
658     }
659 
660     /* MNG-3925 */
661     @Test
662     void testOrderOfMergedPluginExecutionsWithoutPluginManagement() throws Exception {
663         PomTestWrapper pom = buildPom("merged-plugin-exec-order/wo-plugin-mgmt/sub");
664         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
665         assertEquals("parent-1", pom.getValue("build/plugins[1]/executions[1]/goals[1]"));
666         assertEquals("parent-2", pom.getValue("build/plugins[1]/executions[2]/goals[1]"));
667         assertEquals("child-default", pom.getValue("build/plugins[1]/executions[3]/goals[1]"));
668         assertEquals("child-1", pom.getValue("build/plugins[1]/executions[4]/goals[1]"));
669         assertEquals("child-2", pom.getValue("build/plugins[1]/executions[5]/goals[1]"));
670     }
671 
672     @Test
673     void testOrderOfMergedPluginExecutionsWithPluginManagement() throws Exception {
674         PomTestWrapper pom = buildPom("merged-plugin-exec-order/w-plugin-mgmt/sub");
675         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
676         assertEquals("parent-1", pom.getValue("build/plugins[1]/executions[1]/goals[1]"));
677         assertEquals("parent-2", pom.getValue("build/plugins[1]/executions[2]/goals[1]"));
678         assertEquals("child-default", pom.getValue("build/plugins[1]/executions[3]/goals[1]"));
679         assertEquals("child-1", pom.getValue("build/plugins[1]/executions[4]/goals[1]"));
680         assertEquals("child-2", pom.getValue("build/plugins[1]/executions[5]/goals[1]"));
681     }
682 
683     /* MNG-3984*/
684     @Test
685     void testDifferentContainersWithSameId() throws Exception {
686         PomTestWrapper pom = buildPom("join-different-containers-same-id");
687         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/executions[1]/goals")).size());
688         assertEquals(
689                 1,
690                 ((List<?>) pom.getValue(
691                                 "build/pluginManagement/plugins[@artifactId='maven-it-plugin-b']/executions[1]/goals"))
692                         .size());
693     }
694 
695     /* MNG-3937*/
696     @Test
697     void testOrderOfMergedPluginExecutionGoalsWithoutPluginManagement() throws Exception {
698         PomTestWrapper pom = buildPom("merged-plugin-exec-goals-order/wo-plugin-mgmt/sub");
699 
700         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/executions[1]/goals")).size());
701         assertEquals("child-a", pom.getValue("build/plugins[1]/executions[1]/goals[1]"));
702         assertEquals("merged", pom.getValue("build/plugins[1]/executions[1]/goals[2]"));
703         assertEquals("child-b", pom.getValue("build/plugins[1]/executions[1]/goals[3]"));
704         assertEquals("parent-b", pom.getValue("build/plugins[1]/executions[1]/goals[4]"));
705         assertEquals("parent-a", pom.getValue("build/plugins[1]/executions[1]/goals[5]"));
706     }
707 
708     @Test
709     void testOrderOfMergedPluginExecutionGoalsWithPluginManagement() throws Exception {
710         PomTestWrapper pom = buildPom("merged-plugin-exec-goals-order/w-plugin-mgmt/sub");
711         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/executions[1]/goals")).size());
712         assertEquals("child-a", pom.getValue("build/plugins[1]/executions[1]/goals[1]"));
713         assertEquals("merged", pom.getValue("build/plugins[1]/executions[1]/goals[2]"));
714         assertEquals("child-b", pom.getValue("build/plugins[1]/executions[1]/goals[3]"));
715         assertEquals("parent-b", pom.getValue("build/plugins[1]/executions[1]/goals[4]"));
716         assertEquals("parent-a", pom.getValue("build/plugins[1]/executions[1]/goals[5]"));
717     }
718 
719     /*MNG-3938*/
720     @Test
721     void testOverridingOfInheritedPluginExecutionsWithoutPluginManagement() throws Exception {
722         PomTestWrapper pom = buildPom("plugin-exec-merging/wo-plugin-mgmt/sub");
723         assertEquals(2, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
724         assertEquals("child-default", pom.getValue("build/plugins[1]/executions[@id='default']/phase"));
725         assertEquals("child-non-default", pom.getValue("build/plugins[1]/executions[@id='non-default']/phase"));
726     }
727 
728     /* MNG-3938 */
729     @Test
730     void testOverridingOfInheritedPluginExecutionsWithPluginManagement() throws Exception {
731         PomTestWrapper pom = buildPom("plugin-exec-merging/w-plugin-mgmt/sub");
732         assertEquals(2, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
733         assertEquals("child-default", pom.getValue("build/plugins[1]/executions[@id='default']/phase"));
734         assertEquals("child-non-default", pom.getValue("build/plugins[1]/executions[@id='non-default']/phase"));
735     }
736 
737     /* MNG-3906*/
738     @Test
739     void testOrderOfMergedPluginDependenciesWithoutPluginManagement() throws Exception {
740         PomTestWrapper pom = buildPom("merged-plugin-class-path-order/wo-plugin-mgmt/sub");
741 
742         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/dependencies")).size());
743         assertNotNull(pom.getValue("build/plugins[1]/dependencies[1]"));
744         assertEquals("c", pom.getValue("build/plugins[1]/dependencies[1]/artifactId"));
745         assertEquals("1", pom.getValue("build/plugins[1]/dependencies[1]/version"));
746         assertEquals("a", pom.getValue("build/plugins[1]/dependencies[2]/artifactId"));
747         assertEquals("2", pom.getValue("build/plugins[1]/dependencies[2]/version"));
748         assertEquals("b", pom.getValue("build/plugins[1]/dependencies[3]/artifactId"));
749         assertEquals("1", pom.getValue("build/plugins[1]/dependencies[3]/version"));
750         assertEquals("e", pom.getValue("build/plugins[1]/dependencies[4]/artifactId"));
751         assertEquals("1", pom.getValue("build/plugins[1]/dependencies[4]/version"));
752         assertEquals("d", pom.getValue("build/plugins[1]/dependencies[5]/artifactId"));
753         assertEquals("1", pom.getValue("build/plugins[1]/dependencies[5]/version"));
754     }
755 
756     @Test
757     void testOrderOfMergedPluginDependenciesWithPluginManagement() throws Exception {
758         PomTestWrapper pom = buildPom("merged-plugin-class-path-order/w-plugin-mgmt/sub");
759         assertEquals(5, ((List<?>) pom.getValue("build/plugins[1]/dependencies")).size());
760         assertEquals("c", pom.getValue("build/plugins[1]/dependencies[1]/artifactId"));
761         assertEquals("1", pom.getValue("build/plugins[1]/dependencies[1]/version"));
762         assertEquals("a", pom.getValue("build/plugins[1]/dependencies[2]/artifactId"));
763         assertEquals("2", pom.getValue("build/plugins[1]/dependencies[2]/version"));
764         assertEquals("b", pom.getValue("build/plugins[1]/dependencies[3]/artifactId"));
765         assertEquals("1", pom.getValue("build/plugins[1]/dependencies[3]/version"));
766         assertEquals("e", pom.getValue("build/plugins[1]/dependencies[4]/artifactId"));
767         assertEquals("1", pom.getValue("build/plugins[1]/dependencies[4]/version"));
768         assertEquals("d", pom.getValue("build/plugins[1]/dependencies[5]/artifactId"));
769         assertEquals("1", pom.getValue("build/plugins[1]/dependencies[5]/version"));
770     }
771 
772     @Test
773     void testInterpolationOfNestedBuildDirectories() throws Exception {
774         PomTestWrapper pom = buildPom("nested-build-dir-interpolation");
775         assertEquals(
776                 new File(pom.getBasedir(), "target/classes/dir0"), new File((String) pom.getValue("properties/dir0")));
777         assertEquals(new File(pom.getBasedir(), "src/test/dir1"), new File((String) pom.getValue("properties/dir1")));
778         assertEquals(
779                 new File(pom.getBasedir(), "target/site/dir2"), new File((String) pom.getValue("properties/dir2")));
780     }
781 
782     @Test
783     void testAppendArtifactIdOfChildToInheritedUrls() throws Exception {
784         PomTestWrapper pom = buildPom("url-inheritance/sub");
785         assertEquals("https://parent.url/child", pom.getValue("url"));
786         assertEquals("https://parent.url/org", pom.getValue("organization/url"));
787         assertEquals("https://parent.url/license.txt", pom.getValue("licenses[1]/url"));
788         assertEquals("https://parent.url/viewvc/child", pom.getValue("scm/url"));
789         assertEquals("https://parent.url/scm/child", pom.getValue("scm/connection"));
790         assertEquals("https://parent.url/scm/child", pom.getValue("scm/developerConnection"));
791         assertEquals("https://parent.url/issues", pom.getValue("issueManagement/url"));
792         assertEquals("https://parent.url/ci", pom.getValue("ciManagement/url"));
793         assertEquals("https://parent.url/dist", pom.getValue("distributionManagement/repository/url"));
794         assertEquals("https://parent.url/snaps", pom.getValue("distributionManagement/snapshotRepository/url"));
795         assertEquals("https://parent.url/site/child", pom.getValue("distributionManagement/site/url"));
796         assertEquals("https://parent.url/download", pom.getValue("distributionManagement/downloadUrl"));
797     }
798 
799     /* MNG-3846*/
800     @Test
801     void testAppendArtifactIdOfParentAndChildToInheritedUrls() throws Exception {
802         PomTestWrapper pom = buildPom("url-inheritance/another-parent/sub");
803         assertEquals("https://parent.url/ap/child", pom.getValue("url"));
804         assertEquals("https://parent.url/org", pom.getValue("organization/url"));
805         assertEquals("https://parent.url/license.txt", pom.getValue("licenses[1]/url"));
806         assertEquals("https://parent.url/viewvc/ap/child", pom.getValue("scm/url"));
807         assertEquals("https://parent.url/scm/ap/child", pom.getValue("scm/connection"));
808         assertEquals("https://parent.url/scm/ap/child", pom.getValue("scm/developerConnection"));
809         assertEquals("https://parent.url/issues", pom.getValue("issueManagement/url"));
810         assertEquals("https://parent.url/ci", pom.getValue("ciManagement/url"));
811         assertEquals("https://parent.url/dist", pom.getValue("distributionManagement/repository/url"));
812         assertEquals("https://parent.url/snaps", pom.getValue("distributionManagement/snapshotRepository/url"));
813         assertEquals("https://parent.url/site/ap/child", pom.getValue("distributionManagement/site/url"));
814         assertEquals("https://parent.url/download", pom.getValue("distributionManagement/downloadUrl"));
815     }
816 
817     @Test
818     void testNonInheritedElementsInSubtreesOverriddenByChild() throws Exception {
819         PomTestWrapper pom = buildPom("limited-inheritance/child");
820         assertNull(pom.getValue("organization/url"));
821         assertNull(pom.getValue("issueManagement/system"));
822         assertEquals(0, ((List<?>) pom.getValue("ciManagement/notifiers")).size());
823         assertEquals("child-distros", pom.getValue("distributionManagement/repository/id"));
824         assertEquals("ssh://child.url/distros", pom.getValue("distributionManagement/repository/url"));
825         assertNull(pom.getValue("distributionManagement/repository/name"));
826         assertEquals(true, pom.getValue("distributionManagement/repository/uniqueVersion"));
827         assertEquals("default", pom.getValue("distributionManagement/repository/layout"));
828         assertEquals("child-snaps", pom.getValue("distributionManagement/snapshotRepository/id"));
829         assertEquals("ssh://child.url/snaps", pom.getValue("distributionManagement/snapshotRepository/url"));
830         assertNull(pom.getValue("distributionManagement/snapshotRepository/name"));
831         assertEquals(true, pom.getValue("distributionManagement/snapshotRepository/uniqueVersion"));
832         assertEquals("default", pom.getValue("distributionManagement/snapshotRepository/layout"));
833         assertEquals("child-site", pom.getValue("distributionManagement/site/id"));
834         assertEquals("scp://child.url/site", pom.getValue("distributionManagement/site/url"));
835         assertNull(pom.getValue("distributionManagement/site/name"));
836     }
837 
838     @Test
839     void testXmlTextCoalescing() throws Exception {
840         PomTestWrapper pom = buildPom("xml-coalesce-text");
841         assertEquals("A  Test  Project Property", pom.getValue("properties/prop0"));
842         assertEquals("That's a test!", pom.getValue("properties/prop1"));
843         assertEquals(
844                 32 * 1024,
845                 pom.getValue("properties/prop2")
846                         .toString()
847                         .trim()
848                         .replaceAll("[\n\r]", "")
849                         .length());
850     }
851 
852     @Test
853     void testFullInterpolationOfNestedExpressions() throws Exception {
854         PomTestWrapper pom = buildPom("full-interpolation");
855         for (int i = 0; i < 24; i++) {
856             String index = ((i < 10) ? "0" : "") + i;
857             assertEquals("PASSED", pom.getValue("properties/property" + index));
858         }
859     }
860 
861     @Test
862     void testInterpolationWithBasedirAlignedDirectories() throws Exception {
863         PomTestWrapper pom = buildPom("basedir-aligned-interpolation");
864         assertEquals(
865                 new File(pom.getBasedir(), "src/main/java"),
866                 new File(pom.getValue("properties/buildMainSrc").toString()));
867         assertEquals(
868                 new File(pom.getBasedir(), "src/test/java"),
869                 new File(pom.getValue("properties/buildTestSrc").toString()));
870         assertEquals(
871                 new File(pom.getBasedir(), "src/main/scripts"),
872                 new File(pom.getValue("properties/buildScriptSrc").toString()));
873         assertEquals(
874                 new File(pom.getBasedir(), "target"),
875                 new File(pom.getValue("properties/buildOut").toString()));
876         assertEquals(
877                 new File(pom.getBasedir(), "target/classes"),
878                 new File(pom.getValue("properties/buildMainOut").toString()));
879         assertEquals(
880                 new File(pom.getBasedir(), "target/test-classes"),
881                 new File(pom.getValue("properties/buildTestOut").toString()));
882         assertEquals(
883                 new File(pom.getBasedir(), "target/site"),
884                 new File(pom.getValue("properties/siteOut").toString()));
885     }
886 
887     /* MNG-3944*/
888     @Test
889     void testInterpolationOfBasedirInPomWithUnusualName() throws Exception {
890         PomTestWrapper pom = buildPom("basedir-interpolation/pom-with-unusual-name.xml");
891         assertEquals(pom.getBasedir(), new File(pom.getValue("properties/prop0").toString()));
892         assertEquals(pom.getBasedir(), new File(pom.getValue("properties/prop1").toString()));
893     }
894 
895     /* MNG-3979 */
896     @Test
897     void testJoiningOfContainersWhenChildHasEmptyElements() throws Exception {
898         PomTestWrapper pom = buildPom("id-container-joining-with-empty-elements/sub");
899         assertNotNull(pom);
900     }
901 
902     @Test
903     void testOrderOfPluginConfigurationElementsWithoutPluginManagement() throws Exception {
904         PomTestWrapper pom = buildPom("plugin-config-order/wo-plugin-mgmt");
905         assertEquals("one", pom.getValue("build/plugins[1]/configuration/stringParams/stringParam[1]"));
906         assertEquals("two", pom.getValue("build/plugins[1]/configuration/stringParams/stringParam[2]"));
907         assertEquals("three", pom.getValue("build/plugins[1]/configuration/stringParams/stringParam[3]"));
908         assertEquals("four", pom.getValue("build/plugins[1]/configuration/stringParams/stringParam[4]"));
909     }
910 
911     /* MNG-3827*/
912     @Test
913     void testOrderOfPluginConfigurationElementsWithPluginManagement() throws Exception {
914         PomTestWrapper pom = buildPom("plugin-config-order/w-plugin-mgmt");
915         assertEquals("one", pom.getValue("build/plugins[1]/configuration/stringParams/stringParam[1]"));
916         assertEquals("two", pom.getValue("build/plugins[1]/configuration/stringParams/stringParam[2]"));
917         assertEquals("three", pom.getValue("build/plugins[1]/configuration/stringParams/stringParam[3]"));
918         assertEquals("four", pom.getValue("build/plugins[1]/configuration/stringParams/stringParam[4]"));
919     }
920 
921     @Test
922     void testOrderOfPluginExecutionConfigurationElementsWithoutPluginManagement() throws Exception {
923         PomTestWrapper pom = buildPom("plugin-exec-config-order/wo-plugin-mgmt");
924         String prefix = "build/plugins[1]/executions[1]/configuration/";
925         assertEquals("one", pom.getValue(prefix + "stringParams/stringParam[1]"));
926         assertEquals("two", pom.getValue(prefix + "stringParams/stringParam[2]"));
927         assertEquals("three", pom.getValue(prefix + "stringParams/stringParam[3]"));
928         assertEquals("four", pom.getValue(prefix + "stringParams/stringParam[4]"));
929         assertEquals("key1", pom.getValue(prefix + "propertiesParam/property[1]/name"));
930         assertEquals("key2", pom.getValue(prefix + "propertiesParam/property[2]/name"));
931     }
932 
933     /* MNG-3864*/
934     @Test
935     void testOrderOfPluginExecutionConfigurationElementsWithPluginManagement() throws Exception {
936         PomTestWrapper pom = buildPom("plugin-exec-config-order/w-plugin-mgmt");
937         String prefix = "build/plugins[1]/executions[1]/configuration/";
938         assertEquals("one", pom.getValue(prefix + "stringParams/stringParam[1]"));
939         assertEquals("two", pom.getValue(prefix + "stringParams/stringParam[2]"));
940         assertEquals("three", pom.getValue(prefix + "stringParams/stringParam[3]"));
941         assertEquals("four", pom.getValue(prefix + "stringParams/stringParam[4]"));
942         assertEquals("key1", pom.getValue(prefix + "propertiesParam/property[1]/name"));
943         assertEquals("key2", pom.getValue(prefix + "propertiesParam/property[2]/name"));
944     }
945 
946     /* MNG-3836*/
947     @Test
948     void testMergeOfInheritedPluginConfiguration() throws Exception {
949         PomTestWrapper pom = buildPom("plugin-config-merging/child");
950 
951         String prefix = "build/plugins[1]/configuration/";
952         assertEquals("PASSED", pom.getValue(prefix + "propertiesFile"));
953         assertEquals("PASSED", pom.getValue(prefix + "parent"));
954         assertEquals("PASSED-1", pom.getValue(prefix + "stringParams/stringParam[1]"));
955         assertEquals("PASSED-3", pom.getValue(prefix + "stringParams/stringParam[2]"));
956         assertEquals("PASSED-2", pom.getValue(prefix + "stringParams/stringParam[3]"));
957         assertEquals("PASSED-4", pom.getValue(prefix + "stringParams/stringParam[4]"));
958         assertEquals("PASSED-1", pom.getValue(prefix + "listParam/listParam[1]"));
959         assertEquals("PASSED-3", pom.getValue(prefix + "listParam/listParam[2]"));
960         assertEquals("PASSED-2", pom.getValue(prefix + "listParam/listParam[3]"));
961         assertEquals("PASSED-4", pom.getValue(prefix + "listParam/listParam[4]"));
962     }
963 
964     /* MNG-2591 */
965     @Test
966     void testAppendOfInheritedPluginConfigurationWithNoProfile() throws Exception {
967         testAppendOfInheritedPluginConfiguration("no-profile");
968     }
969 
970     /* MNG-2591*/
971     @Test
972     void testAppendOfInheritedPluginConfigurationWithActiveProfile() throws Exception {
973         testAppendOfInheritedPluginConfiguration("with-profile");
974     }
975 
976     private void testAppendOfInheritedPluginConfiguration(String test) throws Exception {
977         PomTestWrapper pom = buildPom("plugin-config-append/" + test + "/subproject");
978         String prefix = "build/plugins[1]/configuration/";
979         assertEquals("PARENT-1", pom.getValue(prefix + "stringParams/stringParam[1]"));
980         assertEquals("PARENT-3", pom.getValue(prefix + "stringParams/stringParam[2]"));
981         assertEquals("PARENT-2", pom.getValue(prefix + "stringParams/stringParam[3]"));
982         assertEquals("PARENT-4", pom.getValue(prefix + "stringParams/stringParam[4]"));
983         assertEquals("CHILD-1", pom.getValue(prefix + "stringParams/stringParam[5]"));
984         assertEquals("CHILD-3", pom.getValue(prefix + "stringParams/stringParam[6]"));
985         assertEquals("CHILD-2", pom.getValue(prefix + "stringParams/stringParam[7]"));
986         assertEquals("CHILD-4", pom.getValue(prefix + "stringParams/stringParam[8]"));
987         assertNull(pom.getValue(prefix + "stringParams/stringParam[9]"));
988         assertEquals("PARENT-1", pom.getValue(prefix + "listParam/listParam[1]"));
989         assertEquals("PARENT-3", pom.getValue(prefix + "listParam/listParam[2]"));
990         assertEquals("PARENT-2", pom.getValue(prefix + "listParam/listParam[3]"));
991         assertEquals("PARENT-4", pom.getValue(prefix + "listParam/listParam[4]"));
992         assertEquals("CHILD-1", pom.getValue(prefix + "listParam/listParam[5]"));
993         assertEquals("CHILD-3", pom.getValue(prefix + "listParam/listParam[6]"));
994         assertEquals("CHILD-2", pom.getValue(prefix + "listParam/listParam[7]"));
995         assertEquals("CHILD-4", pom.getValue(prefix + "listParam/listParam[8]"));
996         assertNull(pom.getValue(prefix + "listParam/listParam[9]"));
997     }
998 
999     /* MNG-4000 */
1000     @Test
1001     void testMultiplePluginExecutionsWithAndWithoutIdsWithoutPluginManagement() throws Exception {
1002         PomTestWrapper pom = buildPom("plugin-exec-w-and-wo-id/wo-plugin-mgmt");
1003         assertEquals(2, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
1004         assertEquals("log-string", pom.getValue("build/plugins[1]/executions[1]/goals[1]"));
1005         assertEquals("log-string", pom.getValue("build/plugins[1]/executions[2]/goals[1]"));
1006     }
1007 
1008     @Test
1009     void testMultiplePluginExecutionsWithAndWithoutIdsWithPluginManagement() throws Exception {
1010         PomTestWrapper pom = buildPom("plugin-exec-w-and-wo-id/w-plugin-mgmt");
1011         assertEquals(2, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
1012         assertEquals("log-string", pom.getValue("build/plugins[1]/executions[1]/goals[1]"));
1013         assertEquals("log-string", pom.getValue("build/plugins[1]/executions[2]/goals[1]"));
1014     }
1015 
1016     @Test
1017     void testDependencyOrderWithoutPluginManagement() throws Exception {
1018         PomTestWrapper pom = buildPom("dependency-order/wo-plugin-mgmt");
1019         assertEquals(4, ((List<?>) pom.getValue("dependencies")).size());
1020         assertEquals("a", pom.getValue("dependencies[1]/artifactId"));
1021         assertEquals("c", pom.getValue("dependencies[2]/artifactId"));
1022         assertEquals("b", pom.getValue("dependencies[3]/artifactId"));
1023         assertEquals("d", pom.getValue("dependencies[4]/artifactId"));
1024     }
1025 
1026     @Test
1027     void testDependencyOrderWithPluginManagement() throws Exception {
1028         PomTestWrapper pom = buildPom("dependency-order/w-plugin-mgmt");
1029         assertEquals(4, ((List<?>) pom.getValue("dependencies")).size());
1030         assertEquals("a", pom.getValue("dependencies[1]/artifactId"));
1031         assertEquals("c", pom.getValue("dependencies[2]/artifactId"));
1032         assertEquals("b", pom.getValue("dependencies[3]/artifactId"));
1033         assertEquals("d", pom.getValue("dependencies[4]/artifactId"));
1034     }
1035 
1036     @Test
1037     void testBuildDirectoriesUsePlatformSpecificFileSeparator() throws Exception {
1038         PomTestWrapper pom = buildPom("platform-file-separator");
1039         assertPathWithNormalizedFileSeparators(pom.getValue("build/directory"));
1040         assertPathWithNormalizedFileSeparators(pom.getValue("build/outputDirectory"));
1041         assertPathWithNormalizedFileSeparators(pom.getValue("build/testOutputDirectory"));
1042         assertPathWithNormalizedFileSeparators(pom.getValue("build/sourceDirectory"));
1043         assertPathWithNormalizedFileSeparators(pom.getValue("build/testSourceDirectory"));
1044         assertPathWithNormalizedFileSeparators(pom.getValue("build/resources[1]/directory"));
1045         assertPathWithNormalizedFileSeparators(pom.getValue("build/testResources[1]/directory"));
1046         assertPathWithNormalizedFileSeparators(pom.getValue("build/filters[1]"));
1047         assertPathWithNormalizedFileSeparators(pom.getValue("reporting/outputDirectory"));
1048     }
1049 
1050     /* MNG-4008 */
1051     @Test
1052     void testMergedFilterOrder() throws Exception {
1053         PomTestWrapper pom = buildPom("merged-filter-order/sub");
1054 
1055         assertEquals(7, ((List<?>) pom.getValue("build/filters")).size());
1056         assertThat(pom.getValue("build/filters[1]").toString(), endsWith("child-a.properties"));
1057         assertThat(pom.getValue("build/filters[2]").toString(), endsWith("child-c.properties"));
1058         assertThat(pom.getValue("build/filters[3]").toString(), endsWith("child-b.properties"));
1059         assertThat(pom.getValue("build/filters[4]").toString(), endsWith("child-d.properties"));
1060         assertThat(pom.getValue("build/filters[5]").toString(), endsWith("parent-c.properties"));
1061         assertThat(pom.getValue("build/filters[6]").toString(), endsWith("parent-b.properties"));
1062         assertThat(pom.getValue("build/filters[7]").toString(), endsWith("parent-d.properties"));
1063     }
1064 
1065     /** MNG-4027*/
1066     @Test
1067     void testProfileInjectedDependencies() throws Exception {
1068         PomTestWrapper pom = buildPom("profile-injected-dependencies");
1069         assertEquals(4, ((List<?>) pom.getValue("dependencies")).size());
1070         assertEquals("a", pom.getValue("dependencies[1]/artifactId"));
1071         assertEquals("c", pom.getValue("dependencies[2]/artifactId"));
1072         assertEquals("b", pom.getValue("dependencies[3]/artifactId"));
1073         assertEquals("d", pom.getValue("dependencies[4]/artifactId"));
1074     }
1075 
1076     /** IT-0021*/
1077     @Test
1078     void testProfileDependenciesMultipleProfiles() throws Exception {
1079         PomTestWrapper pom = buildPom("profile-dependencies-multiple-profiles", "profile-1", "profile-2");
1080         assertEquals(2, ((List<?>) pom.getValue("dependencies")).size());
1081     }
1082 
1083     @Test
1084     void testDependencyInheritance() throws Exception {
1085         PomTestWrapper pom = buildPom("dependency-inheritance/sub");
1086         assertEquals(1, ((List<?>) pom.getValue("dependencies")).size());
1087         assertEquals("4.13.1", pom.getValue("dependencies[1]/version"));
1088     }
1089 
1090     /** MNG-4034 */
1091     @Test
1092     void testManagedProfileDependency() throws Exception {
1093         PomTestWrapper pom = this.buildPom("managed-profile-dependency/sub", "maven-core-it");
1094         assertEquals(1, ((List<?>) pom.getValue("dependencies")).size());
1095         assertEquals("org.apache.maven.its", pom.getValue("dependencies[1]/groupId"));
1096         assertEquals("maven-core-it-support", pom.getValue("dependencies[1]/artifactId"));
1097         assertEquals("1.3", pom.getValue("dependencies[1]/version"));
1098         assertEquals("runtime", pom.getValue("dependencies[1]/scope"));
1099         assertEquals(1, ((List<?>) pom.getValue("dependencies[1]/exclusions")).size());
1100         assertEquals("commons-lang", pom.getValue("dependencies[1]/exclusions[1]/groupId"));
1101     }
1102 
1103     /** MNG-4040 */
1104     @Test
1105     void testProfileModuleInheritance() throws Exception {
1106         PomTestWrapper pom = this.buildPom("profile-module-inheritance/sub", "dist");
1107         assertEquals(0, ((List<?>) pom.getValue("modules")).size());
1108     }
1109 
1110     /** MNG-3621 */
1111     @Test
1112     void testUncPath() throws Exception {
1113         PomTestWrapper pom = this.buildPom("unc-path/sub");
1114         assertEquals("file:////host/site/test-child", pom.getValue("distributionManagement/site/url"));
1115     }
1116 
1117     /** MNG-2006 */
1118     @Test
1119     void testUrlAppendWithChildPathAdjustment() throws Exception {
1120         PomTestWrapper pom = this.buildPom("url-append/child");
1121         assertEquals("https://project.url/child", pom.getValue("url"));
1122         assertEquals("https://viewvc.project.url/child", pom.getValue("scm/url"));
1123         assertEquals("https://scm.project.url/child", pom.getValue("scm/connection"));
1124         assertEquals("https://scm.project.url/child", pom.getValue("scm/developerConnection"));
1125         assertEquals("https://site.project.url/child", pom.getValue("distributionManagement/site/url"));
1126     }
1127 
1128     /** MNG-0479 */
1129     @Test
1130     void testRepoInheritance() throws Exception {
1131         PomTestWrapper pom = this.buildPom("repo-inheritance");
1132         assertEquals(1, ((List<?>) pom.getValue("repositories")).size());
1133         assertEquals("it0043", pom.getValue("repositories[1]/name"));
1134     }
1135 
1136     @Test
1137     void testEmptyScm() throws Exception {
1138         PomTestWrapper pom = this.buildPom("empty-scm");
1139         assertNull(pom.getValue("scm"));
1140     }
1141 
1142     @Test
1143     void testPluginConfigurationUsingAttributesWithoutPluginManagement() throws Exception {
1144         PomTestWrapper pom = buildPom("plugin-config-attributes/wo-plugin-mgmt");
1145         assertEquals("src", pom.getValue("build/plugins[1]/configuration/domParam/copy/@todir"));
1146         assertEquals("true", pom.getValue("build/plugins[1]/configuration/domParam/copy/@overwrite"));
1147         assertEquals("target", pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset/@dir"));
1148         assertNull(pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset/@todir"));
1149         assertNull(pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset/@overwrite"));
1150     }
1151 
1152     /** MNG-4053*/
1153     @Test
1154     void testPluginConfigurationUsingAttributesWithPluginManagement() throws Exception {
1155         PomTestWrapper pom = buildPom("plugin-config-attributes/w-plugin-mgmt");
1156         assertEquals("src", pom.getValue("build/plugins[1]/configuration/domParam/copy/@todir"));
1157         assertEquals("true", pom.getValue("build/plugins[1]/configuration/domParam/copy/@overwrite"));
1158         assertEquals("target", pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset/@dir"));
1159         assertNull(pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset/@todir"));
1160         assertNull(pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset/@overwrite"));
1161     }
1162 
1163     @Test
1164     void testPluginConfigurationUsingAttributesWithPluginManagementAndProfile() throws Exception {
1165         PomTestWrapper pom = buildPom("plugin-config-attributes/w-profile", "maven-core-it");
1166         assertEquals("src", pom.getValue("build/plugins[1]/configuration/domParam/copy/@todir"));
1167         assertEquals("true", pom.getValue("build/plugins[1]/configuration/domParam/copy/@overwrite"));
1168         assertEquals("target", pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset/@dir"));
1169         assertNull(pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset/@todir"));
1170         assertNull(pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset/@overwrite"));
1171     }
1172 
1173     @Test
1174     void testPomEncoding() throws Exception {
1175         PomTestWrapper pom = buildPom("pom-encoding/utf-8");
1176         assertEquals("TEST-CHARS: \u00DF\u0131\u03A3\u042F\u05D0\u20AC", pom.getValue("description"));
1177         pom = buildPom("pom-encoding/latin-1");
1178         assertEquals("TEST-CHARS: \u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF", pom.getValue("description"));
1179     }
1180 
1181     /* MNG-4070 */
1182     @Test
1183     void testXmlWhitespaceHandling() throws Exception {
1184         PomTestWrapper pom = buildPom("xml-whitespace/sub");
1185         assertEquals("org.apache.maven.its.mng4070", pom.getValue("groupId"));
1186     }
1187 
1188     /* MNG-3760*/
1189     @Test
1190     void testInterpolationOfBaseUri() throws Exception {
1191         PomTestWrapper pom = buildPom("baseuri-interpolation/pom.xml");
1192         assertNotEquals(
1193                 pom.getBasedir().toURI().toString(),
1194                 pom.getValue("properties/prop1").toString());
1195     }
1196 
1197     /* MNG-6386 */
1198     @Test
1199     void testInterpolationOfRfc3986BaseUri() throws Exception {
1200         PomTestWrapper pom = buildPom("baseuri-interpolation/pom.xml");
1201         String prop1 = pom.getValue("properties/prop1").toString();
1202         assertEquals(pom.getBasedir().toPath().toUri().toASCIIString(), prop1);
1203         assertThat(prop1, startsWith("file:///"));
1204     }
1205 
1206     /* MNG-3811*/
1207     @Test
1208     void testReportingPluginConfig() throws Exception {
1209         PomTestWrapper pom = buildPom("reporting-plugin-config/sub");
1210 
1211         assertEquals(3, ((List<?>) pom.getValue("reporting/plugins[1]/configuration/stringParams")).size());
1212         assertEquals("parentParam", pom.getValue("reporting/plugins[1]/configuration/stringParams[1]/stringParam[1]"));
1213         assertEquals("childParam", pom.getValue("reporting/plugins[1]/configuration/stringParams[1]/stringParam[2]"));
1214         assertEquals(
1215                 "  preserve space  ",
1216                 pom.getValue("reporting/plugins[1]/configuration/stringParams[1]/stringParam[3]"));
1217         assertEquals("true", pom.getValue("reporting/plugins[1]/configuration/booleanParam"));
1218     }
1219 
1220     @Test
1221     void testPropertiesNoDuplication() throws Exception {
1222         PomTestWrapper pom = buildPom("properties-no-duplication/sub");
1223         assertEquals(3, ((Properties) pom.getValue("properties")).size());
1224         assertEquals("child", pom.getValue("properties/pomProfile"));
1225     }
1226 
1227     @Test
1228     void testPomInheritance() throws Exception {
1229         PomTestWrapper pom = buildPom("pom-inheritance/sub");
1230         assertEquals("parent-description", pom.getValue("description"));
1231         assertEquals("jar", pom.getValue("packaging"));
1232     }
1233 
1234     @Test
1235     void testCompleteModelWithoutParent() throws Exception {
1236         PomTestWrapper pom = buildPom("complete-model/wo-parent");
1237 
1238         testCompleteModel(pom);
1239     }
1240 
1241     @Test
1242     void testCompleteModelWithParent() throws Exception {
1243         PomTestWrapper pom = buildPom("complete-model/w-parent/sub");
1244 
1245         testCompleteModel(pom);
1246     }
1247 
1248     private void testCompleteModel(PomTestWrapper pom) throws Exception {
1249         assertEquals("4.0.0", pom.getValue("modelVersion"));
1250 
1251         assertEquals("org.apache.maven.its.mng", pom.getValue("groupId"));
1252         assertEquals("test", pom.getValue("artifactId"));
1253         assertEquals("0.2", pom.getValue("version"));
1254         assertEquals("pom", pom.getValue("packaging"));
1255 
1256         assertEquals("project-name", pom.getValue("name"));
1257         assertEquals("project-description", pom.getValue("description"));
1258         assertEquals("https://project.url/", pom.getValue("url"));
1259         assertEquals("2009", pom.getValue("inceptionYear"));
1260 
1261         assertEquals("project-org", pom.getValue("organization/name"));
1262         assertEquals("https://project-org.url/", pom.getValue("organization/url"));
1263 
1264         assertEquals(1, ((List<?>) pom.getValue("licenses")).size());
1265         assertEquals("project-license", pom.getValue("licenses[1]/name"));
1266         assertEquals("https://project.url/license", pom.getValue("licenses[1]/url"));
1267         assertEquals("repo", pom.getValue("licenses[1]/distribution"));
1268         assertEquals("free", pom.getValue("licenses[1]/comments"));
1269 
1270         assertEquals(1, ((List<?>) pom.getValue("developers")).size());
1271         assertEquals("dev", pom.getValue("developers[1]/id"));
1272         assertEquals("project-developer", pom.getValue("developers[1]/name"));
1273         assertEquals("developer@", pom.getValue("developers[1]/email"));
1274         assertEquals("https://developer", pom.getValue("developers[1]/url"));
1275         assertEquals("developer", pom.getValue("developers[1]/organization"));
1276         assertEquals("https://devel.org", pom.getValue("developers[1]/organizationUrl"));
1277         assertEquals("-1", pom.getValue("developers[1]/timezone"));
1278         assertEquals("yes", pom.getValue("developers[1]/properties/developer"));
1279         assertEquals(1, ((List<?>) pom.getValue("developers[1]/roles")).size());
1280         assertEquals("devel", pom.getValue("developers[1]/roles[1]"));
1281 
1282         assertEquals(1, ((List<?>) pom.getValue("contributors")).size());
1283         assertEquals("project-contributor", pom.getValue("contributors[1]/name"));
1284         assertEquals("contributor@", pom.getValue("contributors[1]/email"));
1285         assertEquals("https://contributor", pom.getValue("contributors[1]/url"));
1286         assertEquals("contributor", pom.getValue("contributors[1]/organization"));
1287         assertEquals("https://contrib.org", pom.getValue("contributors[1]/organizationUrl"));
1288         assertEquals("+1", pom.getValue("contributors[1]/timezone"));
1289         assertEquals("yes", pom.getValue("contributors[1]/properties/contributor"));
1290         assertEquals(1, ((List<?>) pom.getValue("contributors[1]/roles")).size());
1291         assertEquals("contrib", pom.getValue("contributors[1]/roles[1]"));
1292 
1293         assertEquals(1, ((List<?>) pom.getValue("mailingLists")).size());
1294         assertEquals("project-mailing-list", pom.getValue("mailingLists[1]/name"));
1295         assertEquals("subscribe@", pom.getValue("mailingLists[1]/subscribe"));
1296         assertEquals("unsubscribe@", pom.getValue("mailingLists[1]/unsubscribe"));
1297         assertEquals("post@", pom.getValue("mailingLists[1]/post"));
1298         assertEquals("mail-archive", pom.getValue("mailingLists[1]/archive"));
1299         assertEquals(1, ((List<?>) pom.getValue("mailingLists[1]/otherArchives")).size());
1300         assertEquals("other-archive", pom.getValue("mailingLists[1]/otherArchives[1]"));
1301 
1302         assertEquals("2.0.1", pom.getValue("prerequisites/maven"));
1303 
1304         assertEquals("https://project.url/trunk", pom.getValue("scm/url"));
1305         assertEquals("https://project.url/scm", pom.getValue("scm/connection"));
1306         assertEquals("https://project.url/scm", pom.getValue("scm/developerConnection"));
1307         assertEquals("TAG", pom.getValue("scm/tag"));
1308 
1309         assertEquals("issues", pom.getValue("issueManagement/system"));
1310         assertEquals("https://project.url/issues", pom.getValue("issueManagement/url"));
1311 
1312         assertEquals("ci", pom.getValue("ciManagement/system"));
1313         assertEquals("https://project.url/ci", pom.getValue("ciManagement/url"));
1314         assertEquals(1, ((List<?>) pom.getValue("ciManagement/notifiers")).size());
1315         assertEquals("irc", pom.getValue("ciManagement/notifiers[1]/type"));
1316         assertEquals("ci@", pom.getValue("ciManagement/notifiers[1]/address"));
1317         assertEquals(Boolean.TRUE, pom.getValue("ciManagement/notifiers[1]/sendOnError"));
1318         assertEquals(Boolean.FALSE, pom.getValue("ciManagement/notifiers[1]/sendOnFailure"));
1319         assertEquals(Boolean.FALSE, pom.getValue("ciManagement/notifiers[1]/sendOnWarning"));
1320         assertEquals(Boolean.FALSE, pom.getValue("ciManagement/notifiers[1]/sendOnSuccess"));
1321         assertEquals("ci", pom.getValue("ciManagement/notifiers[1]/configuration/ciProp"));
1322 
1323         assertEquals("project.distros", pom.getValue("distributionManagement/repository/id"));
1324         assertEquals("distros", pom.getValue("distributionManagement/repository/name"));
1325         assertEquals("https://project.url/dist", pom.getValue("distributionManagement/repository/url"));
1326         assertEquals(Boolean.TRUE, pom.getValue("distributionManagement/repository/uniqueVersion"));
1327 
1328         assertEquals("project.snaps", pom.getValue("distributionManagement/snapshotRepository/id"));
1329         assertEquals("snaps", pom.getValue("distributionManagement/snapshotRepository/name"));
1330         assertEquals("https://project.url/snaps", pom.getValue("distributionManagement/snapshotRepository/url"));
1331         assertEquals(Boolean.FALSE, pom.getValue("distributionManagement/snapshotRepository/uniqueVersion"));
1332 
1333         assertEquals("project.site", pom.getValue("distributionManagement/site/id"));
1334         assertEquals("docs", pom.getValue("distributionManagement/site/name"));
1335         assertEquals("https://project.url/site", pom.getValue("distributionManagement/site/url"));
1336 
1337         assertEquals("https://project.url/download", pom.getValue("distributionManagement/downloadUrl"));
1338         assertEquals("reloc-gid", pom.getValue("distributionManagement/relocation/groupId"));
1339         assertEquals("reloc-aid", pom.getValue("distributionManagement/relocation/artifactId"));
1340         assertEquals("reloc-version", pom.getValue("distributionManagement/relocation/version"));
1341         assertEquals("project-reloc-msg", pom.getValue("distributionManagement/relocation/message"));
1342 
1343         assertEquals(1, ((List<?>) pom.getValue("modules")).size());
1344         assertEquals("sub", pom.getValue("modules[1]"));
1345 
1346         assertEquals(3, ((Map<?, ?>) pom.getValue("properties")).size());
1347         assertEquals("project-property", pom.getValue("properties[1]/itProperty"));
1348         assertEquals("UTF-8", pom.getValue("properties[1]/project.build.sourceEncoding"));
1349         assertEquals("UTF-8", pom.getValue("properties[1]/project.reporting.outputEncoding"));
1350 
1351         assertEquals(1, ((List<?>) pom.getValue("dependencyManagement/dependencies")).size());
1352         assertEquals("org.apache.maven.its", pom.getValue("dependencyManagement/dependencies[1]/groupId"));
1353         assertEquals("managed-dep", pom.getValue("dependencyManagement/dependencies[1]/artifactId"));
1354         assertEquals("0.1", pom.getValue("dependencyManagement/dependencies[1]/version"));
1355         assertEquals("war", pom.getValue("dependencyManagement/dependencies[1]/type"));
1356         assertEquals("runtime", pom.getValue("dependencyManagement/dependencies[1]/scope"));
1357         assertEquals(Boolean.FALSE, pom.getValue("dependencyManagement/dependencies[1]/optional"));
1358         assertEquals(1, ((List<?>) pom.getValue("dependencyManagement/dependencies[1]/exclusions")).size());
1359         assertEquals(
1360                 "org.apache.maven.its", pom.getValue("dependencyManagement/dependencies[1]/exclusions[1]/groupId"));
1361         assertEquals(
1362                 "excluded-managed-dep", pom.getValue("dependencyManagement/dependencies[1]/exclusions[1]/artifactId"));
1363 
1364         assertEquals(1, ((List<?>) pom.getValue("dependencies")).size());
1365         assertEquals("org.apache.maven.its", pom.getValue("dependencies[1]/groupId"));
1366         assertEquals("dep", pom.getValue("dependencies[1]/artifactId"));
1367         assertEquals("0.2", pom.getValue("dependencies[1]/version"));
1368         assertEquals("ejb", pom.getValue("dependencies[1]/type"));
1369         assertEquals("test", pom.getValue("dependencies[1]/scope"));
1370         assertEquals(Boolean.TRUE, pom.getValue("dependencies[1]/optional"));
1371         assertEquals(1, ((List<?>) pom.getValue("dependencies[1]/exclusions")).size());
1372         assertEquals("org.apache.maven.its", pom.getValue("dependencies[1]/exclusions[1]/groupId"));
1373         assertEquals("excluded-dep", pom.getValue("dependencies[1]/exclusions[1]/artifactId"));
1374 
1375         assertEquals(1, ((List<?>) pom.getValue("repositories")).size());
1376         assertEquals("project-remote-repo", pom.getValue("repositories[1]/id"));
1377         assertEquals("https://project.url/remote", pom.getValue("repositories[1]/url"));
1378         assertEquals("repo", pom.getValue("repositories[1]/name"));
1379 
1380         assertEquals("test", pom.getValue("build/defaultGoal"));
1381         assertEquals("coreit", pom.getValue("build/finalName"));
1382 
1383         assertPathSuffixEquals("build", pom.getValue("build/directory"));
1384         assertPathSuffixEquals("build/main", pom.getValue("build/outputDirectory"));
1385         assertPathSuffixEquals("build/test", pom.getValue("build/testOutputDirectory"));
1386         assertPathSuffixEquals("sources/main", pom.getValue("build/sourceDirectory"));
1387         assertPathSuffixEquals("sources/test", pom.getValue("build/testSourceDirectory"));
1388         assertPathSuffixEquals("sources/scripts", pom.getValue("build/scriptSourceDirectory"));
1389 
1390         assertEquals(1, ((List<?>) pom.getValue("build/filters")).size());
1391         assertPathSuffixEquals("src/main/filter/it.properties", pom.getValue("build/filters[1]"));
1392 
1393         assertEquals(1, ((List<?>) pom.getValue("build/resources")).size());
1394         assertPathSuffixEquals("res/main", pom.getValue("build/resources[1]/directory"));
1395         assertPathSuffixEquals("main", pom.getValue("build/resources[1]/targetPath"));
1396         assertEquals(Boolean.TRUE, pom.getValue("build/resources[1]/filtering"));
1397         assertEquals(1, ((List<?>) pom.getValue("build/resources[1]/includes")).size());
1398         assertPathSuffixEquals("main.included", pom.getValue("build/resources[1]/includes[1]"));
1399         assertEquals(1, ((List<?>) pom.getValue("build/resources[1]/excludes")).size());
1400         assertPathSuffixEquals("main.excluded", pom.getValue("build/resources[1]/excludes[1]"));
1401 
1402         assertEquals(1, ((List<?>) pom.getValue("build/testResources")).size());
1403         assertPathSuffixEquals("res/test", pom.getValue("build/testResources[1]/directory"));
1404         assertPathSuffixEquals("test", pom.getValue("build/testResources[1]/targetPath"));
1405         assertEquals(Boolean.TRUE, pom.getValue("build/testResources[1]/filtering"));
1406         assertEquals(1, ((List<?>) pom.getValue("build/testResources[1]/includes")).size());
1407         assertPathSuffixEquals("test.included", pom.getValue("build/testResources[1]/includes[1]"));
1408         assertEquals(1, ((List<?>) pom.getValue("build/testResources[1]/excludes")).size());
1409         assertPathSuffixEquals("test.excluded", pom.getValue("build/testResources[1]/excludes[1]"));
1410 
1411         assertEquals(1, ((List<?>) pom.getValue("build/extensions")).size());
1412         assertEquals("org.apache.maven.its.ext", pom.getValue("build/extensions[1]/groupId"));
1413         assertEquals("ext", pom.getValue("build/extensions[1]/artifactId"));
1414         assertEquals("3.0", pom.getValue("build/extensions[1]/version"));
1415 
1416         assertEquals(1, ((List<?>) pom.getValue("build/plugins")).size());
1417         assertEquals("org.apache.maven.its.plugins", pom.getValue("build/plugins[1]/groupId"));
1418         assertEquals("maven-it-plugin-build", pom.getValue("build/plugins[1]/artifactId"));
1419         assertEquals("2.1-SNAPSHOT", pom.getValue("build/plugins[1]/version"));
1420         assertEquals("test.properties", pom.getValue("build/plugins[1]/configuration/outputFile"));
1421         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/executions")).size());
1422         assertEquals("test", pom.getValue("build/plugins[1]/executions[1]/id"));
1423         assertEquals("validate", pom.getValue("build/plugins[1]/executions[1]/phase"));
1424         assertEquals("pom.properties", pom.getValue("build/plugins[1]/executions[1]/configuration/outputFile"));
1425         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/executions[1]/goals")).size());
1426         assertEquals("eval", pom.getValue("build/plugins[1]/executions[1]/goals[1]"));
1427         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/dependencies")).size());
1428         assertEquals("org.apache.maven.its", pom.getValue("build/plugins[1]/dependencies[1]/groupId"));
1429         assertEquals("build-plugin-dep", pom.getValue("build/plugins[1]/dependencies[1]/artifactId"));
1430         assertEquals("0.3", pom.getValue("build/plugins[1]/dependencies[1]/version"));
1431         assertEquals("zip", pom.getValue("build/plugins[1]/dependencies[1]/type"));
1432         assertEquals(1, ((List<?>) pom.getValue("build/plugins[1]/dependencies[1]/exclusions")).size());
1433         assertEquals("org.apache.maven.its", pom.getValue("build/plugins[1]/dependencies[1]/exclusions[1]/groupId"));
1434         assertEquals(
1435                 "excluded-build-plugin-dep", pom.getValue("build/plugins[1]/dependencies[1]/exclusions[1]/artifactId"));
1436 
1437         assertEquals(Boolean.TRUE, pom.getValue("reporting/excludeDefaults"));
1438         assertPathSuffixEquals("docs", pom.getValue("reporting/outputDirectory"));
1439 
1440         assertEquals(1, ((List<?>) pom.getValue("reporting/plugins")).size());
1441         assertEquals("org.apache.maven.its.plugins", pom.getValue("reporting/plugins[1]/groupId"));
1442         assertEquals("maven-it-plugin-reporting", pom.getValue("reporting/plugins[1]/artifactId"));
1443         assertEquals("2.0-SNAPSHOT", pom.getValue("reporting/plugins[1]/version"));
1444         assertEquals("test.html", pom.getValue("reporting/plugins[1]/configuration/outputFile"));
1445         assertEquals(1, ((List<?>) pom.getValue("reporting/plugins[1]/reportSets")).size());
1446         assertEquals("it", pom.getValue("reporting/plugins[1]/reportSets[1]/id"));
1447         assertEquals("index.html", pom.getValue("reporting/plugins[1]/reportSets[1]/configuration/outputFile"));
1448         assertEquals(1, ((List<?>) pom.getValue("reporting/plugins[1]/reportSets[1]/reports")).size());
1449         assertEquals("run", pom.getValue("reporting/plugins[1]/reportSets[1]/reports[1]"));
1450     }
1451 
1452     /* MNG-2309*/
1453     @Test
1454     void testProfileInjectionOrder() throws Exception {
1455         PomTestWrapper pom = buildPom("profile-injection-order", "pom-a", "pom-b", "pom-e", "pom-c", "pom-d");
1456         assertEquals("e", pom.getValue("properties[1]/pomProperty"));
1457     }
1458 
1459     @Test
1460     void testPropertiesInheritance() throws Exception {
1461         PomTestWrapper pom = buildPom("properties-inheritance/sub");
1462         assertEquals("parent-property", pom.getValue("properties/parentProperty"));
1463         assertEquals("child-property", pom.getValue("properties/childProperty"));
1464         assertEquals("child-override", pom.getValue("properties/overriddenProperty"));
1465     }
1466 
1467     /* MNG-4102*/
1468     @Test
1469     void testInheritedPropertiesInterpolatedWithValuesFromChildWithoutProfiles() throws Exception {
1470         PomTestWrapper pom = buildPom("inherited-properties-interpolation/no-profile/sub");
1471 
1472         assertEquals("CHILD", pom.getValue("properties/overridden"));
1473         assertEquals("CHILD", pom.getValue("properties/interpolated"));
1474     }
1475 
1476     /* MNG-4102 */
1477     @Test
1478     void testInheritedPropertiesInterpolatedWithValuesFromChildWithActiveProfiles() throws Exception {
1479         PomTestWrapper pom = buildPom("inherited-properties-interpolation/active-profile/sub");
1480 
1481         assertEquals(1, pom.getMavenProject().getModel().getProfiles().size());
1482 
1483         buildPom("inherited-properties-interpolation/active-profile/sub", "it-parent", "it-child");
1484         assertEquals("CHILD", pom.getValue("properties/overridden"));
1485         assertEquals("CHILD", pom.getValue("properties/interpolated"));
1486     }
1487 
1488     /* MNG-3545 */
1489     @Test
1490     void testProfileDefaultActivation() throws Exception {
1491         PomTestWrapper pom = buildPom("profile-default-deactivation", "profile4");
1492         assertEquals(1, pom.getMavenProject().getActiveProfiles().size());
1493         assertEquals(1, ((List<?>) pom.getValue("build/plugins")).size());
1494         assertEquals("2.1", pom.getValue("build/plugins[1]/version"));
1495     }
1496 
1497     /* MNG-1995 */
1498     @Test
1499     void testBooleanInterpolation() throws Exception {
1500         PomTestWrapper pom = buildPom("boolean-interpolation");
1501         assertEquals(true, pom.getValue("repositories[1]/releases/enabled"));
1502         assertEquals(true, pom.getValue("build/resources[1]/filtering"));
1503     }
1504 
1505     /* MNG-3899 */
1506     @Test
1507     void testBuildExtensionInheritance() throws Exception {
1508         PomTestWrapper pom = buildPom("build-extension-inheritance/sub");
1509         assertEquals(3, ((List<?>) pom.getValue("build/extensions")).size());
1510         assertEquals("b", pom.getValue("build/extensions[1]/artifactId"));
1511         assertEquals("a", pom.getValue("build/extensions[2]/artifactId"));
1512         assertEquals("0.2", pom.getValue("build/extensions[2]/version"));
1513         assertEquals("c", pom.getValue("build/extensions[3]/artifactId"));
1514     }
1515 
1516     /*MNG-1957*/
1517     @Test
1518     void testJdkActivation() throws Exception {
1519         Properties props = new Properties();
1520         props.put("java.version", "1.5.0_15");
1521 
1522         PomTestWrapper pom = buildPom("jdk-activation", props, null);
1523         assertEquals(3, pom.getMavenProject().getActiveProfiles().size());
1524         assertEquals("PASSED", pom.getValue("properties/jdkProperty3"));
1525         assertEquals("PASSED", pom.getValue("properties/jdkProperty2"));
1526         assertEquals("PASSED", pom.getValue("properties/jdkProperty1"));
1527     }
1528 
1529     /* MNG-2174 */
1530     @Test
1531     void testProfilePluginMngDependencies() throws Exception {
1532         PomTestWrapper pom = buildPom("profile-plugin-mng-dependencies/sub", "maven-core-it");
1533         assertEquals("a", pom.getValue("build/plugins[1]/dependencies[1]/artifactId"));
1534     }
1535 
1536     /** MNG-4116 */
1537     @Test
1538     void testPercentEncodedUrlsMustNotBeDecoded() throws Exception {
1539         PomTestWrapper pom = this.buildPom("url-no-decoding");
1540         assertEquals("https://maven.apache.org/spacy%20path", pom.getValue("url"));
1541         assertEquals("https://svn.apache.org/viewvc/spacy%20path", pom.getValue("scm/url"));
1542         assertEquals("scm:svn:svn+ssh://svn.apache.org/spacy%20path", pom.getValue("scm/connection"));
1543         assertEquals("scm:svn:svn+ssh://svn.apache.org/spacy%20path", pom.getValue("scm/developerConnection"));
1544         assertEquals("https://issues.apache.org/spacy%20path", pom.getValue("issueManagement/url"));
1545         assertEquals("https://ci.apache.org/spacy%20path", pom.getValue("ciManagement/url"));
1546         assertEquals(
1547                 "scm:svn:svn+ssh://dist.apache.org/spacy%20path",
1548                 pom.getValue("distributionManagement/repository/url"));
1549         assertEquals(
1550                 "scm:svn:svn+ssh://snap.apache.org/spacy%20path",
1551                 pom.getValue("distributionManagement/snapshotRepository/url"));
1552         assertEquals("scm:svn:svn+ssh://site.apache.org/spacy%20path", pom.getValue("distributionManagement/site/url"));
1553     }
1554 
1555     @Test
1556     void testPluginManagementInheritance() throws Exception {
1557         PomTestWrapper pom = this.buildPom("plugin-management-inheritance");
1558         assertEquals(
1559                 "0.1-stub-SNAPSHOT",
1560                 pom.getValue("build/pluginManagement/plugins[@artifactId='maven-compiler-plugin']/version"));
1561     }
1562 
1563     @Test
1564     void testProfilePlugins() throws Exception {
1565         PomTestWrapper pom = this.buildPom("profile-plugins", "standard");
1566         assertEquals(2, ((List<?>) pom.getValue("build/plugins")).size());
1567         assertEquals("maven-assembly2-plugin", pom.getValue("build/plugins[2]/artifactId"));
1568     }
1569 
1570     @Test
1571     void testPluginInheritanceSimple() throws Exception {
1572         PomTestWrapper pom = this.buildPom("plugin-inheritance-simple/sub");
1573         assertEquals(2, ((List<?>) pom.getValue("build/plugins")).size());
1574     }
1575 
1576     @Test
1577     void testPluginManagementDuplicate() throws Exception {
1578         PomTestWrapper pom = this.buildPom("plugin-management-duplicate/sub");
1579         assertEquals(7, ((List<?>) pom.getValue("build/pluginManagement/plugins")).size());
1580     }
1581 
1582     @Test
1583     void testDistributionManagement() throws Exception {
1584         PomTestWrapper pom = this.buildPom("distribution-management");
1585         assertEquals("legacy", pom.getValue("distributionManagement/repository/layout"));
1586     }
1587 
1588     @Test
1589     void testDependencyScopeInheritance() throws Exception {
1590         PomTestWrapper pom = buildPom("dependency-scope-inheritance/sub");
1591         String scope = (String) pom.getValue("dependencies[1]/scope");
1592         assertEquals("compile", scope);
1593     }
1594 
1595     @Test
1596     void testDependencyScope() throws Exception {
1597         buildPom("dependency-scope/sub");
1598     }
1599 
1600     // This will fail on a validation error if incorrect
1601     public void testDependencyManagementWithInterpolation() throws Exception {
1602         buildPom("dependency-management-with-interpolation/sub");
1603     }
1604 
1605     @Test
1606     void testInterpolationWithSystemProperty() throws Exception {
1607         Properties sysProps = new Properties();
1608         sysProps.setProperty("system.property", "PASSED");
1609         PomTestWrapper pom = buildPom("system-property-interpolation", sysProps, null);
1610         assertEquals("PASSED", pom.getValue("name"));
1611     }
1612 
1613     /* MNG-4129 */
1614     @Test
1615     void testPluginExecutionInheritanceWhenChildDoesNotDeclarePlugin() throws Exception {
1616         PomTestWrapper pom = buildPom("plugin-exec-inheritance/wo-merge");
1617         @SuppressWarnings("unchecked")
1618         List<PluginExecution> executions = (List<PluginExecution>) pom.getValue(
1619                 "build/pluginsAsMap[@name='org.apache.maven.its.plugins:maven-it-plugin-log-file']/executions");
1620         assertEquals(1, executions.size());
1621         assertEquals("inherited-execution", executions.get(0).getId());
1622     }
1623 
1624     @Test
1625     void testPluginExecutionInheritanceWhenChildDoesDeclarePluginAsWell() throws Exception {
1626         PomTestWrapper pom = buildPom("plugin-exec-inheritance/w-merge");
1627         @SuppressWarnings("unchecked")
1628         List<PluginExecution> executions = (List<PluginExecution>) pom.getValue(
1629                 "build/pluginsAsMap[@name='org.apache.maven.its.plugins:maven-it-plugin-log-file']/executions");
1630         assertEquals(1, executions.size());
1631         assertEquals("inherited-execution", executions.get(0).getId());
1632     }
1633 
1634     /* MNG-4193 */
1635     @Test
1636     void testValidationErrorUponNonUniqueArtifactRepositoryId() throws Exception {
1637         assertThrows(
1638                 ProjectBuildingException.class,
1639                 () -> buildPom("unique-repo-id/artifact-repo"),
1640                 "Non-unique repository ids did not cause validation error");
1641     }
1642 
1643     /* MNG-4193 */
1644     @Test
1645     void testValidationErrorUponNonUniquePluginRepositoryId() throws Exception {
1646         assertThrows(
1647                 ProjectBuildingException.class,
1648                 () -> buildPom("unique-repo-id/plugin-repo"),
1649                 "Non-unique repository ids did not cause validation error");
1650     }
1651 
1652     /* MNG-4193 */
1653     @Test
1654     void testValidationErrorUponNonUniqueArtifactRepositoryIdInProfile() throws Exception {
1655         assertThrows(
1656                 ProjectBuildingException.class,
1657                 () -> buildPom("unique-repo-id/artifact-repo-in-profile"),
1658                 "Non-unique repository ids did not cause validation error");
1659     }
1660 
1661     /* MNG-4193 */
1662     @Test
1663     void testValidationErrorUponNonUniquePluginRepositoryIdInProfile() throws Exception {
1664         assertThrows(
1665                 ProjectBuildingException.class,
1666                 () -> buildPom("unique-repo-id/plugin-repo-in-profile"),
1667                 "Non-unique repository ids did not cause validation error");
1668     }
1669 
1670     /** MNG-3843 */
1671     @Test
1672     void testPrerequisitesAreNotInherited() throws Exception {
1673         PomTestWrapper pom = buildPom("prerequisites-inheritance/child");
1674         assertSame(null, pom.getValue("prerequisites"));
1675     }
1676 
1677     @Test
1678     void testLicensesAreInheritedButNotAggregated() throws Exception {
1679         PomTestWrapper pom = buildPom("licenses-inheritance/child-2");
1680         assertEquals(1, ((List<?>) pom.getValue("licenses")).size());
1681         assertEquals("child-license", pom.getValue("licenses[1]/name"));
1682         assertEquals("https://child.url/license", pom.getValue("licenses[1]/url"));
1683     }
1684 
1685     @Test
1686     void testDevelopersAreInheritedButNotAggregated() throws Exception {
1687         PomTestWrapper pom = buildPom("developers-inheritance/child-2");
1688         assertEquals(1, ((List<?>) pom.getValue("developers")).size());
1689         assertEquals("child-developer", pom.getValue("developers[1]/name"));
1690     }
1691 
1692     @Test
1693     void testContributorsAreInheritedButNotAggregated() throws Exception {
1694         PomTestWrapper pom = buildPom("contributors-inheritance/child-2");
1695         assertEquals(1, ((List<?>) pom.getValue("contributors")).size());
1696         assertEquals("child-contributor", pom.getValue("contributors[1]/name"));
1697     }
1698 
1699     @Test
1700     void testMailingListsAreInheritedButNotAggregated() throws Exception {
1701         PomTestWrapper pom = buildPom("mailing-lists-inheritance/child-2");
1702         assertEquals(1, ((List<?>) pom.getValue("mailingLists")).size());
1703         assertEquals("child-mailing-list", pom.getValue("mailingLists[1]/name"));
1704     }
1705 
1706     @Test
1707     void testPluginInheritanceOrder() throws Exception {
1708         PomTestWrapper pom = buildPom("plugin-inheritance-order/child");
1709 
1710         assertEquals("maven-it-plugin-log-file", pom.getValue("build/plugins[1]/artifactId"));
1711         assertEquals("maven-it-plugin-expression", pom.getValue("build/plugins[2]/artifactId"));
1712         assertEquals("maven-it-plugin-configuration", pom.getValue("build/plugins[3]/artifactId"));
1713 
1714         assertEquals("maven-it-plugin-log-file", pom.getValue("reporting/plugins[1]/artifactId"));
1715         assertEquals("maven-it-plugin-expression", pom.getValue("reporting/plugins[2]/artifactId"));
1716         assertEquals("maven-it-plugin-configuration", pom.getValue("reporting/plugins[3]/artifactId"));
1717     }
1718 
1719     @Test
1720     void testCliPropsDominateProjectPropsDuringInterpolation() throws Exception {
1721         Properties props = new Properties();
1722         props.setProperty("testProperty", "PASSED");
1723         PomTestWrapper pom = buildPom("interpolation-cli-wins", null, props);
1724 
1725         assertEquals("PASSED", pom.getValue("properties/interpolatedProperty"));
1726     }
1727 
1728     @Test
1729     void testParentPomPackagingMustBePom() throws Exception {
1730         assertThrows(
1731                 ProjectBuildingException.class,
1732                 () -> buildPom("parent-pom-packaging/sub"),
1733                 "Wrong packaging of parent POM was not rejected");
1734     }
1735 
1736     /** MNG-522, MNG-3018 */
1737     @Test
1738     void testManagedPluginConfigurationAppliesToImplicitPluginsIntroducedByPackaging() throws Exception {
1739         PomTestWrapper pom = buildPom("plugin-management-for-implicit-plugin/child");
1740         assertEquals(
1741                 "passed.txt",
1742                 pom.getValue("build/plugins[@artifactId='maven-resources-plugin']/configuration/pathname"));
1743         assertEquals(
1744                 "passed.txt",
1745                 pom.getValue("build/plugins[@artifactId='maven-it-plugin-log-file']/configuration/logFile"));
1746     }
1747 
1748     @Test
1749     void testDefaultPluginsExecutionContributedByPackagingExecuteBeforeUserDefinedExecutions() throws Exception {
1750         PomTestWrapper pom = buildPom("plugin-exec-order-and-default-exec");
1751         @SuppressWarnings("unchecked")
1752         List<PluginExecution> executions =
1753                 (List<PluginExecution>) pom.getValue("build/plugins[@artifactId='maven-resources-plugin']/executions");
1754         assertNotNull(executions);
1755         assertEquals(4, executions.size());
1756         assertEquals("default-resources", executions.get(0).getId());
1757         assertEquals("default-testResources", executions.get(1).getId());
1758         assertEquals("test-1", executions.get(2).getId());
1759         assertEquals("test-2", executions.get(3).getId());
1760     }
1761 
1762     @Test
1763     void testPluginDeclarationsRetainPomOrderAfterInjectionOfDefaultPlugins() throws Exception {
1764         PomTestWrapper pom = buildPom("plugin-exec-order-with-lifecycle");
1765         @SuppressWarnings("unchecked")
1766         List<Plugin> plugins = (List<Plugin>) pom.getValue("build/plugins");
1767         int resourcesPlugin = -1;
1768         int customPlugin = -1;
1769         for (int i = 0; i < plugins.size(); i++) {
1770             Plugin plugin = plugins.get(i);
1771             if ("maven-resources-plugin".equals(plugin.getArtifactId())) {
1772                 assertThat(resourcesPlugin, lessThan(0));
1773                 resourcesPlugin = i;
1774             } else if ("maven-it-plugin-log-file".equals(plugin.getArtifactId())) {
1775                 assertThat(customPlugin, lessThan(0));
1776                 customPlugin = i;
1777             }
1778         }
1779         assertEquals(customPlugin, resourcesPlugin - 1, plugins.toString());
1780     }
1781 
1782     /** MNG-4415 */
1783     @Test
1784     void testPluginOrderAfterMergingWithInheritedPlugins() throws Exception {
1785         PomTestWrapper pom = buildPom("plugin-inheritance-merge-order/sub");
1786 
1787         List<String> expected = new ArrayList<>();
1788         expected.add("maven-it-plugin-error");
1789         expected.add("maven-it-plugin-configuration");
1790         expected.add("maven-it-plugin-dependency-resolution");
1791         expected.add("maven-it-plugin-packaging");
1792         expected.add("maven-it-plugin-log-file");
1793         expected.add("maven-it-plugin-expression");
1794         expected.add("maven-it-plugin-fork");
1795         expected.add("maven-it-plugin-touch");
1796 
1797         List<String> actual = new ArrayList<>();
1798         @SuppressWarnings("unchecked")
1799         List<Plugin> plugins = (List<Plugin>) pom.getValue("build/plugins");
1800         for (Plugin plugin : plugins) {
1801             actual.add(plugin.getArtifactId());
1802         }
1803 
1804         actual.retainAll(expected);
1805 
1806         assertEquals(actual, expected);
1807     }
1808 
1809     /** MNG-4416 */
1810     @Test
1811     void testPluginOrderAfterMergingWithInjectedPlugins() throws Exception {
1812         PomTestWrapper pom = buildPom("plugin-injection-merge-order");
1813 
1814         List<String> expected = new ArrayList<>();
1815         expected.add("maven-it-plugin-error");
1816         expected.add("maven-it-plugin-configuration");
1817         expected.add("maven-it-plugin-dependency-resolution");
1818         expected.add("maven-it-plugin-packaging");
1819         expected.add("maven-it-plugin-log-file");
1820         expected.add("maven-it-plugin-expression");
1821         expected.add("maven-it-plugin-fork");
1822         expected.add("maven-it-plugin-touch");
1823 
1824         List<String> actual = new ArrayList<>();
1825         @SuppressWarnings("unchecked")
1826         List<Plugin> plugins = (List<Plugin>) pom.getValue("build/plugins");
1827         for (Plugin plugin : plugins) {
1828             actual.add(plugin.getArtifactId());
1829         }
1830 
1831         actual.retainAll(expected);
1832 
1833         assertEquals(actual, expected);
1834     }
1835 
1836     @Test
1837     void testProjectArtifactIdIsNotInheritedButMandatory() throws Exception {
1838         assertThrows(
1839                 ProjectBuildingException.class,
1840                 () -> buildPom("artifact-id-inheritance/child"),
1841                 "Missing artifactId did not cause validation error");
1842     }
1843 
1844     private void assertPathSuffixEquals(String expected, Object actual) {
1845         String a = actual.toString();
1846         a = a.substring(a.length() - expected.length()).replace('\\', '/');
1847         assertEquals(expected, a);
1848     }
1849 
1850     private void assertPathWithNormalizedFileSeparators(Object value) {
1851         assertEquals(new File(value.toString()).getPath(), value.toString());
1852     }
1853 
1854     private PomTestWrapper buildPom(String pomPath, String... profileIds) throws Exception {
1855         return buildPom(pomPath, null, null, profileIds);
1856     }
1857 
1858     private PomTestWrapper buildPom(
1859             String pomPath, Properties systemProperties, Properties userProperties, String... profileIds)
1860             throws Exception {
1861         return buildPom(pomPath, false, systemProperties, userProperties, profileIds);
1862     }
1863 
1864     private PomTestWrapper buildPom(
1865             String pomPath,
1866             boolean lenientValidation,
1867             Properties systemProperties,
1868             Properties userProperties,
1869             String... profileIds)
1870             throws Exception {
1871         File pomFile = new File(testDirectory, pomPath);
1872         if (pomFile.isDirectory()) {
1873             pomFile = new File(pomFile, "pom.xml");
1874         }
1875 
1876         ProjectBuildingRequest config = new DefaultProjectBuildingRequest();
1877 
1878         String localRepoUrl =
1879                 System.getProperty("maven.repo.local", System.getProperty("user.home") + "/.m2/repository");
1880         localRepoUrl = "file://" + localRepoUrl;
1881         config.setLocalRepository(repositorySystem.createArtifactRepository(
1882                 "local", localRepoUrl, new DefaultRepositoryLayout(), null, null));
1883         config.setActiveProfileIds(Arrays.asList(profileIds));
1884         config.setSystemProperties(systemProperties);
1885         config.setUserProperties(userProperties);
1886         config.setValidationLevel(
1887                 lenientValidation
1888                         ? ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0
1889                         : ModelBuildingRequest.VALIDATION_LEVEL_STRICT);
1890 
1891         DefaultRepositorySystemSession repoSession = MavenTestHelper.createSession(repositorySystem);
1892         LocalRepository localRepo =
1893                 new LocalRepository(config.getLocalRepository().getBasedir());
1894         repoSession.setLocalRepositoryManager(
1895                 new SimpleLocalRepositoryManagerFactory().newInstance(repoSession, localRepo));
1896         config.setRepositorySession(repoSession);
1897 
1898         return new PomTestWrapper(pomFile, projectBuilder.build(pomFile, config).getProject());
1899     }
1900 
1901     protected void assertModelEquals(PomTestWrapper pom, Object expected, String expression) {
1902         assertEquals(expected, pom.getValue(expression));
1903     }
1904 
1905     private static String createPath(List<String> elements) {
1906         StringBuilder buffer = new StringBuilder(256);
1907         for (String s : elements) {
1908             buffer.append(s).append(File.separator);
1909         }
1910         return buffer.toString().substring(0, buffer.toString().length() - 1);
1911     }
1912 }