/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java

https://github.com/sonatype/maven-demo · Java · 95 lines · 36 code · 14 blank · 45 comment · 1 complexity · 96d99b298062d1518917e8f19592e182 MD5 · raw file

  1. package org.apache.maven.project.inheritance.t10;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import java.io.File;
  21. import java.util.Map;
  22. import org.apache.maven.artifact.Artifact;
  23. import org.apache.maven.project.MavenProject;
  24. import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
  25. /**
  26. * Verifies scope inheritence of direct and transitive dependencies.
  27. *
  28. * Should show three behaviors:
  29. *
  30. * 1. dependencyManagement should override the scope of transitive dependencies.
  31. * 2. Direct dependencies should override the scope of dependencyManagement.
  32. * 3. Direct dependencies should inherit scope from dependencyManagement when
  33. * they do not explicitly state a scope.
  34. *
  35. * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a>
  36. * @version $Id: ProjectInheritanceTest.java 948687 2010-05-27 06:37:07Z bentmann $
  37. */
  38. public class ProjectInheritanceTest
  39. extends AbstractProjectInheritanceTestCase
  40. {
  41. // ----------------------------------------------------------------------
  42. //
  43. // p1 inherits from p0
  44. // p0 inhertis from super model
  45. //
  46. // or we can show it graphically as:
  47. //
  48. // p1 ---> p0 --> super model
  49. //
  50. // ----------------------------------------------------------------------
  51. public void testDependencyManagementOverridesTransitiveDependencyVersion()
  52. throws Exception
  53. {
  54. File localRepo = getLocalRepositoryPath();
  55. File pom0 = new File( localRepo, "p0/pom.xml" );
  56. File pom0Basedir = pom0.getParentFile();
  57. File pom1 = new File( pom0Basedir, "p1/pom.xml" );
  58. // load the child project, which inherits from p0...
  59. MavenProject project0 = getProjectWithDependencies( pom0 );
  60. MavenProject project1 = getProjectWithDependencies( pom1 );
  61. assertEquals( pom0Basedir, project1.getParent().getBasedir() );
  62. System.out.println("Project " + project1.getId() + " " + project1);
  63. Map map = project1.getArtifactMap();
  64. assertNotNull("No artifacts", map);
  65. assertTrue("No Artifacts", map.size() > 0);
  66. assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
  67. Artifact a = (Artifact) map.get("maven-test:t10-a");
  68. Artifact b = (Artifact) map.get("maven-test:t10-b");
  69. Artifact c = (Artifact) map.get("maven-test:t10-c");
  70. assertNotNull( a );
  71. assertNotNull( b );
  72. assertNotNull( c );
  73. // inherited from depMgmt
  74. System.out.println(a.getScope());
  75. assertTrue("Incorrect scope for " + a.getDependencyConflictId(), a.getScope().equals("test"));
  76. // transitive dep, overridden b depMgmt
  77. assertTrue("Incorrect scope for " + b.getDependencyConflictId(), b.getScope().equals("runtime"));
  78. // direct dep, overrides depMgmt
  79. assertTrue("Incorrect scope for " + c.getDependencyConflictId(), c.getScope().equals("runtime"));
  80. }
  81. }