Search in sources :

Example 1 with TestUserManager

use of org.springframework.integration.samples.ftp.support.TestUserManager in project spring-integration-samples by spring-projects.

the class TestSuite method setupFtpServer.

@BeforeClass
public static void setupFtpServer() throws FtpException, IOException {
    Integer availableServerSocket;
    if (System.getProperty(SERVER_PORT_SYSTEM_PROPERTY) == null) {
        availableServerSocket = 0;
    } else {
        availableServerSocket = Integer.valueOf(System.getProperty(SERVER_PORT_SYSTEM_PROPERTY));
    }
    File ftpRoot = new File(FTP_ROOT_DIR);
    ftpRoot.mkdirs();
    TestUserManager userManager = new TestUserManager(ftpRoot.getAbsolutePath());
    FtpServerFactory serverFactory = new FtpServerFactory();
    serverFactory.setUserManager(userManager);
    ListenerFactory factory = new ListenerFactory();
    factory.setPort(availableServerSocket);
    factory.setIdleTimeout(600);
    serverFactory.addListener("default", factory.createListener());
    server = serverFactory.createServer();
    server.start();
    Listener listener = serverFactory.getListeners().values().iterator().next();
    availableServerSocket = listener.getPort();
    LOGGER.info("Using open server port..." + availableServerSocket);
    System.setProperty(SERVER_PORT_SYSTEM_PROPERTY, availableServerSocket.toString());
}
Also used : Listener(org.apache.ftpserver.listener.Listener) FtpServerFactory(org.apache.ftpserver.FtpServerFactory) File(java.io.File) TestUserManager(org.springframework.integration.samples.ftp.support.TestUserManager) ListenerFactory(org.apache.ftpserver.listener.ListenerFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

File (java.io.File)1 FtpServerFactory (org.apache.ftpserver.FtpServerFactory)1 Listener (org.apache.ftpserver.listener.Listener)1 ListenerFactory (org.apache.ftpserver.listener.ListenerFactory)1 BeforeClass (org.junit.BeforeClass)1 TestUserManager (org.springframework.integration.samples.ftp.support.TestUserManager)1