1   package org.apache.maven.project.imports.t01;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.project.MavenProject;
24  import org.apache.maven.project.imports.AbstractProjectImportsTestCase;
25  
26  import java.io.File;
27  import java.util.Map;
28  
29  
30  /**
31   * Verifies managed dependencies are imported into other projects correctly.
32   *
33   * @version $Id: ProjectImportsTest.java 641671 2008-03-27 01:05:26Z jdcasey $
34   */
35  public class ProjectImportsTest extends AbstractProjectImportsTestCase
36  {
37      // ----------------------------------------------------------------------
38      //
39      // p1 inherits from p0
40      // p0 inhertis from super model
41      //
42      // or we can show it graphically as:
43      //
44      // p1 ---> p0 --> super model
45      //
46      // ----------------------------------------------------------------------
47  
48      public void testDependencyManagementImportsVersions() throws Exception
49      {
50          File localRepo = getLocalRepositoryPath();
51  
52          File pom0 = new File( localRepo, "p0/pom.xml" );
53          File pom0Basedir = pom0.getParentFile();
54          System.out.println("basedir " + pom0Basedir.getAbsolutePath());
55          File pom1 = new File( pom0Basedir, "p1/pom.xml" );
56          File pom2 = new File( pom0Basedir, "p2/pom.xml" );
57          File pom3 = new File( pom0Basedir, "p3/pom.xml" );
58          File pom4 = new File( pom0Basedir, "p4/pom.xml" );
59  
60          getProjectWithDependencies( pom0 );
61          // load the child project, which inherits from p0...
62          // MavenProject project0 = getProjectWithDependencies( pom0 );
63          MavenProject project1 = getProjectWithDependencies( pom1 );
64  
65          assertEquals( pom0Basedir, project1.getParent().getBasedir() );
66  
67          Map map = project1.getArtifactMap();
68          assertNotNull("No artifacts", map);
69          assertTrue("No Artifacts", map.size() > 0);
70          assertTrue("Set size should be 2, is " + map.size(), map.size() == 2);
71  
72          Artifact a = (Artifact) map.get("maven-test:maven-test-a");
73          Artifact b = (Artifact) map.get("maven-test:maven-test-b");
74  
75          assertTrue("Incorrect version for " + a.getDependencyConflictId(), a.getVersion().equals("1.0"));
76          assertTrue("Incorrect version for " + b.getDependencyConflictId(), b.getVersion().equals("1.0"));
77  
78                  // load the child project, which inherits from p0...
79          // MavenProject project0 = getProjectWithDependencies( pom0 );
80          MavenProject project2 = getProjectWithDependencies( pom2 );
81  
82          map = project2.getArtifactMap();
83          assertNotNull("No artifacts", map);
84          assertTrue("No Artifacts", map.size() > 0);
85          assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
86  
87          a = (Artifact) map.get("maven-test:maven-test-a");
88          b = (Artifact) map.get("maven-test:maven-test-b");
89          Artifact c = (Artifact) map.get("maven-test:maven-test-c");
90  
91          assertTrue("Incorrect version for " + a.getDependencyConflictId(), a.getVersion().equals("1.0"));
92          assertTrue("Incorrect version for " + b.getDependencyConflictId(), b.getVersion().equals("1.0"));
93          assertTrue("Incorrect version for " + c.getDependencyConflictId(), c.getVersion().equals("1.0"));
94  
95          // load the child project, which inherits from p0...
96          // MavenProject project0 = getProjectWithDependencies( pom0 );
97          MavenProject project3 = getProjectWithDependencies( pom3 );
98  
99          map = project3.getArtifactMap();
100         assertNotNull("No artifacts", map);
101         assertTrue("No Artifacts", map.size() > 0);
102         assertTrue("Set size should be 3, is " + map.size(), map.size() == 3);
103 
104         a = (Artifact) map.get("maven-test:maven-test-a");
105         c = (Artifact) map.get("maven-test:maven-test-c");
106         Artifact d = (Artifact) map.get("maven-test:maven-test-d");
107 
108         assertTrue("Incorrect version for " + a.getDependencyConflictId(), a.getVersion().equals("1.1"));
109         assertTrue("Incorrect version for " + c.getDependencyConflictId(), c.getVersion().equals("1.1"));
110         assertTrue("Incorrect version for " + d.getDependencyConflictId(), d.getVersion().equals("1.0"));
111 
112         // load the child project, which inherits from p0...
113         // MavenProject project0 = getProjectWithDependencies( pom0 );
114         MavenProject project4 = getProjectWithDependencies( pom4 );
115 
116         map = project4.getArtifactMap();
117         assertNotNull("No artifacts", map);
118         assertTrue("No Artifacts", map.size() > 0);
119         assertTrue("Set size should be 4, is " + map.size(), map.size() == 4);
120 
121         a = (Artifact) map.get("maven-test:maven-test-a");
122         b = (Artifact) map.get("maven-test:maven-test-b");
123         c = (Artifact) map.get("maven-test:maven-test-c");
124         d = (Artifact) map.get("maven-test:maven-test-d");
125 
126         assertTrue("Incorrect version for " + a.getDependencyConflictId(), a.getVersion().equals("1.0"));
127         assertTrue("Incorrect version for " + b.getDependencyConflictId(), b.getVersion().equals("1.1"));
128         assertTrue("Incorrect version for " + c.getDependencyConflictId(), c.getVersion().equals("1.0"));
129         assertTrue("Incorrect version for " + d.getDependencyConflictId(), d.getVersion().equals("1.0"));
130     }
131 }