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