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