View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.sftp;
8   
9   import org.mule.tck.junit4.AbstractMuleTestCase;
10  
11  import org.junit.Test;
12  
13  import static org.junit.Assert.assertEquals;
14  
15  /**
16   * JUnit test for SftpClient
17   * 
18   * @author Lennart H��ggkvist
19   */
20  public class SftpClientTestCase extends AbstractMuleTestCase
21  {
22  
23      @Test
24      public void testGetAbsolutePath()
25      {
26          SftpClient client = new SftpClient("hostName");
27          client.setHome("/home/user");
28  
29          // Assuming address="sftp://user@host/PATH" and thus the path always start
30          // with "/"
31          assertEquals("hostName", client.getHost());
32  
33          // Relative paths
34          assertEquals("/home/user/foo", client.getAbsolutePath("/~/foo"));
35          assertEquals("/home/user/foo/bar", client.getAbsolutePath("/~/foo/bar"));
36  
37          // Two calls to getAbsolutePath should return the same
38          assertEquals("/home/user/foo/bar", client.getAbsolutePath(client.getAbsolutePath("/~/foo/bar")));
39  
40          // Absolute path
41          assertEquals("/opt/mule/files", client.getAbsolutePath("/opt/mule/files"));
42  
43          // If the path did not contain any '/' we should not assume it is an relative
44          // path
45          assertEquals("foo", client.getAbsolutePath("foo"));
46      }
47  }