[jboss-svn-commits] JBL Code SVN: r10960 - in labs/jbossesb/trunk/product: core/listeners/src/org/jboss/soa/esb/listeners/gateway and 7 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Apr 13 02:42:27 EDT 2007


Author: beve
Date: 2007-04-13 02:42:27 -0400 (Fri, 13 Apr 2007)
New Revision: 10960

Added:
   labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/EdtFtpImplUnitTest.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/EmbeddableException.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/EmbeddedServer.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/EmbeddedFtpServer.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/FtpTestUtil.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/NoConfigFileFtpServer.java
Modified:
   labs/jbossesb/trunk/product/build.xml
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
   labs/jbossesb/trunk/product/core/listeners/tests/build.xml
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
   labs/jbossesb/trunk/product/core/rosetta/tests/build.xml
Log:
Added org.jboss.esb.jar to the list of dependencies for target test, as the services build seems to depend upon that the jar target has been run.


Modified: labs/jbossesb/trunk/product/build.xml
===================================================================
--- labs/jbossesb/trunk/product/build.xml	2007-04-13 04:02:38 UTC (rev 10959)
+++ labs/jbossesb/trunk/product/build.xml	2007-04-13 06:42:27 UTC (rev 10960)
@@ -120,7 +120,7 @@
 	</target>
 
     <!-- Test targets -->
-    <target name="org.jboss.esb.test" depends="org.jboss.esb.compile">
+    <target name="org.jboss.esb.test" depends="org.jboss.esb.compile, org.jboss.esb.jar">
         <echo message="Testing of modules, using unit and functional tests"/>
         <ant dir="core" target="org.jboss.esb.core.test"/>
     	<ant dir="services" target="test"/>

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java	2007-04-13 04:02:38 UTC (rev 10959)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -175,7 +175,8 @@
 							{
 								_logger.error("Problems with file EPR", e);							}
 						}
-						_courier = CourierFactory.getCourier(current);
+//						_courier = CourierFactory.getCourier(current);
+						_courier = getCourier(current);
                                                 try
                                                 {
                                                     if (_courier
@@ -283,17 +284,22 @@
 				{
 					thrown.printStackTrace();
 					_logger.error(text, thrown);
-					File fileError = new File(_errorDirectory, fileIn.getName()
-							+ _errorSuffix);
+					File fileError = new File(_errorDirectory, fileIn.getName() + _errorSuffix);
 					try
 					{
 						deleteFile(fileError);
+					}
+					catch (GatewayException e)
+					{
+						_logger.warn( "File : " + fileError + " did not exist.");
+					}
+					try
+					{
 						renameFile(fileWork, fileError);
 					}
 					catch (GatewayException e)
 					{
-						_logger.error("Problems renaming file " + fileWork
-								+ " to " + fileError, e);
+						_logger.error("Problems renaming file " + fileWork + " to " + fileError, e);
 					}
 				}
 			}
@@ -307,7 +313,15 @@
                 }
 	} // ________________________________
         
