use of com.axway.ats.core.filetransfer.model.IFileTransferClient in project ats-framework by Axway.
the class Test_GenericTransferClient method testConnectUsingCustomClient.
@Test(expected = AssertionError.class)
public void testConnectUsingCustomClient() throws Exception {
String customFileTransferClientName = "SomeCustomClientClass";
mockStatic(FileTransferConfigurator.class);
FileTransferConfigurator mockFileTransferConfigurator = createMock(FileTransferConfigurator.class);
expect(FileTransferConfigurator.getInstance()).andReturn(mockFileTransferConfigurator);
expect(mockFileTransferConfigurator.getFileTransferClient(TransferProtocol.HTTP_CUSTOM)).andReturn(customFileTransferClientName);
IFileTransferClient basicClient = createMock(IFileTransferClient.class);
mockStatic(ClientFactory.class);
expect(ClientFactory.getInstance()).andReturn(factoryMock);
expect(factoryMock.getClient(TransferProtocol.HTTP_CUSTOM, TransferProtocol.HTTP_CUSTOM.getDefaultPort(), customFileTransferClientName)).andReturn(basicClient);
basicClient.connect(SAMPLE_HOST_NAME, SAMPLE_USER_NAME, SAMPLE_PASSWORD);
replayAll();
mockedTestObject = new FileTransferClient(TransferProtocol.HTTP_CUSTOM);
mockedTestObject.connect(SAMPLE_HOST_NAME, SAMPLE_USER_NAME, SAMPLE_PASSWORD);
verifyAll();
}
use of com.axway.ats.core.filetransfer.model.IFileTransferClient in project ats-framework by Axway.
the class ClientFactory method loadCustomClient.
/**
* Instantiates the custom file transfer client
*
* @param customFileTransferClient the class name of the custom client
* @return
* @throws FileTransferException
*/
private IFileTransferClient loadCustomClient(String customFileTransferClient) throws FileTransferException {
try {
// load the custom client class
Class<?> customFileTransferClientClass = this.getClass().getClassLoader().loadClass(customFileTransferClient);
// make an instance of the custom client
IFileTransferClient client = (IFileTransferClient) customFileTransferClientClass.newInstance();
log.info("Loaded custom file transfer client: " + customFileTransferClient);
return client;
} catch (ClassNotFoundException e) {
throw new FileTransferException("Custom file transfer client not found in the classpath: " + customFileTransferClient);
} catch (ClassCastException e) {
throw new FileTransferException("Wrong type of the custom file transfer client: " + customFileTransferClient);
} catch (InstantiationException e) {
throw new FileTransferException("Unable to create an instance of the custom file transfer client: " + customFileTransferClient);
} catch (IllegalAccessException e) {
throw new FileTransferException("Unable to create an instance of the custom file transfer client: " + customFileTransferClient);
}
}
use of com.axway.ats.core.filetransfer.model.IFileTransferClient in project ats-framework by Axway.
the class ClientFactory method getClient.
/**
* Returns a product specific {@link IFileTransferClient} that handles transfers via the specified {@link TransferProtocol}.
*
* @param protocol the {@link TransferProtocol} to use
* @param port a custom port to use when connecting
* @param customFileTransferClient the class name of the custom client
* @return the {@link IFileTransferClient} that handles transfers via the specified {@link TransferProtocol}
* @throws FileTransferException
* @see {@link TransferProtocol}
*/
public IFileTransferClient getClient(TransferProtocol protocol, int port, String customFileTransferClient) throws FileTransferException {
switch(protocol) {
case FTP:
return new FtpClient(port);
case FTPS:
return new FtpsClient(port);
case SFTP:
return new SftpClient(port);
case HTTP:
return new HttpClient(port);
case HTTPS:
return new HttpsClient(port);
case HTTP_CUSTOM:
case HTTPS_CUSTOM:
case PESIT_CUSTOM:
case CUSTOM:
// load the custom client
IFileTransferClient client = loadCustomClient(customFileTransferClient);
client.setCustomPort(port);
return client;
default:
throw new FileTransferException("No implementation for the " + protocol + " protocol is currently available");
}
}
Aggregations