1 package org.apache.maven.project.inheritance.t10;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Map;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.project.MavenProject;
27 import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
28 import org.junit.jupiter.api.Test;
29
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31 import static org.junit.jupiter.api.Assertions.assertNotNull;
32 import static org.junit.jupiter.api.Assertions.assertTrue;
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class ProjectInheritanceTest
47 extends AbstractProjectInheritanceTestCase
48 {
49
50
51
52
53
54
55
56
57
58
59
60 @Test
61 public void testDependencyManagementOverridesTransitiveDependencyVersion()
62 throws Exception
63 {
64 File localRepo = getLocalRepositoryPath();
65
66 File pom0 = new File( localRepo, "p0/pom.xml" );
67 File pom0Basedir = pom0.getParentFile();
68 File pom1 = new File( pom0Basedir, "p1/pom.xml" );
69
70
71 MavenProject project0 = getProjectWithDependencies( pom0 );
72 MavenProject project1 = getProjectWithDependencies( pom1 );
73
74 assertEquals( pom0Basedir, project1.getParent().getBasedir() );
75 System.out.println("Project " + project1.getId() + " " + project1);
76 Map map = project1.getArtifactMap();
77 assertNotNull( map, "No artifacts" );
78 assertTrue( map.size() > 0, "No Artifacts" );
79 assertTrue( map.size() == 3, "Set size should be 3, is " + map.size() );
80
81 Artifact a = (Artifact) map.get("maven-test:t10-a");
82 Artifact b = (Artifact) map.get("maven-test:t10-b");
83 Artifact c = (Artifact) map.get("maven-test:t10-c");
84
85 assertNotNull( a );
86 assertNotNull( b );
87 assertNotNull( c );
88
89
90 System.out.println(a.getScope());
91 assertTrue( a.getScope().equals("test"), "Incorrect scope for " + a.getDependencyConflictId() );
92
93
94 assertTrue( b.getScope().equals("runtime"), "Incorrect scope for " + b.getDependencyConflictId() );
95
96
97 assertTrue( c.getScope().equals("runtime"), "Incorrect scope for " + c.getDependencyConflictId() );
98
99 }
100 }