-        /**
+        /* 
+         * Extracted to simplify testing
+         */
+        protected Courier getCourier( EPR current ) throws CourierException, MalformedEPRException
+		{
+			return CourierFactory.getCourier(current);
+		}
+
+		/**
          * Handle the destroy of the managed instance.
          * 
          * @throws ManagedLifecycleException for errors while destroying.

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java	2007-04-13 04:02:38 UTC (rev 10959)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -188,7 +188,8 @@
 				FTPEpr ftpEpr = (FTPEpr) epr;
 				rfs = RemoteFileSystemFactory.getRemoteFileSystem(ftpEpr, true);
 				rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
-				rfs.renameInRemoteDir(from.toString(), to.toString());
+//				rfs.renameInRemoteDir(from.toString(), to.toString());
+				rfs.remoteRename( from, to );
 				return true;
 			} else {
 				throw new GatewayException("This Gateway only accepts FTP and SFTP.");

Modified: labs/jbossesb/trunk/product/core/listeners/tests/build.xml
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/build.xml	2007-04-13 04:02:38 UTC (rev 10959)
+++ labs/jbossesb/trunk/product/core/listeners/tests/build.xml	2007-04-13 06:42:27 UTC (rev 10960)
@@ -19,7 +19,9 @@
     <property name="org.jboss.esb.test.ftp.dir" value="/pub/DNS"/>
 
     <property name="org.jboss.esb.ext.lib.dir" location="${org.jboss.esb.root.dir}/lib/ext"/>
+	<property name="org.jboss.esb.ftp.lib.dir" location="${org.jboss.esb.root.dir}/ftp/lib"/>
 
+
     <condition property="org.jboss.esb.ext.lib.dir" value="${org.jboss.esb.jboss.home}/client">
         <equals arg1="${org.jboss.esb.frominstall}" arg2="yes"/>
     </condition>
@@ -28,6 +30,7 @@
     	<fileset dir="${org.jboss.esb.ext.lib.dir}"
     		excludes="*.jar" includes="jaxr-api*.jar,scout*.jar,juddi*.jar"/>
         <fileset dir="${org.jboss.esb.ext.lib.dir}" includes="*.jar"/>
+        <fileset dir="${org.jboss.esb.ftp.lib.dir}" includes="*.jar"/>
         <pathelement location="${org.jboss.esb.module.classes.root.dir}/rosetta"/>
         <pathelement location="${org.jboss.esb.module.classes.root.dir}/services"/>
     	<pathelement location="${gendir}/classes"/>

Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -0,0 +1,508 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.gateway;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import junit.framework.JUnit4TestAdapter;
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.embedded.EmbeddableException;
+import org.jboss.internal.soa.esb.util.embedded.ftp.FtpTestUtil;
+import org.jboss.internal.soa.esb.util.embedded.ftp.NoConfigFileFtpServer;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Unit test for RemoteGatewayListener that uses an embedded ftp server
+ *  
+ * @author Daniel Bevenius
+ *
+ */
+public class RemoteGatewayListenerUnitTest
+{
+	private static Logger log = Logger.getLogger( RemoteGatewayListenerUnitTest.class );
+	
+	/*  EmbeddedFtp Server  */
+	private static NoConfigFileFtpServer ftpServer;
+	
+	/* Instance of class under test */
+	private static RemoteGatewayListener gatewayListener;
+	
+	/*
+	 * ConfigTree configuration. This is a field so that test methods
+	 * can override the default settings created by createConfigTree()
+	 */
+	private static ConfigTree configTree;
+	
+	/* name of the remote ftp input directory */
+	private static String remoteInputDirName;
+	
+	/* name of the remote ftp upload directory */
+	private static String remoteUploadDirName;
+	
+	/* name of the remote ftp error directory */
+	private static String remoteErrorDirName;
+	
+	private static final String SERVICE_CATEGORY = "RemoteGWListenerTest";
+	private static final String SERVICE_NAME =  SERVICE_CATEGORY;
+	private static final String INPUT_SUFFIX = ".txt";
+	private static final String WORK_SUFFIX = ".esbwork";
+	private static final String POST_SUFFIX = ".done";
+	private static final String POST_ERROR_SUFFIX = ".error";
+	private static final String POST_DEL = "false";
+	private static final String RENAMED_SUFFIX = ".renamed";
+	
+	private static final String TEST_FILE_CONTENT = RemoteGatewayListenerUnitTest.class.getName() + " junit ftp test";
+
+	private File testFile;
+
+	private File renamedFile;
+	
+	@BeforeClass
+	public static void classSetup() throws EmbeddableException, ConfigurationException, GatewayException, RegistryException, MalformedURLException
+	{
+		ftpServer = new NoConfigFileFtpServer();
+		ftpServer.setPort( 2221 );
+		ftpServer.start();
+		
+		remoteInputDirName = "/" + ftpServer.getLocalInputDir().getName();
+		remoteUploadDirName = "/" + ftpServer.getLocalUploadDir().getName();
+		remoteErrorDirName = "/" + ftpServer.getLocalErrorDir().getName();
+		
+		configTree = createConfigTree();
+		gatewayListener = new RemoteGatewayListener( configTree );
+		
+	}
+	
+	@AfterClass
+	public static void classTearDown() 
+	{
+		try
+		{
+			ftpServer.stop();
+		}
+		catch ( Exception e )
+		{
+			log.warn ( e.getMessage() );
+		}
+		
+		if  ( !FtpTestUtil.deleteDir( ftpServer.getFtpServerDir() ) )
+		{
+			log.warn( "Could not delete " +  ftpServer.getFtpServerDir() ) ;
+		}
+	}
+	
+	@Before
+	public void setUp()
+	{
+		testFile = FtpTestUtil.createTestFile( ftpServer.getLocalInputDir(),  getClass().getName() + INPUT_SUFFIX , TEST_FILE_CONTENT );
+	}
+	
+	@After
+	public void tearDown()
+	{
+		FtpTestUtil.deleteFile( testFile );
+		FtpTestUtil.deleteFile( renamedFile );
+	}
+	
+	/**
+	 * Test with the following configuration:
+	 * inputDir="/input" 
+	 * postDir="/upload" 
+	 */
+	@Test ( timeout=3000 )
+	public void doRun_PostDir_Different_From_InputDir() throws ManagedLifecycleException, ConfigurationException, GatewayException, RegistryException, InterruptedException
+	{
+		setAbsoluteInputDir();
+		setAbsolutePostDirToUploadDir();
+		boolean getCourierReturnValue = true;
+		
+		RemoteGatewayListenerMock mock = createAndStartListener ( configTree,  getCourierReturnValue );
+		
+		File done =  ftpServer.getLocalUploadDir();
+		String doneFileName = testFile.getName() + POST_SUFFIX;
+		
+		waitForFile( done, doneFileName );
+		stopdoRun( mock );
+		
+		File processedFile = new File ( done,  doneFileName );
+		try
+		{
+			assertTrue ( processedFile.exists() );
+		}
+		finally
+		{
+			FtpTestUtil.deleteFile( processedFile );
+		}
+	}
+	
+	/**
+	 * Test with the following configuration:
+	 *	inputDir="/input" 
+	 *	postDir="/input" 
+	 */
+	@Test ( timeout=3000 )
+	public void doRun_PostDir_Same_As_InputDir() throws ManagedLifecycleException, ConfigurationException, GatewayException, RegistryException, InterruptedException
+	{
+		setAbsoluteInputDir();
+		setAbsolutePostDirToInputDir();
+		boolean getCourierReturnValue = true;
+		
+		RemoteGatewayListenerMock mock = createAndStartListener ( configTree,  getCourierReturnValue );
+		
+		File inputDir =  ftpServer.getLocalInputDir();
+		String doneFileName = testFile.getName() + POST_SUFFIX;
+		
+		waitForFile( inputDir, doneFileName );
+		stopdoRun( mock );
+		
+		File processedFile = new File ( inputDir,  doneFileName );
+		try
+		{
+			assertTrue ( processedFile.exists() );
+		}
+		finally
+		{
+			FtpTestUtil.deleteFile( processedFile );
+		}
+	}
+	
+	/**
+	 *  This test will assert that the work file is renamed into the error directory.
+	 * Test with the following configuration:
+	 *	postDir="/input" 
+	 *	errorDir="/error" 
+	 *
+	 *  Note. when this test runs a stacktrace will be displayed. This is expected.
+	 */
+	@Test ( timeout = 2000 )
+	public void doRun_Negative() throws ManagedLifecycleException, ConfigurationException, GatewayException, RegistryException, InterruptedException
+	{
+		setAbsoluteInputDir();
+		setAbsoluteErrorDir();
+		boolean getCourierReturnValue = false;
+		RemoteGatewayListenerMock mock = createAndStartListener ( configTree, getCourierReturnValue );
+		
+		File errorDir =  ftpServer.getLocalErrorDir();
+		String errorFileName = testFile.getName() + POST_ERROR_SUFFIX;
+		waitForFile( errorDir, errorFileName );
+		stopdoRun( mock );
+		
+		File errorFile = new File ( errorDir,  errorFileName );
+		try
+		{
+			assertTrue ( errorFile.exists() );
+		}
+		finally 
+		{
+			FtpTestUtil.deleteFile( errorFile );
+		}
+	}
+	
+	@Test
+	public void renameFile_In_Same_Directory() throws GatewayException
+	{
+		File from = createAbsoluteFromFile();
+		File to = createAbsoluteToFile();
+			
+		gatewayListener.renameFile( from, to );
+			
+		renamedFile = new File ( ftpServer.getLocalInputDir(), to.getName() );
+		assertFileRemoved( testFile );
+		assertFileExists( renamedFile );
+	}
+	
+	@Test
+	public void renameFile_In_Different_Directory() throws GatewayException
+	{
+		File from = createAbsoluteFromFile();
+		File to = createAbsoluteToFileUploadDir();
+			
+		gatewayListener.renameFile( from, to );
+			
+		renamedFile = new File ( ftpServer.getLocalUploadDir(), to.getName() );
+		assertFileRemoved( testFile );
+		assertFileExists( renamedFile );
+	}
+	
+	@Test
+	public void deleteFile() throws GatewayException 
+	{
+		File remoteFile = createAbsoluteFromFile();
+				
+		gatewayListener.deleteFile( remoteFile );
+		assertFalse( "Remote file was not deleted",  testFile.exists() );
+	}
+	
+	@Test
+	public void getFileListFromRemoteDir() throws GatewayException
+	{
+		File[] fileListFromRemoteDir = gatewayListener.getFileList();
+			
+		assertNotNull ( fileListFromRemoteDir );
+		assertTrue ( fileListFromRemoteDir.length > 0 );
+			
+		List<File> fileList = Arrays.asList( fileListFromRemoteDir );
+		assertTrue( "The test file was not included in the List! " , fileList.contains( new File ( testFile.getName() )  ));
+	}
+	
+	@Test
+	public void getFileContents() throws GatewayException
+	{
+		File remoteFileName = createAbsoluteFromFile();
+		byte[] fileContents = gatewayListener.getFileContents( remoteFileName );
+			
+		assertEquals( TEST_FILE_CONTENT, new String ( fileContents ) );
+		assertTrue( "The remote file should not have been removed.",  testFile.exists() );
+	}
+	
+	/*
+	 * Will create a configTree that looks like the following:
+	 *  <junitRemoteGatewayListenerTest 
+	 * 	URL="ftp://anonymous:letMeIn@localhost:2221/input"
+	 * 	errorDelete="false" 
+	 * 	errorDir="/error"
+	 * 	errorSuffix=".error" 
+	 * 	gatewayClass="org.jboss.soa.esb.listeners.gateway.RemoteGatewayListener" 
+	 * 	inputSuffix=".txt" 
+	 * 	maxThreads="1" 
+	 * 	passive="false" 
+	 * 	pollLatencySeconds="5" 
+	 * 	postDelete="false" 
+	 *		postDir="/upload" 
+	 *		postSuffix=".done" 
+	 *		service-description="Gateway for SIFO" 
+	 *		target-service-category="RemoteGWListenerTest"
+	 *		target-service-name="RemoteGWListenerTest"
+	 *		workSuffix=".esbwork"
+	 *	/> 
+	 */
+	private static ConfigTree createConfigTree()
+	{
+		ConfigTree configTree = new ConfigTree( "junitRemoteGatewayListenerTest" );
+
+		configTree.setAttribute( ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, SERVICE_CATEGORY );
+		configTree.setAttribute( ListenerTagNames.TARGET_SERVICE_NAME_TAG, SERVICE_NAME );
+
+		try
+		{
+			configTree.setAttribute( ListenerTagNames.URL_TAG, ftpServer.getURL().toString() );
+		} 
+		catch (MalformedURLException e)
+		{
+			fail ( e.getMessage() );
+		} 
+		
+		/* input attributes */
+		configTree.setAttribute( ListenerTagNames.FILE_INPUT_DIR_TAG, remoteInputDirName );
+		configTree.setAttribute( ListenerTagNames.FILE_INPUT_SFX_TAG, INPUT_SUFFIX );
+		configTree.setAttribute( ListenerTagNames.FILE_WORK_SFX_TAG, WORK_SUFFIX );
+		/* post attributes */
+		configTree.setAttribute( ListenerTagNames.FILE_POST_DIR_TAG,  remoteUploadDirName );
+		configTree.setAttribute( ListenerTagNames.FILE_POST_SFX_TAG, POST_SUFFIX);
+		configTree.setAttribute( ListenerTagNames.FILE_POST_DEL_TAG, POST_DEL);
+		/* post error attributes */
+		configTree.setAttribute( ListenerTagNames.FILE_ERROR_DIR_TAG,  remoteErrorDirName );
+		configTree.setAttribute( ListenerTagNames.FILE_ERROR_SFX_TAG, POST_ERROR_SUFFIX);
+		
+		return configTree;
+	}
+	
+	private void waitForFile( File inDir, String fileNameToWaitfor ) throws InterruptedException
+	{
+		boolean done = false;
+		while( !done )
+		{
+			for( String fileName : inDir.list() )
+			{
+				System.out.println( fileName );
+				if ( fileName.equals( fileNameToWaitfor ) )
+				{
+					done = true;
+					break;
+				}
+				else
+					Thread.sleep( 1000 );
+			}
+		}
+	}
+	
+	/**
+	 * Creates a RemoteGatewayListenerMock instance with the passed in arguments, and then starts
+	 * the RemoteGatewayListener's doRun() method in a new Thread.
+	 * 
+	 * @param configTree										The configTree to use to configure the RemoteGatewayListenerMock object
+	 * @param returnValueForCourier					the return value for the getCourier method of the RemoteGatewayListenerMock object
+	 * @return RemoteGatewayListenerMock		Mock impl of a RemoteGatewayListener.
+	 */
+	private RemoteGatewayListenerMock createAndStartListener ( ConfigTree configTree,  boolean returnValueForCourier ) throws ConfigurationException, GatewayException, RegistryException
+	{
+		final RemoteGatewayListenerMock mock = new RemoteGatewayListenerMock( configTree , returnValueForCourier );
+		mock.doInitialise();
+		
+		Thread thread = new Thread ( new Runnable ()  {
+			public void run()
+			{
+				mock.doRun();
+			}
+		});
+		thread.start();
+		
+		return mock;
+		
+	}
+	
+	private void stopdoRun ( RemoteGatewayListenerMock mock )
+	{
+		try 
+		{
+			mock.stop();
+		}
+		catch ( Exception e )
+		{
+			if ( ! (e instanceof ManagedLifecycleException ) )
+				fail ( e.getMessage() );
+		}
+	}
+	
+	private static void assertFileRemoved( File file)
+	{
+			assertFalse( "The file was not removed from the filesystem", file.exists() );
+	}
+	
+	private static void assertFileExists( File file )
+	{
+		assertTrue( "The file was not renamed to the upload directory.",  file.exists() );
+	}
+	
+	private void setAbsoluteInputDir()
+	{
+		configTree.setAttribute( ListenerTagNames.FILE_INPUT_DIR_TAG, remoteInputDirName );
+	}
+	
+	private void setAbsolutePostDirToInputDir()
+	{
+		configTree.setAttribute( ListenerTagNames.FILE_POST_DIR_TAG, remoteInputDirName );
+	}
+
+	private void setAbsolutePostDirToUploadDir()
+	{
+		configTree.setAttribute( ListenerTagNames.FILE_POST_DIR_TAG, remoteUploadDirName );
+	}
+	
+	private void setAbsoluteErrorDir()
+	{
+		configTree.setAttribute( ListenerTagNames.FILE_ERROR_DIR_TAG, remoteErrorDirName );
+	}
+	
+	private File createAbsoluteFromFile()
+	{
+		return new File ( remoteInputDirName + "/" + testFile.getName() );
+	}
+	
+	private File createAbsoluteToFile()
+	{
+		return new File ( remoteInputDirName + "/" + testFile.getName() + RENAMED_SUFFIX );
+	}
+	
+	private File createAbsoluteToFileUploadDir()
+	{
+		return new File ( remoteUploadDirName + "/" +  testFile.getName() + RENAMED_SUFFIX );
+	}
+	
+	/**
+	 * Just here to get Ant to find annotated test.
+	 */
+	public static junit.framework.Test suite()
+	{
+		return new JUnit4TestAdapter( RemoteGatewayListenerUnitTest.class);
+	}
+	
+	/**
+	 *  Mock impl of RemoteGatewayListener. 
+	 */
+	private class RemoteGatewayListenerMock extends RemoteGatewayListener
+	{
+		private static final long serialVersionUID = 1L;
+		
+		/* value that will be returned from the getCourier( EPR ) method */
+		private boolean returnValueForCourier;
+
+		/**
+		 * Sole constructor
+		 * 
+		 * @param configTree						configTree used to configure this RemoteGatewayListener
+		 * @param returnValueForCourier	value to be returned from this objects getCourier( EPR ) method
+		 * 
+		 */
+		public RemoteGatewayListenerMock ( ConfigTree configTree, boolean returnValueForCourier) throws ConfigurationException, GatewayException, RegistryException
+		{
+			super ( configTree );
+			this.returnValueForCourier = returnValueForCourier;
+		}
+		
+		/**
+		 * Will return a Courier instance that returns the value of the
+		 * field returnValueForCourier.
+		 */
+		@Override
+		protected Courier getCourier( EPR current ) throws CourierException, MalformedEPRException
+		{
+			return new Courier() {
+				public boolean deliver( Message message ) throws CourierException, MalformedEPRException
+				{
+					return returnValueForCourier;
+				}
+				public void cleanup() { }
+			};
+		}
+		
+		@Override
+		protected void doInitialise() 
+		{ 
+			_targetEprs = new ArrayList<EPR>();
+			_targetEprs.add( new JMSEpr( new EPR() ) );
+		};
+	}
+	
+}

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java	2007-04-13 04:02:38 UTC (rev 10959)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -552,6 +552,7 @@
 		try
 		{
 			m_oConn.chdir(p_sDir);
+			m_sRemoteDir = p_sDir;
 		}
 		catch (IOException ex)
 		{

Modified: labs/jbossesb/trunk/product/core/rosetta/tests/build.xml
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/build.xml	2007-04-13 04:02:38 UTC (rev 10959)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/build.xml	2007-04-13 06:42:27 UTC (rev 10960)
@@ -26,8 +26,11 @@
         <equals arg1="${org.jboss.esb.frominstall}" arg2="yes"/>
     </condition>
 
+	<property name="org.jboss.esb.ftp.lib.dir" location="${org.jboss.esb.root.dir}/ftp/lib"/>
+
     <path id="org.jboss.esb.tests.base.classpath">
         <fileset dir="${org.jboss.esb.ext.lib.dir}" includes="*.jar"/>
+        <fileset dir="${org.jboss.esb.ftp.lib.dir}" includes="*.jar"/>
     	<pathelement location="${org.jboss.esb.root.dir}/core/rosetta/tests/resources/etc"/>
         <pathelement location="${org.jboss.esb.module.classes.dir}"/>
     </path>

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/EdtFtpImplUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/EdtFtpImplUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/EdtFtpImplUnitTest.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -0,0 +1,333 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ * 
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.List;
+import junit.framework.JUnit4TestAdapter;
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.embedded.EmbeddableException;
+import org.jboss.internal.soa.esb.util.embedded.ftp.FtpTestUtil;
+import org.jboss.internal.soa.esb.util.embedded.ftp.NoConfigFileFtpServer;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.util.RemoteFileSystem;
+import org.jboss.soa.esb.util.RemoteFileSystemException;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Unit test for EdtFtpImpl that uses an embedded ftp server
+ * 
+ * @author Daniel Bevenius
+ * 
+ */
+public class EdtFtpImplUnitTest 
+{
+	private static Logger log = Logger.getLogger( EdtFtpImplUnitTest.class );
+	
+	/* EmbeddedFtp Server */
+	private static NoConfigFileFtpServer ftpServer;
+
+	/* Instance of class under test */
+	private static EdtFtpImpl edtFtpImpl;
+	
+	private static String remoteInputDirName;
+	private static String remoteUploadDirName;
+	private static final String INPUT_SUFFIX = ".txt";
+	private static final String RENAMED_SUFFIX = ".renamed";
+	
+	/* Content for created test files */
+	private static final String TEST_FILE_CONTENT = EdtFtpImplUnitTest.class .getName() + " junit ftp test";
+	private File testFile;
+	private File renamedFile;
+
+	@BeforeClass
+	public static void classSetup() throws EmbeddableException, ConfigurationException, RemoteFileSystemException, MalformedURLException, URISyntaxException
+	{
+		ftpServer = new NoConfigFileFtpServer();
+		ftpServer.setPort( 2221 );
+		ftpServer.start();
+
+		remoteInputDirName = "/" + ftpServer.getLocalInputDir().getName();
+		remoteUploadDirName = "/" + ftpServer.getLocalUploadDir().getName();
+		edtFtpImpl = new EdtFtpImpl( createConfigTree(), true );
+	}
+
+	@AfterClass
+	public static void classTearDown() throws EmbeddableException
+	{
+		try
+		{
+			ftpServer.stop();
+		} 
+		catch (Exception e)
+		{
+			log.warn( e.getMessage() );
+		}
+		
+		if  ( !FtpTestUtil.deleteDir( ftpServer.getFtpServerDir() ) )
+		{
+			log.warn( "Could not delete " +  ftpServer.getFtpServerDir() ) ;
+		}
+	}
+
+	@Before
+	public void setUp()
+	{
+		testFile = FtpTestUtil.createTestFile( ftpServer.getLocalInputDir(), getClass().getName() + INPUT_SUFFIX, TEST_FILE_CONTENT );
+	}
+	
+	@After
+	public void tearDown()
+	{
+		FtpTestUtil.deleteFile( testFile );
+		FtpTestUtil.deleteFile( renamedFile );
+	}
+	
+	@Test
+	public void construtor_FTPEpr() 
+	{
+		try
+		{
+			new EdtFtpImpl( createFTPEpr(), true );
+		}
+		catch ( Exception e )
+		{
+			fail ( e.getMessage() );
+		}
+	}
+	
+	@Test
+	public void getRemoteDir() throws RemoteFileSystemException
+	{
+		String oldRemoteDir =  remoteInputDirName;
+		try
+		{
+			edtFtpImpl.setRemoteDir( remoteUploadDirName );
+			assertEquals( "The remote dir was not changed.", remoteUploadDirName, edtFtpImpl.getRemoteDir() );
+		} 
+		finally
+		{
+			try { edtFtpImpl.setRemoteDir( oldRemoteDir ); } catch (Exception e) { fail( e.getMessage() ); }
+		}
+	}
+
+	@Test
+	public void setRemoteDir() throws RemoteFileSystemException
+	{
+		String oldRemoteDir = remoteInputDirName;
+		try
+		{
+			edtFtpImpl.setRemoteDir( remoteUploadDirName );
+
+			String actualRemoteDir = edtFtpImpl.getRemoteDir();
+			assertFalse( "The setRemoteDir method did not change the directory!", oldRemoteDir.equals( actualRemoteDir ) );
+		} 
+		finally
+		{
+			try { edtFtpImpl.setRemoteDir( oldRemoteDir ); } catch (Exception e) { fail( e.getMessage() ); }
+		}
+	}
+
+	@Test
+	public void getFileListFromRemoteDir() throws RemoteFileSystemException, IOException
+	{
+		String[] fileListFromRemoteDir = edtFtpImpl .getFileListFromRemoteDir( INPUT_SUFFIX );
+		assertNotNull( fileListFromRemoteDir );
+		List<String> fileList = Arrays.asList( fileListFromRemoteDir );
+		assertTrue( "The test file was not included in the List! ", fileList.contains( testFile.getName() ) );
+	}
+
+	@Test
+	public void deleteRemoteFile() throws RemoteFileSystemException
+	{
+		edtFtpImpl.deleteRemoteFile( testFile.getName() );
+		assertFalse( "File was not deleted", testFile.exists() );
+	}
+
+	@Test
+	public void remoteDelete() throws RemoteFileSystemException
+	{
+		edtFtpImpl.remoteDelete( testFile );
+		assertFalse( testFile.exists() );
+	}
+
+	@Test
+	public void renameInRemoteDir() throws RemoteFileSystemException
+	{
+		File from = testFile;
+		String toFileName = from.getName() + RENAMED_SUFFIX;
+			
+		edtFtpImpl.renameInRemoteDir( from.getName(), toFileName );
+
+		renamedFile = new File( ftpServer.getLocalInputDir(), toFileName );
+		assertFalse( "The file was not removed from the filesystem", from .exists() );
+		assertTrue( "The named file does not exist", renamedFile.exists() );
+	}
+
+	@Test
+	public void remoteRename_To_Different_RemoteDir() throws RemoteFileSystemException
+	{
+		File from = createAbsoluteFromFile();
+		File to = createAbsoluteToFileUploadDir();
+
+		edtFtpImpl.remoteRename( from, to );
+
+		renamedFile = new File( ftpServer.getLocalUploadDir(), to.getName() );
+		assertFalse( "The file was not removed from the filesystem", from .exists() );
+		assertTrue( renamedFile + " was not found in dir " + ftpServer.getLocalUploadDir(), renamedFile.exists() );
+	}
+	
+	@Test
+	public void remoteRename_To_Same_RemoteDir() throws RemoteFileSystemException
+	{
+		File from =  createAbsoluteFromFile();
+		File to = createAbsoluteToFile();
+			
+		edtFtpImpl.remoteRename( from, to );
+
+		renamedFile = new File( ftpServer.getLocalInputDir(), testFile.getName() + RENAMED_SUFFIX );
+		assertFalse( testFile.exists() );
+		assertTrue( renamedFile.exists() );
+	}
+	
+	@Test
+	public void downloadFile() throws RemoteFileSystemException, IOException
+	{
+		File localFile = null;
+		File localDownloadedlFile = null;
+		String testFileName = "downloadFileTestFile.txt";
+		try
+		{
+			localFile = FtpTestUtil.createTestFile( ftpServer .getLocalInputDir(), testFileName, TEST_FILE_CONTENT );
+			String remoteFileName = "/input/" + localFile.getName();
+			String downloadFileName = testFileName + ".downloaded";
+
+			edtFtpImpl.downloadFile( remoteFileName, downloadFileName );
+
+			localDownloadedlFile = new File( ftpServer.getRootDir(), downloadFileName );
+			assertTrue( "The remote file should not have been removed.", localFile.exists() );
+			assertTrue( "File was not downloaded ", localDownloadedlFile .exists() );
+		} 
+		finally
+		{
+			FtpTestUtil.deleteFile( localDownloadedlFile );
+			FtpTestUtil.deleteFile( localFile );
+		}
+	}
+
+	@Test
+	public void uploadFile() throws RemoteFileSystemException
+	{
+			File localFile = null;
+			File remoteFile = null;
+			String testFileName = "uploadFileTestFile.txt";
+			try
+			{
+				localFile = FtpTestUtil.createTestFile(  ftpServer.getLocalInputDir(),  testFileName, TEST_FILE_CONTENT );
+				
+				String renameTo = testFileName + RENAMED_SUFFIX;
+				edtFtpImpl.uploadFile( localFile, renameTo );
+				remoteFile = new File ( ftpServer.getLocalInputDir(), renameTo );
+				
+				assertTrue( "The file was not uploaded succesfully." , remoteFile.exists() );
+			} 
+			finally
+			{
+				FtpTestUtil.deleteFile( remoteFile );
+				FtpTestUtil.deleteFile( localFile );
+			}
+	}
+
+	private static ConfigTree createConfigTree()
+	{
+		ConfigTree configTree = new ConfigTree( "junitEdtFtpImplTest" );
+		try
+		{
+			configTree.setAttribute( FileEpr.URL_TAG, ftpServer.getURL().toString() ) ;
+		}
+		catch ( MalformedURLException e )
+		{
+			log.error(  e  );
+			fail ( e.getMessage() );
+		}
+		configTree.setAttribute( RemoteFileSystem.PARMS_FTP_SERVER, ftpServer .getHost() );
+		configTree.setAttribute( RemoteFileSystem.PARMS_USER, ftpServer .getUserName() );
+		configTree.setAttribute( RemoteFileSystem.PARMS_PASSWD, ftpServer .getPassword() );
+		configTree.setAttribute( RemoteFileSystem.PARMS_REMOTE_DIR, remoteInputDirName );
+		configTree.setAttribute( RemoteFileSystem.PARMS_PORT, Integer .toString( ftpServer.getPort() ) );
+		configTree.setAttribute( RemoteFileSystem.PARMS_LOCAL_DIR, ftpServer .getRootDir() );
+		configTree.setAttribute( RemoteFileSystem.PARMS_ASCII, Boolean .toString( false ) );
+		configTree.setAttribute( RemoteFileSystem.PARMS_PASSIVE, Boolean .toString( false ) );
+		return configTree;
+	}
+	
+	private static FTPEpr createFTPEpr() throws MalformedURLException, URISyntaxException
+	{
+		FTPEpr epr = new FTPEpr ( new EPR() );
+		epr.setURL( ftpServer.getURL() );
+		epr.setUserName( ftpServer.getUserName() );
+		epr.setErrorDirectory( ftpServer.getErrorDirName() );
+		epr.setInputSuffix( INPUT_SUFFIX );
+		epr.setPassword( ftpServer.getPassword() );
+		epr.setPostDirectory( ftpServer.getUploadDirName() );
+		epr.setWorkSuffix( ".work" );
+		return epr;
+	}
+	
+	private File createAbsoluteFromFile()
+	{
+		return new File ( remoteInputDirName + "/" + testFile.getName() );
+	}
+	
+	private File createAbsoluteToFile()
+	{
+		return new File ( remoteInputDirName + "/" + testFile.getName() + RENAMED_SUFFIX );
+	}
+	
+	private File createAbsoluteToFileUploadDir()
+	{
+		return new File ( remoteUploadDirName + "/" +  testFile.getName() + RENAMED_SUFFIX );
+	}
+
+	public static junit.framework.Test suite()
+	{
+		return new JUnit4TestAdapter( EdtFtpImplUnitTest.class);
+	}
+	
+}

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/EmbeddableException.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/EmbeddableException.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/EmbeddableException.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ * 
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.util.embedded;
+
+/**
+ * 
+ * @author Daniel Bevenius
+ *
+ */
+public class EmbeddableException extends Exception
+{
+
+	public EmbeddableException()
+	{
+		super();
+	}
+
+	public EmbeddableException(String message, Throwable cause)
+	{
+		super( message, cause );
+	}
+
+	public EmbeddableException(String message)
+	{
+		super( message );
+	}
+
+	public EmbeddableException(Throwable cause)
+	{
+		super( cause );
+	}
+	
+
+}

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/EmbeddedServer.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/EmbeddedServer.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/EmbeddedServer.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ * 
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.util.embedded;
+
+/**
+ * Simply interface for different types of embedded servers
+ * 
+ * @author Daniel Bevenius
+ *
+ */
+public interface EmbeddedServer
+{
+	void start() throws EmbeddableException;
+	
+	void stop() throws EmbeddableException;
+
+}

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/EmbeddedFtpServer.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/EmbeddedFtpServer.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/EmbeddedFtpServer.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ * 
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.util.embedded.ftp;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.ftpserver.ConfigurableFtpServerContext;
+import org.apache.ftpserver.FtpServer;
+import org.apache.ftpserver.config.PropertiesConfiguration;
+import org.apache.ftpserver.ftplet.Configuration;
+import org.apache.ftpserver.interfaces.FtpServerContext;
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.embedded.EmbeddableException;
+import org.jboss.internal.soa.esb.util.embedded.EmbeddedServer;
+
+/**
+ * Class that can be used to test ftp functionality.
+ * 
+ * @author Daniel Bevenius
+ *
+ */
+public class EmbeddedFtpServer implements EmbeddedServer
+{
+	private static Logger log = Logger.getLogger(EmbeddedFtpServer.class);
+	
+	private Properties ftpProperties;
+	
+	private FtpServer server;
+	
+	public EmbeddedFtpServer()
+	{
+	}
+
+	/**
+	 * 
+	 * @param configFile	path to the ftpserver properties file used
+	 * 						to configure the ftpserver.
+	 */
+	public EmbeddedFtpServer( String configFile)
+	{
+		if (configFile == null)
+			throw new IllegalArgumentException("configFile must not be null");
+		
+		try
+		{
+			ftpProperties = getConfiguration( configFile ) ;
+		} 
+		catch (IOException e)
+		{
+			log.error( e );
+			throw new IllegalStateException ( "Could not configure the ftp server");
+		}
+	}
+	
+	public EmbeddedFtpServer( Properties ftpProperties )
+	{
+		this.ftpProperties = ftpProperties;
+	}
+	
+	
+	public void addProperties( Properties ftpProperties)
+	{
+		if ( this.ftpProperties == null )
+			this.ftpProperties = ftpProperties;
+		else
+			this.ftpProperties.putAll( ftpProperties );
+	}
+	
+	public void start() throws EmbeddableException 
+	{
+		try 
+		{
+			Configuration configuration = new PropertiesConfiguration( ftpProperties );
+			FtpServerContext context = new ConfigurableFtpServerContext( configuration );
+			server = new FtpServer( context );
+			server.start();
+		} 
+		catch (IOException e) 
+		{
+			log.error( e );
+			throw new EmbeddableException( e );
+		} 
+		catch (Exception e) 
+		{
+			log.error( e );
+			throw new EmbeddableException( e );
+		}
+	}
+	
+	public void stop() throws EmbeddableException  
+	{ 
+		server.stop();
+	}
+	
+	private static Properties getConfiguration( String configFile ) throws IOException
+	{
+		FileInputStream in = null;
+		try 
+		{
+			in = new FileInputStream( configFile );
+			Properties props = new Properties();
+			props.load( in );
+			return props;
+		} 
+		finally
+		{
+			if ( in != null )
+				in.close();
+		}
+	}
+
+}

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/FtpTestUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/FtpTestUtil.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/FtpTestUtil.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ * 
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.util.embedded.ftp;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Scanner;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Util methods created for embedded FTP server test
+ * 
+ * @author Daniel Bevenius
+ *
+ */
+public class FtpTestUtil
+{
+	private static Logger log = Logger.getLogger( FtpTestUtil.class );
+	
+	private FtpTestUtil() { }
+	
+	/**
+	 * Can be used to test the embedded ftp server 
+	 * with a local client.  Useful for debugging when you need to know
+	 * what a specific command does on the ftp server ( like CWD )
+	 * 
+	 * Add a call to this method in youre test method
+	 * and you can start a local ftp client that connects to the
+	 * embedded ftp server. 
+	 *
+	 */
+	public static  void promptForQuit()
+	{
+		System.out.println( "Enter q to quit:" );
+		Scanner scanner = new Scanner( System.in );
+		scanner.hasNext( "q" );
+	}
+	
+	public static boolean deleteFile( File file )
+	{
+		if ( file != null && file.exists() )
+		{
+			return file.delete();
+		}
+		return true; 
+	}
+	
+	public static boolean deleteDir( File dir )
+	{
+		if ( dir.isDirectory() ) 
+		{
+            String[] filesInDir = dir.list();
+            for ( String fileName : filesInDir )
+            {
+                if ( ! ( deleteDir( new File( dir, fileName ) ) ) ) 
+                    return false;
+            }
+		}
+		return dir.delete();
+	}
+	
+	public static File createTestFile( final File dir, final String fileName, final String fileContents )
+	{
+		return createTestFile( dir.getAbsolutePath() + File.separator + fileName, fileContents );
+	}
+
+	public static File createTestFile( final String fileName, String fileContents)
+	{
+		File testFile = new File ( fileName );
+		FileWriter writer = null;
+		try
+		{
+			testFile.createNewFile();
+			writer = new FileWriter( testFile );
+			writer.write( fileContents );
+		} 
+		catch (IOException e)
+		{
+			log.error ( e.getMessage() );
+		} 
+		finally
+		{
+			close( writer );
+		}
+		return testFile;
+	}
+	
+	public static void close( Closeable c )
+	{
+		if (c != null)
+		{
+			try
+			{
+				c.close();
+			} catch (IOException e)
+			{
+				/* ignore */
+			}
+		}
+	}
+
+}

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/NoConfigFileFtpServer.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/NoConfigFileFtpServer.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/util/embedded/ftp/NoConfigFileFtpServer.java	2007-04-13 06:42:27 UTC (rev 10960)
@@ -0,0 +1,333 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ * 
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.util.embedded.ftp;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.apache.ftpserver.ftplet.Authority;
+import org.apache.ftpserver.ftplet.FtpException;
+import org.apache.ftpserver.listener.io.IOListener;
+import org.apache.ftpserver.usermanager.BaseUser;
+import org.apache.ftpserver.usermanager.PropertiesUserManager;
+import org.apache.ftpserver.usermanager.WritePermission;
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.util.embedded.EmbeddableException;
+
+/**
+ * This class extends EmbeddedFtpServer and can be used without
+ * having a configuration file for the ftp server.
+ * 
+ * By default this class will create and perform operations on the following directories:
+ *	/tmp/ftpserver/home/
+ *									input/
+ *									upload/
+ *									error/
+ *
+ *
+ *	The default host is localhost and the default port is 21.
+ *	But this can be changed by calling any of the setters before calling start.
+ *	
+ *	Usage:
+ *	NoConfigFileFtpServer ftpServer = new NoConfigFileFtpServer();
+ *	ftpServer.setPort( 2221 ) ;
+ *	ftpServer.start();
+ * ...
+ * ftpServer.stop();
+ * 
+ * @author Daniel Bevenius
+ *
+ */
+public class NoConfigFileFtpServer extends EmbeddedFtpServer
+{
+	private Logger log = Logger.getLogger( NoConfigFileFtpServer.class );
+	
+	/* root dir for ftp server */
+	private String rootDir = System.getProperty( "java.io.tmpdir" );
+	
+	/* name of the server directory. This will be created directly below the rootDir */
+	private String serverDirName = "ftpserver";
+	private File ftpServerDir;
+	
+	/* name of the user home dir. This will be created directly below the ftpServerDir */
+	private String homeDirName = "home";
+	private File ftpHomeDir;
+	
+	/* File that point to the local input directory.  */
+	private String inputDirName = "input";
+	private String remoteInputDir = "/input";
+	private File localInputDir;
+	
+	/* File that point to the local upload directory.  */
+	private String uploadDirName = "upload";
+	private File localUploadDir;
+	
+	/* File that point to the local error directory.  */
+	private String errorDirName = "error";
+	private File localErrorDir;
+	
+	/* this file is created by the FTP server. Will be named rootDir/ftpServerDir/user.properties */
+	private String userPropertiesFileName = "user.properties";
+	private File ftpUserPropertiesFile;
+	
+	/* ftp connection settings */
+	private String host = "localhost";
+	private int port = 21;
+	private String userName = "anonymous";
+	private String password = "letMeIn";
+	
+	public void start() throws EmbeddableException
+	{
+		createDirs();
+		addProperties( getDefaultProperties() );
+		createUsers();
+		super.start();
+	}
+
+	protected void createUsers()
+	{
+		try
+		{
+			PropertiesUserManager propertiesUserManager = new PropertiesUserManager();
+			propertiesUserManager.setPropFile(  ftpUserPropertiesFile );
+			BaseUser ftpUser = new BaseUser();
+			ftpUser.setName( userName );
+			ftpUser.setPassword( password );
+			ftpUser.setHomeDirectory( ftpHomeDir.getAbsolutePath() );
+			Authority[] auths = { new WritePermission() };
+			ftpUser.setAuthorities( auths );
+	        ftpUser.setEnabled(  true );
+	        propertiesUserManager.configure();
+			propertiesUserManager.save( ftpUser );
+			
+			BaseUser adminUser = new BaseUser();
+			adminUser.setName( "admin" );
+			adminUser.setHomeDirectory( ftpHomeDir.getAbsolutePath() );
+			propertiesUserManager.save( adminUser );
+		} 
+		catch (FtpException e)
+		{
+			log.error( e );
+		}
+	}
+
+	protected Properties getDefaultProperties()
+	{
+		Properties properties = new Properties();
+        properties.setProperty("config.listeners.default.port", Integer.toString( port ) );
+        properties.setProperty("config.listeners.default.class", IOListener.class.getName() );
+        properties.setProperty("config.connection-manager.anonymous-login-enabled", "true");
+        properties.setProperty("config.user-manager.prop-file", ftpUserPropertiesFile.getAbsolutePath() );
+		return properties;
+	}
+
+	protected void createDirs()
+	{
+			ftpServerDir = new File ( rootDir + File.separator + serverDirName );
+			if ( ftpServerDir.exists() )
+				ftpServerDir.delete();
+			
+			ftpServerDir.mkdirs();
+	        ftpUserPropertiesFile = new File ( ftpServerDir.getAbsolutePath() + File.separator + userPropertiesFileName);
+			
+			ftpHomeDir = new File(  ftpServerDir, homeDirName );
+			ftpHomeDir.mkdirs();
+			
+			localInputDir = new File( ftpHomeDir,  inputDirName );
+			localInputDir.mkdir();
+			
+			localUploadDir = new File( ftpHomeDir,  uploadDirName);
+			localUploadDir.mkdir();
+			
+			localErrorDir = new File( ftpHomeDir,  errorDirName);
+			localErrorDir.mkdir();
+	}
+
+	public  File getFtpServerDir()
+	{
+		return ftpServerDir;
+	}
+
+	public  void setFtpServerDir( File ftpServerDir )
+	{
+		this.ftpServerDir = ftpServerDir;
+	}
+
+	public  File getFtpHomeDir()
+	{
+		return ftpHomeDir;
+	}
+
+	public void setFtpHomeDir( File ftpHomeDir )
+	{
+		this.ftpHomeDir = ftpHomeDir;
+	}
+
+	public  File getFtpPropertiesFile()
+	{
+		return ftpUserPropertiesFile;
+	}
+
+	public void setFtpPropertiesFile( File ftpPropertiesFile )
+	{
+		this.ftpUserPropertiesFile = ftpPropertiesFile;
+	}
+
+	public int getPort()
+	{
+		return port;
+	}
+
+	public void setPort( int port )
+	{
+		this.port = port;
+	}
+
+	public File getLocalInputDir()
+	{
+		return localInputDir;
+	}
+
+	public void setLocalInputDir( File localInputDir )
+	{
+		this.localInputDir = localInputDir;
+	}
+
+	public File getLocalUploadDir()
+	{
+		return localUploadDir;
+	}
+
+	public void setLocalUploadDir( File localUploadDir )
+	{
+		this.localUploadDir = localUploadDir;
+	}
+
+	public String getHost()
+	{
+		return host;
+	}
+
+	public void setHost( String host )
+	{
+		this.host = host;
+	}
+
+	public String getRootDir()
+	{
+		return rootDir;
+	}
+
+	public void setRootDir( String rootDir )
+	{
+		this.rootDir = rootDir;
+	}
+
+	public String getUserName()
+	{
+		return userName;
+	}
+
+	public void setUserName( String userName )
+	{
+		this.userName = userName;
+	}
+
+	public String getPassword()
+	{
+		return password;
+	}
+
+	public void setPassword( String password )
+	{
+		this.password = password;
+	}
+
+	public URL getURL() throws MalformedURLException
+	{
+//		return new URL ( "ftp://" + userName + ":" + password + "@" + host + ":" + port + "/" + localInputDir.getName() );
+		return new URL ( "ftp://" + userName + ":" + password + "@" + host + ":" + port + "/" + remoteInputDir );
+	}
+
+	public String getServerDirName()
+	{
+		return serverDirName;
+	}
+
+	public void setServerDirName( String serverDirName )
+	{
+		this.serverDirName = serverDirName;
+	}
+
+	public String getHomeDirName()
+	{
+		return homeDirName;
+	}
+
+	public void setHomeDirName( String homeDirName )
+	{
+		this.homeDirName = homeDirName;
+	}
+
+	public String getInputDirName()
+	{
+		return inputDirName;
+	}
+
+	public void setInputDirName( String inputDirName )
+	{
+		this.inputDirName = inputDirName;
+	}
+
+	public String getUploadDirName()
+	{
+		return uploadDirName;
+	}
+
+	public void setUploadDirName( String uploadDirName )
+	{
+		this.uploadDirName = uploadDirName;
+	}
+
+	public String getErrorDirName()
+	{
+		return errorDirName;
+	}
+
+	public void setErrorDirName( String errorDirName )
+	{
+		this.errorDirName = errorDirName;
+	}
+
+	public File getLocalErrorDir()
+	{
+		return localErrorDir;
+	}
+
+	public void setLocalErrorDir( File localErrorDir )
+	{
+		this.localErrorDir = localErrorDir;
+	}
+		
+}




More information about the jboss-svn-commits mailing list