package org.apache.maven.artifact;

/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import junit.framework.TestCase;
import org.apache.maven.project.Project;
import org.apache.maven.model.Model;
import org.apache.maven.model.Dependency;
import org.apache.maven.MavenException;
import org.apache.maven.MavenUtils;
import org.apache.maven.MavenConstants;

import java.io.File;
import java.io.FileReader;

/**
 * Test the POM rewriter.
 *
 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 * @version $Id$
 */
public class PomRewriterTest
    extends TestCase
{
    protected void setUp()
        throws Exception
    {
        if ( System.getProperty( MavenConstants.MAVEN_HOME ) == null )
        {
            System.setProperty( MavenConstants.MAVEN_HOME, "target/maven-home" );
        }
    }

    public void testPropertiesRewriting()
        throws Exception
    {
        String resourceName = "pom-with-properties.xml";

        Model model = PomRewriter.getRewrittenModel( new File( System.getProperty( "basedir"), "src/test/resources/" + resourceName ), null );

        Dependency dep = (Dependency) model.getDependencies().get( 0 );
        assertEquals( "check property war.bundle", "true", dep.getProperty( "war.bundle" ) );
        assertEquals( "check num properties", 1, dep.getProperties().size() );

        dep = (Dependency) model.getDependencies().get( 1 );
        assertEquals( "check property gump.project", "jakarta-taglibs-standard", dep.getProperty( "gump.project" ) );
        assertEquals( "check property gump.id", "jstl", dep.getProperty( "gump.id" ) );
        assertEquals( "check num properties", 2, dep.getProperties().size() );
    }

}
