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();
}
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();
}
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();
}
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);
}
}
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();
}
Aggregations