View Javadoc

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