1   package org.apache.maven.jelly.tags.maven;
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  import java.io.IOException;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * Tests for {@link RootRelativePathTag}.
28   * 
29   * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
30   * @version $Id: RootRelativePathTagTest.java 517014 2007-03-11 21:15:50Z ltheussl $
31   */
32  public class RootRelativePathTagTest
33      extends TestCase
34  {
35      /**
36       * The tag to test
37       */
38      private RootRelativePathTag tag;
39  
40      /**
41       * @see TestCase#setUp()
42       */
43      protected void setUp()
44      {
45          tag = new RootRelativePathTag();
46      }
47  
48      public void testComputePathOk()
49          throws Exception
50      {
51          tag.setPath( "c:/apps/myproject/path/subproject2" );
52          tag.setRootdir( new File( "c:/apps/myproject" ) );
53          String result = tag.computePath();
54          assertEquals( "./../..", result );
55      }
56  
57      public void testComputePathWithEndingSeparator()
58          throws Exception
59      {
60          tag.setPath( "c:/apps/myproject/path/subproject2" );
61          tag.setRootdir( new File( "c:/apps/myproject/" ) );
62          String result = tag.computePath();
63          assertEquals( "./../..", result );
64      }
65  
66      public void testComputePathOk2()
67          throws Exception
68      {
69          tag.setPath( "c:/apps/myproject" );
70          tag.setRootdir( new File( "c:/apps/myproject" ) );
71          String result = tag.computePath();
72          assertEquals( ".", result );
73      }
74  
75      public void testComputePathOk3()
76          throws Exception
77      {
78          tag.setPath( "c:\\apps\\myproject\\path\\subproject2" );
79          tag.setRootdir( new File( "c:\\apps\\myproject" ) );
80          String result = tag.computePath();
81          assertEquals( "./../..", result );
82      }
83  
84      public void testComputePathWhenPathNotSubsetRootdir()
85          throws Exception
86      {
87          tag.setPath( "c:/apps/myproject/path/subproject2" );
88          tag.setRootdir( new File( "c:/somethingelse" ) );
89  
90          try
91          {
92              tag.computePath();
93              fail( "should have thrown an exception" );
94          }
95          catch ( IOException expected )
96          {
97              assertTrue( true );
98          }
99      }
100 }