1 package org.apache.maven.jelly.tags.maven;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }