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