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.inheritance.t06;
20  
21  import java.io.File;
22  import java.util.Iterator;
23  import java.util.Set;
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   * A test which demonstrates maven's dependency management
36   *
37   */
38  @Deprecated
39  class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase {
40      // ----------------------------------------------------------------------
41      //
42      // p1 inherits from p0
43      // p0 inherits from super model
44      //
45      // or we can show it graphically as:
46      //
47      // p1 ---> p0 --> super model
48      //
49      // ----------------------------------------------------------------------
50  
51      @Test
52      void testDependencyManagement() throws Exception {
53          File localRepo = getLocalRepositoryPath();
54          File pom0 = new File(localRepo, "p0/pom.xml");
55  
56          File pom0Basedir = pom0.getParentFile();
57  
58          File pom1 = new File(pom0Basedir, "p1/pom.xml");
59  
60          // load everything...
61          MavenProject project0 = getProjectWithDependencies(pom0);
62          MavenProject project1 = getProjectWithDependencies(pom1);
63  
64          assertEquals(pom0Basedir, project1.getParent().getBasedir());
65          Set set = project1.getArtifacts();
66          assertNotNull(set, "No artifacts");
67          assertTrue(set.size() > 0, "No Artifacts");
68          Iterator iter = set.iterator();
69          assertTrue(set.size() == 4, "Set size should be 4, is " + set.size());
70  
71          while (iter.hasNext()) {
72              Artifact artifact = (Artifact) iter.next();
73              System.out.println("Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion()
74                      + " Optional=" + (artifact.isOptional() ? "true" : "false"));
75              assertTrue(
76                      artifact.getVersion().equals("1.0"), "Incorrect version for " + artifact.getDependencyConflictId());
77          }
78      }
79  }