Search in sources :

Example 1 with CommonsNetFtpClient

use of com.adaptris.ftp.CommonsNetFtpClient in project interlok by adaptris.

the class TestCommonsNetFtp method testSetTimeout.

@Test
public void testSetTimeout() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("testSetTimeout");
        CommonsNetFtpClient client = new CommonsNetFtpClient(config.getProperty(FTP_HOST));
        client.setTimeout(client.getTimeout());
        client.setKeepAliveTimeout(client.getKeepAliveTimeout());
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : CommonsNetFtpClient(com.adaptris.ftp.CommonsNetFtpClient) Test(org.junit.Test)

Example 2 with CommonsNetFtpClient

use of com.adaptris.ftp.CommonsNetFtpClient in project interlok by adaptris.

the class TestCommonsNetFtp method testBug1924.

@Test
public void testBug1924() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("testBug1924");
        // Use an arbitarily small timeout to a range that almost certainly
        // shouldn't exist when the tests are running.
        CommonsNetFtpClient client = new CommonsNetFtpClient("192.168.17.1", 21, 1);
        client.disconnect();
        fail("Successfully connected, with a timeout of 1ms (surely not possible!)");
    } catch (SocketTimeoutException e) {
        // expected.
        ;
    } catch (NoRouteToHostException e) {
        // also possibly expected
        ;
    } catch (IOException e) {
        // also possibly expected from FtpCommonsNetClient
        ;
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) CommonsNetFtpClient(com.adaptris.ftp.CommonsNetFtpClient) NoRouteToHostException(java.net.NoRouteToHostException) Test(org.junit.Test)

Example 3 with CommonsNetFtpClient

use of com.adaptris.ftp.CommonsNetFtpClient in project interlok by adaptris.

the class TestCommonsNetFtp method testConnectWithTimeout.

@Test
public void testConnectWithTimeout() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("testBug1924");
        // Use an arbitarily small timeout.
        CommonsNetFtpClient client = new CommonsNetFtpClient("192.168.17.1", 21, 1);
        client.setAdditionalDebug(true);
        client.connect(config.getProperty(FTP_USERNAME), config.getProperty(FTP_PASSWORD));
        client.disconnect();
        fail("Successfully connected, with a timeout of 1ms (surely not possible!)");
    } catch (SocketTimeoutException e) {
        // expected.
        ;
    } catch (NoRouteToHostException e) {
        // also possibly expected
        ;
    } catch (IOException e) {
        // also possibly expected from FtpCommonsNetClient
        ;
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) CommonsNetFtpClient(com.adaptris.ftp.CommonsNetFtpClient) NoRouteToHostException(java.net.NoRouteToHostException) Test(org.junit.Test)

Example 4 with CommonsNetFtpClient

use of com.adaptris.ftp.CommonsNetFtpClient in project interlok by adaptris.

the class TestCommonsNetFtp method testGetLastModifiedWithTimezone.

@Test
public void testGetLastModifiedWithTimezone() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("testGetLastModifiedWithTimezone");
        FileTransferClient client = connectClientImpl();
        client.chdir(getRemoteGetDirectory());
        long mtime = client.lastModified(getRemoteGetFilename());
        client.disconnect();
        CommonsNetFtpClient tzClient = (CommonsNetFtpClient) connectClientImpl();
        tzClient.setServerTimezone(TimeZone.getTimeZone(ALTERNATE_TZ));
        tzClient.chdir(getRemoteGetDirectory());
        long tztime = tzClient.lastModified(getRemoteGetFilename());
        tzClient.disconnect();
        logR.debug("testGetLastModifiedWithTimezone : " + new Date(tztime));
        assertNotSame("" + new Date(mtime), mtime, tztime);
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient) CommonsNetFtpClient(com.adaptris.ftp.CommonsNetFtpClient) Date(java.util.Date) Test(org.junit.Test)

Example 5 with CommonsNetFtpClient

use of com.adaptris.ftp.CommonsNetFtpClient in project interlok by adaptris.

the class TestCommonsNetFtp method testGetLastModifiedDateWithTimezone.

@Test
public void testGetLastModifiedDateWithTimezone() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("testGetLastModifiedDateWithTimezone");
        FileTransferClient client = connectClientImpl();
        client.chdir(getRemoteGetDirectory());
        Date mtime = client.lastModifiedDate(getRemoteGetFilename());
        client.disconnect();
        CommonsNetFtpClient tzClient = (CommonsNetFtpClient) connectClientImpl();
        tzClient.setServerTimezone(TimeZone.getTimeZone(ALTERNATE_TZ));
        tzClient.chdir(getRemoteGetDirectory());
        Date tzDate = tzClient.lastModifiedDate(getRemoteGetFilename());
        tzClient.disconnect();
        logR.debug("testGetLastModifiedWithTimezone : " + tzDate);
        assertNotSame("" + mtime, mtime, tzDate);
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient) CommonsNetFtpClient(com.adaptris.ftp.CommonsNetFtpClient) Date(java.util.Date) Test(org.junit.Test)

Aggregations

CommonsNetFtpClient (com.adaptris.ftp.CommonsNetFtpClient)6 Test (org.junit.Test)5 FileTransferClient (com.adaptris.filetransfer.FileTransferClient)2 IOException (java.io.IOException)2 NoRouteToHostException (java.net.NoRouteToHostException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Date (java.util.Date)2