Search in sources :

Example 1 with FtpResponseListener

use of com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener in project ats-framework by Axway.

the class Test_FTPClient method testGatherResponses.

@Test
public void testGatherResponses() throws Exception {
    expectNew(org.apache.commons.net.ftp.FTPClient.class).andReturn(mockFtp);
    mockFtp.setConnectTimeout(DEFAULT_TIMEOUT);
    mockFtp.connect(HOSTNAME, PORT_NUMBER);
    expect(mockFtp.login(USERNAME, PASSWORD)).andReturn(true);
    mockFtp.enterLocalPassiveMode();
    expect(mockFtp.setFileType(org.apache.commons.net.ftp.FTPClient.BINARY_FILE_TYPE)).andReturn(true);
    FtpResponseListener listener = new FtpResponseListener();
    expectNew(FtpResponseListener.class).andReturn(listener);
    mockFtp.addProtocolCommandListener(listener);
    mockFtp.removeProtocolCommandListener(listener);
    replayAll();
    testObject.connect(HOSTNAME, USERNAME, PASSWORD);
    testObject.enableResponseCollection(true);
    testObject.enableResponseCollection(false);
    verifyAll();
}
Also used : FtpResponseListener(com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener) BaseTest(com.axway.ats.core.BaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with FtpResponseListener

use of com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener in project ats-framework by Axway.

the class Test_FTPClient method testGetResponses.

@Test
public void testGetResponses() throws Exception {
    FtpResponseListener listener = new FtpResponseListener();
    List<String> initializeResponses = new ArrayList<String>();
    initializeResponses.add("1");
    listener.setResponses(initializeResponses);
    expectNew(org.apache.commons.net.ftp.FTPClient.class).andReturn(mockFtp);
    mockFtp.setConnectTimeout(DEFAULT_TIMEOUT);
    mockFtp.connect(HOSTNAME, PORT_NUMBER);
    expect(mockFtp.login(USERNAME, PASSWORD)).andReturn(true);
    mockFtp.enterLocalPassiveMode();
    expect(mockFtp.setFileType(org.apache.commons.net.ftp.FTPClient.BINARY_FILE_TYPE)).andReturn(true);
    expectNew(FtpResponseListener.class).andReturn(listener);
    mockFtp.addProtocolCommandListener(listener);
    replayAll();
    testObject.connect(HOSTNAME, USERNAME, PASSWORD);
    testObject.enableResponseCollection(true);
    String[] responses = testObject.getResponses();
    Assert.assertEquals(initializeResponses.size(), responses.length);
    Assert.assertEquals(initializeResponses.get(0), responses[0]);
    verifyAll();
}
Also used : FtpResponseListener(com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener) ArrayList(java.util.ArrayList) BaseTest(com.axway.ats.core.BaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with FtpResponseListener

use of com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener in project ats-framework by Axway.

the class Test_FTPSClient method testGetResponses.

@Test(expected = AssertionError.class)
public void testGetResponses() throws Exception {
    FtpResponseListener listener = new FtpResponseListener();
    List<String> initializeResponses = new ArrayList<String>();
    initializeResponses.add("1");
    listener.setResponses(initializeResponses);
    expectNew(org.apache.commons.net.ftp.FTPSClient.class).andReturn(mockFtp);
    mockFtp.setConnectTimeout(DEFAULT_TIMEOUT);
    mockFtp.connect(HOSTNAME, PORT_NUMBER);
    expect(mockFtp.login(USERNAME, PASSWORD)).andReturn(true);
    mockFtp.enterLocalPassiveMode();
    expect(mockFtp.setFileType(org.apache.commons.net.ftp.FTPSClient.BINARY_FILE_TYPE)).andReturn(true);
    expectNew(FtpResponseListener.class).andReturn(listener);
    mockFtp.addProtocolCommandListener(listener);
    replayAll();
    testObject.connect(HOSTNAME, USERNAME, PASSWORD);
    testObject.enableResponseCollection(true);
    String[] responses = testObject.getResponses();
    Assert.assertEquals(initializeResponses.size(), responses.length);
    Assert.assertEquals(initializeResponses.get(0), responses[0]);
    verifyAll();
}
Also used : FtpResponseListener(com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener) ArrayList(java.util.ArrayList) BaseTest(com.axway.ats.core.BaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with FtpResponseListener

use of com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener in project ats-framework by Axway.

the class FtpsClient method performConnect.

private void performConnect(String hostname, String userName, String password, String keystoreFile, String keystorePassword) throws FileTransferException {
    // make new FTP object for every new connection
    disconnect();
    applyCustomProperties();
    //this.ftpsConnection = new FTPSClient( this.protocol, this.implicit);
    this.ftpsConnection = new org.apache.commons.net.ftp.FTPSClient(this.implicit, SslUtils.getSSLContext(keystoreFile, keystorePassword, this.protocol));
    if (this.listener != null) {
        this.listener.setResponses(new ArrayList<String>());
        this.ftpsConnection.addProtocolCommandListener(((FtpResponseListener) listener));
    }
    /* if debug mode is true, we log messages from all levels */
    if (isDebugMode()) {
        this.ftpsConnection.addProtocolCommandListener(new FtpListener());
    }
    try {
        this.ftpsConnection.setConnectTimeout(this.timeout);
        // connect to the host
        this.ftpsConnection.connect(hostname, this.port);
        // login to the host
        if (!this.ftpsConnection.login(userName, password)) {
            throw new Exception("Invallid username and/or password");
        }
        // set transfer mode
        if (this.transferMode == TransferMode.ASCII) {
            if (!this.ftpsConnection.setFileType(org.apache.commons.net.ftp.FTPSClient.ASCII_FILE_TYPE)) {
                throw new Exception("Unable to set transfer mode to ASCII");
            }
        } else {
            if (!this.ftpsConnection.setFileType(org.apache.commons.net.ftp.FTPSClient.BINARY_FILE_TYPE)) {
                throw new Exception("Unable to set transfer mode to BINARY");
            }
        }
    } catch (Exception e) {
        String errMessage = "Unable to connect to  " + hostname + " on port " + this.port + " using username " + userName + " and password " + password;
        log.error(errMessage, e);
        throw new FileTransferException(e);
    }
}
Also used : FtpListener(com.axway.ats.core.filetransfer.model.ftp.FtpListener) FileTransferException(com.axway.ats.common.filetransfer.FileTransferException) FtpResponseListener(com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener) IOException(java.io.IOException) FileTransferException(com.axway.ats.common.filetransfer.FileTransferException)

Example 5 with FtpResponseListener

use of com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener in project ats-framework by Axway.

the class Test_FTPSClient method testGatherResponses.

@Test(expected = AssertionError.class)
public void testGatherResponses() throws Exception {
    expectNew(org.apache.commons.net.ftp.FTPSClient.class).andReturn(mockFtp);
    mockFtp.setConnectTimeout(DEFAULT_TIMEOUT);
    mockFtp.connect(HOSTNAME, PORT_NUMBER);
    expect(mockFtp.login(USERNAME, PASSWORD)).andReturn(true);
    mockFtp.enterLocalPassiveMode();
    expect(mockFtp.setFileType(org.apache.commons.net.ftp.FTPSClient.BINARY_FILE_TYPE)).andReturn(true);
    FtpResponseListener listener = new FtpResponseListener();
    expectNew(FtpResponseListener.class).andReturn(listener);
    mockFtp.addProtocolCommandListener(listener);
    mockFtp.removeProtocolCommandListener(listener);
    replayAll();
    testObject.connect(HOSTNAME, USERNAME, PASSWORD);
    testObject.enableResponseCollection(true);
    testObject.enableResponseCollection(false);
    verifyAll();
}
Also used : FtpResponseListener(com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener) BaseTest(com.axway.ats.core.BaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FtpResponseListener (com.axway.ats.core.filetransfer.model.ftp.FtpResponseListener)6 BaseTest (com.axway.ats.core.BaseTest)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 FileTransferException (com.axway.ats.common.filetransfer.FileTransferException)2 FtpListener (com.axway.ats.core.filetransfer.model.ftp.FtpListener)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2