1   package org.apache.maven.project;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import java.io.File;
22  
23  import junit.framework.Test;
24  import junit.framework.TestCase;
25  import junit.framework.TestSuite;
26  
27  import org.apache.maven.MavenUtils;
28  
29  /**
30   * Test the semantics of basedir inside project.xml.
31   *
32   * @author Brett Porter <a href="mailto:brett@apache.org">brett@apache.org</a>
33   * @version $Id: BasedirTest.java 517014 2007-03-11 21:15:50Z ltheussl $
34   */
35  public class BasedirTest
36      extends TestCase
37  {
38      /**
39       * Test relative paths.
40       */
41      public void testRelativePaths()
42          throws Exception
43      {
44          String basedir = System.getProperty( "basedir" );
45          Project p = MavenUtils.getProject( new File( basedir, "src/test/basedir/extend-2/project.xml" ) );
46          assertEquals( "check group ID", p.getGroupId(), "maven" );
47          assertEquals( "check source directory", p.getBuild().getSourceDirectory(), new File( basedir, "src/java" )
48              .getCanonicalPath() );
49          assertEquals( "check unit test source directory", p.getBuild().getUnitTestSourceDirectory(),
50                        new File( basedir, "src/test" ).getCanonicalPath() );
51          assertEquals( "check iutest source directory", p.getBuild().getIntegrationUnitTestSourceDirectory(),
52                        new File( basedir, "src/test" ).getCanonicalPath() );
53          assertEquals( "check aspect source directory", p.getBuild().getAspectSourceDirectory(), new File( basedir,
54                                                                                                            "src/java" )
55              .getCanonicalPath() );
56      }
57  
58      /**
59       * Test basedir relative paths.
60       */
61      public void testRelativePathsWithBasedir()
62          throws Exception
63      {
64          String basedir = System.getProperty( "basedir" );
65          Project p = MavenUtils.getProject( new File( basedir, "src/test/basedir/extend-1/project.xml" ) );
66          assertEquals( "check group ID", p.getGroupId(), "maven" );
67          assertEquals( "check source directory", new File( p.getBuild().getSourceDirectory() ).getCanonicalPath(),
68                        new File( basedir, "src/java" ).getCanonicalPath() );
69          assertEquals( "check unit test source directory", new File( p.getBuild().getUnitTestSourceDirectory() )
70              .getCanonicalPath(), new File( basedir, "src/test" ).getCanonicalPath() );
71          assertEquals( "check iutest source directory", new File( p.getBuild().getIntegrationUnitTestSourceDirectory() )
72              .getCanonicalPath(), new File( basedir, "src/test" ).getCanonicalPath() );
73          assertEquals( "check aspect source directory", new File( p.getBuild().getAspectSourceDirectory() )
74              .getCanonicalPath(), new File( basedir, "src/java" ).getCanonicalPath() );
75      }
76  
77      /**
78       * Test relative paths (no ..).
79       */
80      public void testRelativePathsForwards()
81          throws Exception
82      {
83          String basedir = System.getProperty( "basedir" );
84          Project p = MavenUtils.getProject( new File( basedir, "src/test/basedir/project.xml" ) );
85          assertEquals( "check group ID", p.getGroupId(), "maven" );
86          assertEquals( "check source directory", p.getBuild().getSourceDirectory(),
87                        new File( basedir, "src/test/basedir/extend-1" ).getCanonicalPath() );
88          assertEquals( "check unit test source directory", p.getBuild().getUnitTestSourceDirectory(),
89                        new File( basedir, "src/test/basedir/extend-1" ).getCanonicalPath() );
90          assertEquals( "check iutest source directory", p.getBuild().getIntegrationUnitTestSourceDirectory(),
91                        new File( basedir, "src/test/basedir/extend-1" ).getCanonicalPath() );
92          assertEquals( "check aspect source directory", p.getBuild().getAspectSourceDirectory(),
93                        new File( basedir, "src/test/basedir/extend-1" ).getCanonicalPath() );
94      }
95  
96      /**
97       * Generate the test suite.
98       * @return the test suite
99       */
100     public static Test suite()
101     {
102         return new TestSuite( BasedirTest.class );
103     }
104 }