001package org.apache.maven.project.inheritance.t07;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023import java.util.Iterator;
024import java.util.Set;
025
026import org.apache.maven.artifact.Artifact;
027import org.apache.maven.project.MavenProject;
028import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
029
030/**
031 * A test which demonstrates maven's dependency management
032 *
033 * @author Jason van Zyl
034 */
035public class ProjectInheritanceTest
036    extends AbstractProjectInheritanceTestCase
037{
038    // ----------------------------------------------------------------------
039    //
040    // p1 inherits from p0
041    // p0 inhertis from super model
042    //
043    // or we can show it graphically as:
044    //
045    // p1 ---> p0 --> super model
046    //
047    // ----------------------------------------------------------------------
048
049    public void testDependencyManagement()
050        throws Exception
051    {
052        File localRepo = getLocalRepositoryPath();
053        File pom0 = new File( localRepo, "p0/pom.xml" );
054
055        File pom0Basedir = pom0.getParentFile();
056
057        File pom1 = new File( pom0Basedir, "p1/pom.xml" );
058
059        // load everything...
060        MavenProject project1 = getProjectWithDependencies( pom1 );
061
062        assertEquals( pom0Basedir, project1.getParent().getBasedir() );
063        System.out.println("Project " + project1.getId() + " " + project1);
064        Set set = project1.getArtifacts();
065        assertNotNull("No artifacts", set);
066        assertTrue("No Artifacts", set.size() > 0);
067        assertTrue("Set size should be 3, is " + set.size(), set.size() == 3 );
068
069        for ( Object aSet : set )
070        {
071            Artifact artifact = (Artifact) aSet;
072            assertFalse( "", artifact.getArtifactId().equals( "t07-d" ) );
073            System.out.println(
074                "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + (
075                    artifact.isOptional()
076                        ? "true"
077                        : "false" ) );
078            assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(),
079                        artifact.getVersion().equals( "1.0" ) );
080        }
081    }
082}