public class SpringConfigTest extends TestCase {
public void test() throws Throwable {
XmlBeanFactory factory = new XmlBeanFactory(new FileSystemResource("src/test/resources/spring-config/config-spring-1.xml"));
FtpServer server = (FtpServer) factory.getBean("server");
server.start();
assertEquals(500, server.getConnectionConfig().getMaxLogins());
assertEquals(false, server.getConnectionConfig().isAnonymousLoginEnabled());
assertEquals(123, server.getConnectionConfig().getMaxAnonymousLogins());
assertEquals(124, server.getConnectionConfig().getMaxLoginFailures());
assertEquals(125, server.getConnectionConfig().getLoginFailureDelay());
Map<String, Listener> listeners = server.getServerContext().getListeners();
assertEquals(3, listeners.size());
Listener listener = listeners.get("listener0");
assertNotNull(listener);
assertTrue(listener instanceof NioListener);
assertEquals(2222, ((NioListener)listener).getPort());
assertEquals(true, ((NioListener)listener).getDataConnectionConfiguration().isActiveEnabled());
assertEquals(InetAddress.getByName("1.2.3.4"), ((NioListener)listener).getDataConnectionConfiguration().getActiveLocalAddress());
assertEquals("123-125", ((NioListener)listener).getDataConnectionConfiguration().getPassivePorts());
List<Subnet> subnets = ((NioListener)listener).getBlockedSubnets();
assertEquals(3, subnets.size());
assertEquals(new Subnet(InetAddress.getByName("1.2.3.0"), 16), subnets.get(0));
assertEquals(new Subnet(InetAddress.getByName("1.2.4.0"), 16), subnets.get(1));
assertEquals(new Subnet(InetAddress.getByName("1.2.3.4"), 32), subnets.get(2));
DefaultSslConfiguration ssl = (DefaultSslConfiguration) listener.getSslConfiguration();
assertEquals(new File("/tmp/tmp.jks"), ssl.getKeystoreFile());
assertEquals("password", ssl.getKeystorePassword());
// make sure the data connection got the same config
ssl = (DefaultSslConfiguration) listener.getDataConnectionConfiguration().getSslConfiguration();
assertEquals(new File("/tmp/tmp.jks"), ssl.getKeystoreFile());
assertEquals("password", ssl.getKeystorePassword());
listener = listeners.get("listener1");
assertNotNull(listener);
assertTrue(listener instanceof NioListener);
assertEquals(2223, ((NioListener)listener).getPort());
listener = listeners.get("listener2");
assertNotNull(listener);
assertTrue(listener instanceof NioListener);
assertEquals(2224, ((NioListener)listener).getPort());
DefaultCommandFactory cf = (DefaultCommandFactory) server.getServerContext().getCommandFactory();
assertEquals(1, cf.getCommandMap().size());
assertTrue(cf.getCommand("FOO") instanceof HELP);
String[] languages = server.getServerContext().getMessageResource().getAvailableLanguages();
assertEquals(3, languages.length);
assertEquals("se", languages[0]);
assertEquals("no", languages[1]);
assertEquals("da", languages[2]);