diff --git a/basic/ftp/pom.xml b/basic/ftp/pom.xml
index 1d8dff9f..4f8afa63 100644
--- a/basic/ftp/pom.xml
+++ b/basic/ftp/pom.xml
@@ -23,6 +23,12 @@
spring-integration-ftp
${spring.integration.version}
+
+ org.springframework.integration
+ spring-integration-test
+ ${spring.integration.version}
+ test
+
commons-io
diff --git a/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/TestSuite.java b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/TestSuite.java
index 1e64842f..5f6e0f7f 100644
--- a/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/TestSuite.java
+++ b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/TestSuite.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.listener.ListenerFactory;
+import org.apache.log4j.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@@ -31,6 +32,7 @@ import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.springframework.integration.samples.ftp.support.TestUserManager;
+import org.springframework.integration.test.util.SocketUtils;
/**
* Test Suite that will bootstrap an embedded Apache FTP Server. Additionally some
@@ -48,8 +50,11 @@ import org.springframework.integration.samples.ftp.support.TestUserManager;
})
public class TestSuite {
+ private static final Logger LOGGER = Logger.getLogger(TestSuite.class);
+
public static final String FTP_ROOT_DIR = "target" + File.separator + "ftproot";
public static final String LOCAL_FTP_TEMP_DIR = "target" + File.separator + "local-ftp-temp";
+ public static final String SERVER_PORT_SYSTEM_PROPERTY = "availableServerPort";
@ClassRule
public static final TemporaryFolder temporaryFolder = new TemporaryFolder();
@@ -59,6 +64,17 @@ public class TestSuite {
@BeforeClass
public static void setupFtpServer() throws FtpException, SocketException, IOException {
+ final int availableServerSocket;
+
+ if (System.getProperty(SERVER_PORT_SYSTEM_PROPERTY) == null) {
+ availableServerSocket = SocketUtils.findAvailableServerSocket(4444);
+ System.setProperty(SERVER_PORT_SYSTEM_PROPERTY, Integer.valueOf(availableServerSocket).toString());
+ } else {
+ availableServerSocket = Integer.valueOf(System.getProperty(SERVER_PORT_SYSTEM_PROPERTY));
+ }
+
+ LOGGER.info("Using open server port..." + availableServerSocket);
+
File ftpRoot = new File (FTP_ROOT_DIR);
ftpRoot.mkdirs();
@@ -68,7 +84,7 @@ public class TestSuite {
serverFactory.setUserManager(userManager);
ListenerFactory factory = new ListenerFactory();
- factory.setPort(3333);
+ factory.setPort(availableServerSocket);
serverFactory.addListener("default", factory.createListener());
diff --git a/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/support/TestUserManager.java b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/support/TestUserManager.java
index 16ef6737..884f88ab 100644
--- a/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/support/TestUserManager.java
+++ b/basic/ftp/src/test/java/org/springframework/integration/samples/ftp/support/TestUserManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,73 +31,73 @@ import org.apache.ftpserver.usermanager.impl.ConcurrentLoginPermission;
import org.apache.ftpserver.usermanager.impl.WritePermission;
/**
- *
+ *
* @author Gunnar Hillert
*
*/
public class TestUserManager extends AbstractUserManager {
- private BaseUser testUser;
- private BaseUser anonUser;
+ private BaseUser testUser;
+ private BaseUser anonUser;
- private static final String TEST_USERNAME = "demo";
- private static final String TEST_PASSWORD = "demo";
+ private static final String TEST_USERNAME = "demo";
+ private static final String TEST_PASSWORD = "demo";
public TestUserManager(String homeDirectory) {
- super("admin", new ClearTextPasswordEncryptor());
+ super("admin", new ClearTextPasswordEncryptor());
- testUser = new BaseUser();
- testUser.setAuthorities(Arrays.asList(new Authority[] {new ConcurrentLoginPermission(1, 1), new WritePermission()}));
- testUser.setEnabled(true);
- testUser.setHomeDirectory(homeDirectory);
- testUser.setMaxIdleTime(10000);
- testUser.setName(TEST_USERNAME);
- testUser.setPassword(TEST_PASSWORD);
+ testUser = new BaseUser();
+ testUser.setAuthorities(Arrays.asList(new Authority[] {new ConcurrentLoginPermission(1, 1), new WritePermission()}));
+ testUser.setEnabled(true);
+ testUser.setHomeDirectory(homeDirectory);
+ testUser.setMaxIdleTime(10000);
+ testUser.setName(TEST_USERNAME);
+ testUser.setPassword(TEST_PASSWORD);
- anonUser = new BaseUser(testUser);
- anonUser.setName("anonymous");
- }
+ anonUser = new BaseUser(testUser);
+ anonUser.setName("anonymous");
+ }
- public User getUserByName(String username) throws FtpException {
- if(TEST_USERNAME.equals(username)) {
- return testUser;
- } else if(anonUser.getName().equals(username)) {
- return anonUser;
- }
+ public User getUserByName(String username) throws FtpException {
+ if(TEST_USERNAME.equals(username)) {
+ return testUser;
+ } else if(anonUser.getName().equals(username)) {
+ return anonUser;
+ }
- return null;
- }
+ return null;
+ }
- public String[] getAllUserNames() throws FtpException {
- return new String[] {TEST_USERNAME, anonUser.getName()};
- }
+ public String[] getAllUserNames() throws FtpException {
+ return new String[] {TEST_USERNAME, anonUser.getName()};
+ }
- public void delete(String username) throws FtpException {
- throw new UnsupportedOperationException("Deleting of FTP Users is not supported.");
- }
+ public void delete(String username) throws FtpException {
+ throw new UnsupportedOperationException("Deleting of FTP Users is not supported.");
+ }
- public void save(User user) throws FtpException {
- throw new UnsupportedOperationException("Saving of FTP Users is not supported.");
- }
+ public void save(User user) throws FtpException {
+ throw new UnsupportedOperationException("Saving of FTP Users is not supported.");
+ }
- public boolean doesExist(String username) throws FtpException {
- return (TEST_USERNAME.equals(username) || anonUser.getName().equals(username)) ? true : false;
- }
+ public boolean doesExist(String username) throws FtpException {
+ return (TEST_USERNAME.equals(username) || anonUser.getName().equals(username)) ? true : false;
+ }
- public User authenticate(Authentication authentication) throws AuthenticationFailedException {
- if(UsernamePasswordAuthentication.class.isAssignableFrom(authentication.getClass())) {
- UsernamePasswordAuthentication upAuth = (UsernamePasswordAuthentication) authentication;
+ public User authenticate(Authentication authentication) throws AuthenticationFailedException {
+ if(UsernamePasswordAuthentication.class.isAssignableFrom(authentication.getClass())) {
+ UsernamePasswordAuthentication upAuth = (UsernamePasswordAuthentication) authentication;
- if(TEST_USERNAME.equals(upAuth.getUsername()) && TEST_PASSWORD.equals(upAuth.getPassword())) {
- return testUser;
- }
+ if(TEST_USERNAME.equals(upAuth.getUsername()) && TEST_PASSWORD.equals(upAuth.getPassword())) {
+ return testUser;
+ }
- if(anonUser.getName().equals(upAuth.getUsername())) {
- return anonUser;
- }
- } else if(AnonymousAuthentication.class.isAssignableFrom(authentication.getClass())) {
- return anonUser;
- }
+ if(anonUser.getName().equals(upAuth.getUsername())) {
+ return anonUser;
+ }
+ } else if(AnonymousAuthentication.class.isAssignableFrom(authentication.getClass())) {
+ return anonUser;
+ }
- return null;
- }
-}
\ No newline at end of file
+ return null;
+ }
+}
diff --git a/basic/ftp/src/test/resources/META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml
index a9ea0081..a94a3cbd 100644
--- a/basic/ftp/src/test/resources/META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml
+++ b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml
@@ -10,25 +10,25 @@
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd">
-
+
-
+
-
+
-
+
diff --git a/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml
index d84e591a..f5b98b16 100644
--- a/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml
+++ b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml
@@ -13,16 +13,16 @@
-
+
-
+
-
+
diff --git a/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml
index 35d714b8..0c43a090 100644
--- a/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml
+++ b/basic/ftp/src/test/resources/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml
@@ -17,7 +17,7 @@
-
+
diff --git a/basic/ftp/src/test/resources/user.properties b/basic/ftp/src/test/resources/user.properties
index c1502a1f..faccbeb7 100644
--- a/basic/ftp/src/test/resources/user.properties
+++ b/basic/ftp/src/test/resources/user.properties
@@ -1,4 +1,4 @@
userid=demo
password=demo
-port=3333
+availableServerPort=3333
host=localhost
\ No newline at end of file