[jboss-svn-commits] JBL Code SVN: r8448 - in labs/jbossesb/trunk: product/core/listeners/src/org/jboss/soa/esb/listeners/gateway product/core/rosetta/src/org/jboss/internal/soa/esb/util product/core/rosetta/src/org/jboss/soa/esb/util product/core/rosetta/tests qa qa/junit qa/junit/src/org/jboss/soa/esb/listeners/gateway

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 20 12:17:47 EST 2006


Author: kevin.conner at jboss.com
Date: 2006-12-20 12:17:36 -0500 (Wed, 20 Dec 2006)
New Revision: 8448

Added:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListenerIntegrationTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpEsbListenerConfig.xml
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpGatewayConfig.xml
Removed:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListener.java
Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
   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/SecureFtpImpl.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystem.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java
   labs/jbossesb/trunk/product/core/rosetta/tests/build.xml
   labs/jbossesb/trunk/qa/build.xml
   labs/jbossesb/trunk/qa/junit/build.xml
Log:
Added FTP gateway integration 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	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java	2006-12-20 17:17:36 UTC (rev 8448)
@@ -185,7 +185,6 @@
         			else
         				try
         				{
-        					deleteFile(fileOK);
         					renameFile(fileWork,fileOK);
         				}
         				catch(GatewayException e)

Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListener.java	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListener.java	2006-12-20 17:17:36 UTC (rev 8448)
@@ -1,167 +0,0 @@
-/*
- * 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.soa.esb.listeners.gateway;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.util.FtpClientUtil;
-import org.jboss.soa.esb.util.RemoteFileSystem;
-import org.jboss.soa.esb.util.RemoteFileSystemFactory;
-import org.jboss.soa.esb.util.Util;
-
-public class FtpGatewayListener extends FileGatewayListener
-{
-	protected FtpGatewayListener()
-	{
-	}
-
-	public FtpGatewayListener(GatewayListenerController commandListener,
-			ConfigTree config) throws Exception
-	{
-		super(commandListener, config);
-	}
-
-	protected void checkMyParms() throws Exception
-	{
-		super.checkMyParms();
-		RemoteFileSystem rfs = RemoteFileSystemFactory.getRemoteFileSystem(
-				_config, true);
-		rfs.quit();
-
-		// Copy FTP parameters to be passed to the action class (inside the
-		// WorkingFile class)
-		// This is a kludge - we have to get back to this (ES)
-		// Maybe we could get these out of the FTPEpr? (GEO)
-		String[] sa = new String[]
-		{ RemoteFileSystem.PARMS_FTP_SERVER, RemoteFileSystem.PARMS_USER,
-				RemoteFileSystem.PARMS_PASSWD, RemoteFileSystem.PARMS_PASSIVE,
-				RemoteFileSystem.PARMS_PORT };
-		for (String sProp : sa)
-		{
-			String sVal = _config.getAttribute(sProp);
-			if (!Util.isNullString(sVal))
-				_ftpArguments.put(sProp, sVal);
-		}
-	}
-
-	@Override
-	protected void seeIfOkToWorkOnDir(File p_oDir) throws GatewayException
-	{
-		// TODO: Implement. Very expensive though.
-		// It is possible to check for existence and permission by connecting,
-		// cd to target, put dummy file, ls to see list it, rm to clean it
-		// p_oDir exists 
-		// p_oDir writable 
-		// p_oDir readable 
-
-	}
-
-	// @Override
-	public boolean deleteFile(File file) throws GatewayException
-	{
-		RemoteFileSystem rfs = null;
-		try
-		{
-			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
-			rfs.deleteRemoteFile(file.toString());
-			return true;
-		} catch (Exception e)
-		{
-			throw new GatewayException(e);
-		} finally
-		{
-			if (null != rfs)
-				rfs.quit();
-		}
-	}
-
-	// @Override
-	byte[] getFileContents(File file) throws GatewayException
-	{
-		RemoteFileSystem rfs = null;
-		try
-		{
-			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
-			File temp = File.createTempFile("FTPdown", ".tmp");
-			temp.delete();
-			rfs.downloadFile(file.toString(), temp.toString());
-			return getFileContents(temp);
-		} catch (Exception e)
-		{
-			throw new GatewayException(e);
-		} finally
-		{
-			if (null != rfs)
-				rfs.quit();
-		}
-	}
-
-	// @Override
-	File[] getFileList(String suffix) throws GatewayException
-	{
-		RemoteFileSystem rfs = null;
-		try
-		{
-			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
-			rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
-			String[] sa = rfs.getFileListFromRemoteDir(_inputSuffix);
-			File[] oaRet = new File[(null == sa) ? 0 : sa.length];
-			int i1 = 0;
-			if (null != sa)
-				for (String sCurr : sa)
-					oaRet[i1++] = new File(sCurr);
-			return oaRet;
-		} catch (Exception e)
-		{
-			throw new GatewayException(e);
-		} finally
-		{
-			if (null != rfs)
-				rfs.quit();
-		}
-	}
-
-	// @Override
-	boolean renameFile(File from, File to) throws GatewayException
-	{
-		RemoteFileSystem rfs = null;
-		try
-		{
-			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
-			rfs.renameInRemoteDir(from.toString(), to.toString());
-			return true;
-		} catch (Exception e)
-		{
-			throw new GatewayException(e);
-		} finally
-		{
-			if (null != rfs)
-				rfs.quit();
-		}
-	}
-
-	protected Map<String, String> _ftpArguments = new HashMap<String, String>();
-}

Copied: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java (from rev 8430, labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListener.java)
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListener.java	2006-12-20 02:17:15 UTC (rev 8430)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java	2006-12-20 17:17:36 UTC (rev 8448)
@@ -0,0 +1,155 @@
+/*
+ * 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.soa.esb.listeners.gateway;
+
+import java.io.File;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.util.FtpClientUtil;
+import org.jboss.soa.esb.util.RemoteFileSystem;
+import org.jboss.soa.esb.util.RemoteFileSystemFactory;
+
+public class RemoteGatewayListener extends FileGatewayListener
+{
+	protected RemoteGatewayListener()
+	{
+	}
+
+	public RemoteGatewayListener(GatewayListenerController commandListener,
+			ConfigTree config) throws Exception
+	{
+		super(commandListener, config);
+	}
+
+	protected void checkMyParms() throws Exception
+	{
+		super.checkMyParms();
+		File temp = File.createTempFile("FTPdown", ".tmp");
+		temp.delete();
+		_config.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, temp.getParent());
+		RemoteFileSystem rfs = RemoteFileSystemFactory.getRemoteFileSystem(
+				_config, true);
+		rfs.quit();
+	}
+
+	@Override
+	protected void seeIfOkToWorkOnDir(File p_oDir) throws GatewayException
+	{
+		// TODO: Implement. Very expensive though.
+		// It is possible to check for existence and permission by connecting,
+		// cd to target, put dummy file, ls to see list it, rm to clean it
+		// p_oDir exists 
+		// p_oDir writable 
+		// p_oDir readable 
+
+	}
+
+	// @Override
+	public boolean deleteFile(File file) throws GatewayException
+	{
+		RemoteFileSystem rfs = null;
+		try
+		{
+			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
+			rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
+			rfs.deleteRemoteFile(file.toString());
+			return true;
+		} catch (Exception e)
+		{
+			throw new GatewayException(e);
+		} finally
+		{
+			if (null != rfs)
+				rfs.quit();
+		}
+	}
+
+	// @Override
+	byte[] getFileContents(File file) throws GatewayException
+	{
+		RemoteFileSystem rfs = null;
+		try
+		{
+			File temp = File.createTempFile("FTPdown", ".tmp");
+			temp.delete();
+			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
+			rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
+			rfs.downloadFile(file.toString(), temp.getName());
+			final byte[] contents = super.getFileContents(temp);
+			temp.delete() ;
+			return contents ;
+		} catch (Exception e)
+		{
+			throw new GatewayException(e);
+		} finally
+		{
+			if (null != rfs)
+				rfs.quit();
+		}
+	}
+
+	// @Override
+	File[] getFileList(String suffix) throws GatewayException
+	{
+		RemoteFileSystem rfs = null;
+		try
+		{
+			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
+			rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
+			String[] sa = rfs.getFileListFromRemoteDir(_inputSuffix);
+			File[] oaRet = new File[(null == sa) ? 0 : sa.length];
+			int i1 = 0;
+			if (null != sa)
+				for (String sCurr : sa)
+					oaRet[i1++] = new File(sCurr);
+			return oaRet;
+		} catch (Exception e)
+		{
+			throw new GatewayException(e);
+		} finally
+		{
+			if (null != rfs)
+				rfs.quit();
+		}
+	}
+
+	// @Override
+	boolean renameFile(File from, File to) throws GatewayException
+	{
+		RemoteFileSystem rfs = null;
+		try
+		{
+			rfs = RemoteFileSystemFactory.getRemoteFileSystem(_config, true);
+			rfs.setRemoteDir(FtpClientUtil.fileToFtpString(_inputDirectory));
+			rfs.renameInRemoteDir(from.toString(), to.toString());
+			return true;
+		} catch (Exception e)
+		{
+			throw new GatewayException(e);
+		} finally
+		{
+			if (null != rfs)
+				rfs.quit();
+		}
+	}
+}


Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListener.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

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	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java	2006-12-20 17:17:36 UTC (rev 8448)
@@ -193,7 +193,7 @@
 
 		m_sRemoteDir = m_oParms.getAttribute(PARMS_REMOTE_DIR);
 		if (null == m_sRemoteDir)
-			m_sRemoteDir = "";
+			m_sRemoteDir = ".";
 
 		m_sLocalDir = m_oParms.getAttribute(PARMS_LOCAL_DIR);
 		if (null == m_sLocalDir)

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java	2006-12-20 17:17:36 UTC (rev 8448)
@@ -87,7 +87,7 @@
 
 	private SFTPEpr m_oEpr;
 
-	private ConfigTree m_oParms, m_oTree;
+	private ConfigTree m_oParms;
 
 	private String m_sFtpServer, m_sUser, m_sPasswd;
 
@@ -428,21 +428,22 @@
 	}
 
 	private void configTreeFromEpr() throws RemoteFileSystemException {
+		m_oParms = new ConfigTree("fromEpr");
 		try {
-			m_oTree.setAttribute(RemoteFileSystem.PARMS_FTP_SERVER,
+			m_oParms.setAttribute(RemoteFileSystem.PARMS_FTP_SERVER,
 					m_sFtpServer);
-			m_oTree.setAttribute(RemoteFileSystem.PARMS_USER, m_sUser);
-			m_oTree.setAttribute(RemoteFileSystem.PARMS_PASSWD, m_sPasswd);
-			m_oTree.setAttribute(RemoteFileSystem.PARMS_REMOTE_DIR,
+			m_oParms.setAttribute(RemoteFileSystem.PARMS_USER, m_sUser);
+			m_oParms.setAttribute(RemoteFileSystem.PARMS_PASSWD, m_sPasswd);
+			m_oParms.setAttribute(RemoteFileSystem.PARMS_REMOTE_DIR,
 					m_sRemoteDir);
-			m_oTree.setAttribute(RemoteFileSystem.PARMS_PORT, Integer
+			m_oParms.setAttribute(RemoteFileSystem.PARMS_PORT, Integer
 					.toString(m_iPort));
-			m_oTree.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, m_sLocalDir);
-			m_oTree.setAttribute(RemoteFileSystem.PARMS_ASCII, Boolean
+			m_oParms.setAttribute(RemoteFileSystem.PARMS_LOCAL_DIR, m_sLocalDir);
+			m_oParms.setAttribute(RemoteFileSystem.PARMS_ASCII, Boolean
 					.toString(false));
-			m_oTree.setAttribute(RemoteFileSystem.PARMS_PASSIVE, Boolean
+			m_oParms.setAttribute(RemoteFileSystem.PARMS_PASSIVE, Boolean
 					.toString(m_bPassive));
-			m_oTree.setAttribute(RemoteFileSystem.PARMS_CERTIFICATE, m_oCertificate.toString());
+			m_oParms.setAttribute(RemoteFileSystem.PARMS_CERTIFICATE, m_oCertificate.toString());
 		} catch (Exception e) {
 			throw new RemoteFileSystemException(e);
 		}

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystem.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystem.java	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystem.java	2006-12-20 17:17:36 UTC (rev 8448)
@@ -32,6 +32,8 @@
 
 	public static final String FTPS_PROTOCOL = "ftps";
 
+	public static final String PARMS_PROTOCOL = "protocol";
+	
 	public static final String PARMS_FTP_SERVER = "ftpServer";
 
 	public static final String PARMS_USER = "ftpUser";

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java	2006-12-20 17:17:36 UTC (rev 8448)
@@ -79,7 +79,6 @@
 			throw new RemoteFileSystemException(e);
 		}
 		throw new RemoteFileSystemException("Unknown or unsupported protocol");
-
 	}
 
 	/**
@@ -92,12 +91,13 @@
 	public static RemoteFileSystem getRemoteFileSystem(ConfigTree p_oP,
 			boolean p_bConnect) throws RemoteFileSystemException
 	{
+		final String protocol = p_oP.getAttribute(RemoteFileSystem.PARMS_PROTOCOL) ;
 		try
 		{
-			// TODO get the implementation class from properties.
-			// See SecureFtpImplUnitTest and EdtFtpImplUnitTest for Tests.
-			// return new SecureFtpImpl(p_oP,p_bConnect);
-			return new EdtFtpImpl(p_oP, p_bConnect);
+			if (RemoteFileSystem.FTP_PROTOCOL.equals(protocol))
+				return new EdtFtpImpl(p_oP, p_bConnect);
+			else if (RemoteFileSystem.SFTP_PROTOCOL.equals(protocol))
+				return new SecureFtpImpl(p_oP, p_bConnect);
 		} catch (UnknownHostException ex)
 		{
 			throw new RemoteFileSystemException(ex);
@@ -122,7 +122,7 @@
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
-		throw new RemoteFileSystemException("Unknown protocol");
+		throw new RemoteFileSystemException("Unknown protocol: " + protocol);
 	}
 
 }

Modified: labs/jbossesb/trunk/product/core/rosetta/tests/build.xml
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/build.xml	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/build.xml	2006-12-20 17:17:36 UTC (rev 8448)
@@ -119,6 +119,7 @@
         	<sysproperty key="org.jboss.esb.test.db.password" value="${org.jboss.esb.test.db.password}"/>
         	<sysproperty key="org.jboss.esb.test.ftp.hostname" value="${org.jboss.esb.test.ftp.hostname}"/>
         	<sysproperty key="org.jboss.esb.test.ftp.user" value="${org.jboss.esb.test.ftp.user}"/>
+        	<sysproperty key="org.jboss.esb.test.ftp.pwd" value="${org.jboss.esb.test.ftp.pwd}"/>
         	<sysproperty key="org.jboss.esb.test.ftp.dir" value="${org.jboss.esb.test.ftp.dir}"/>
         	<sysproperty key="log4j.configuration" value="log4j.xml"/>
         </junit>

Modified: labs/jbossesb/trunk/qa/build.xml
===================================================================
--- labs/jbossesb/trunk/qa/build.xml	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/qa/build.xml	2006-12-20 17:17:36 UTC (rev 8448)
@@ -14,6 +14,7 @@
 			    fork="true" failonerror="true">
 				<sysproperty key="ant.home" value="${ant.home}"/>
 				<sysproperty key="ant.library.dir" value="${ant.library.dir}"/>
+	                        <sysproperty key="org.jboss.esb.properties" value="${org.jboss.esb.properties}"/>
 				<arg value="-cp"/>
 				<arg value="${junit.jar}"/>
 				<arg value="-f"/>

Modified: labs/jbossesb/trunk/qa/junit/build.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/build.xml	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/qa/junit/build.xml	2006-12-20 17:17:36 UTC (rev 8448)
@@ -11,6 +11,12 @@
 	<property name="qa.junit.report" location="${qa.build}/junit/report" />
         <property name="qa.junit.memory" value="128m"/>
 
+        <property file="${org.jboss.esb.properties}"/>
+        <property name="org.jboss.esb.test.ftp.hostname" value="ftp.ncl.ac.uk"/>
+        <property name="org.jboss.esb.test.ftp.user" value="anonymous"/>
+        <property name="org.jboss.esb.test.ftp.pwd" value=""/>
+        <property name="org.jboss.esb.test.ftp.dir" value="/pub/DNS"/>
+
 	<path id="base.cp">
 		<fileset dir="${product.lib}/ext"
 		    		excludes="*.jar" includes="jaxr-api-1.0.jar,scout-0.7rc2-embedded.jar,juddi-embedded.jar"/>
@@ -51,6 +57,7 @@
             <batchtest todir="${qa.junit.report}">
                 <fileset dir="${qa.junit.src}">
                     <include name="**/${tests.filter}Test.java"/>
+                    <exclude name="${tests.exclude}"/>
                 </fileset>
             </batchtest>
             <classpath>
@@ -72,6 +79,11 @@
         	<sysproperty key="org.jboss.esb.db.url" 		value="${org.jboss.esb.db.url}" />
         	<sysproperty key="org.jboss.esb.db.user" 		value="${org.jboss.esb.db.user}" />
 	    	<sysproperty key="org.jboss.esb.db.password" 	value="${org.jboss.esb.db.password}" />
+                <sysproperty key="org.jboss.esb.test.ftp.hostname" value="${org.jboss.esb.test.ftp.hostname}"/>
+                <sysproperty key="org.jboss.esb.test.ftp.user" value="${org.jboss.esb.test.ftp.user}"/>
+                <sysproperty key="org.jboss.esb.test.ftp.pwd" value="${org.jboss.esb.test.ftp.pwd}"/>
+                <sysproperty key="org.jboss.esb.test.ftp.dir" value="${org.jboss.esb.test.ftp.dir}"/>
+
         </junit>
 		
 		<!-- Remove all "fixed-up" listener configuration files -->
@@ -99,6 +111,7 @@
 	</target>
 
 	<target name="prompt">
+            <property name="tests.exclude" value="**/*IntegrationTest.java"/>
 		<echo message="" />
 		<echo message="" />
 		<input message='Which tests? (Press return to run all tests - Wildcards Supported - already assumes test cases end with the "Test" suffix)' 

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListenerIntegrationTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListenerIntegrationTest.java	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListenerIntegrationTest.java	2006-12-20 17:17:36 UTC (rev 8448)
@@ -0,0 +1,279 @@
+/*
+ * 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.soa.esb.listeners.gateway;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Properties;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.EsbListenerControllerFactory;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.testutils.FileUtil;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import org.jboss.soa.esb.util.RemoteFileSystem;
+import org.jboss.soa.esb.util.RemoteFileSystemFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+public class FtpGatewayListenerIntegrationTest
+{
+
+	private static final String TMP_DIR	= System.getProperty("java.io.tmpdir","/tmp");
+
+	private static Logger _logger			= Logger.getLogger(FtpGatewayListenerIntegrationTest.class);
+	private static String _gatewayConfig		= "ftpGatewayConfig.xml";
+	private static String _esbListenerConfig 	= "ftpEsbListenerConfig.xml";
+	private static File _returnFile			= new File(TMP_DIR,"ftpMessageBack.txt");
+	private static File _initialFile			= new File(TMP_DIR,"ftpMessage.txt");
+
+	
+	private static String THE_TEXT 		= "This is the FTP text that will travel around";
+
+	EsbListenerController	_esbListController;
+	GatewayListenerController _gatewayController;
+
+    private static String mDbDriver;
+	private static String mDbUrl;
+	private static String mDbUsername;
+	private static String mDbPassword;
+	
+	private static String mFtpHostname ;
+	private static String mFtpUser ;
+	private static String mFtpPwd ;
+	private static String mFtpDir ;
+
+	@BeforeClass
+	public static void setUp() throws Exception
+	{
+		_logger.info("Writing temp files to "+TMP_DIR);
+
+    	// delete this one just to make sure asserts take the new ones
+    	_returnFile.delete();
+    	
+    	// initialize registry
+    	runBeforeAllTests();
+	}
+	
+	@AfterClass
+	public static void tearDown() throws Exception
+	{
+    	_returnFile.delete();
+
+    	Thread.sleep(2000);
+    	if ("org.hsqldb.jdbcDriver".equals(mDbDriver))
+			HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+	}
+	
+	@Test
+	public void ftpGatewayListener() throws Exception 
+    {
+    	// send a message so when gateway comes up, it will have something waiting
+    	sendFtpMessage(THE_TEXT);
+    	
+		InputStream inStream = getClass().getResourceAsStream(_esbListenerConfig);
+		ConfigTree tree = ConfigTree.fromInputStream(inStream);
+		_esbListController = EsbListenerControllerFactory.getInstance(tree);
+
+		tree = getGatewayConfig() ;
+		_gatewayController = new GatewayListenerController(tree);
+		new Thread(_gatewayController).start();
+		Thread.sleep(4000);
+
+		_esbListController.requestEnd();
+		_gatewayController.requestEnd();    
+		
+		assertEquals(THE_TEXT, stringFromFile(_returnFile));
+    }
+	
+	public static class MockMessageAwareAction 
+	{
+	    ConfigTree _config;
+	    public MockMessageAwareAction(ConfigTree config) { _config = config; } 
+	    public Message writeToDisk (Message message) throws Exception 
+	    {
+	    	bytesToFile(_returnFile, message.getBody().getContents());
+	    	return message;
+	    } // ________________________________
+
+	} // ___________________________________________________
+
+	private ConfigTree getGatewayConfig()
+		throws IOException, SAXException
+	{
+		InputStream inStream = getClass().getResourceAsStream(_gatewayConfig);
+		try
+		{
+			ConfigTree tree = ConfigTree.fromInputStream(inStream);
+		
+			final ConfigTree child = tree.getAllChildren()[0] ;
+			child.setAttribute(RemoteFileSystem.PARMS_FTP_SERVER, mFtpHostname) ;
+			child.setAttribute(RemoteFileSystem.PARMS_USER, mFtpUser) ;
+			child.setAttribute(RemoteFileSystem.PARMS_PASSWD, mFtpPwd) ;
+			child.setAttribute(ListenerTagNames.FILE_INPUT_DIR_TAG, mFtpDir) ;
+			return tree ;
+		}
+		finally
+		{
+			inStream.close() ;
+		}
+	}
+
+	private static void bytesToFile(File file, byte[] text) throws Exception
+	{
+		OutputStream out = new FileOutputStream(file);
+		try
+		{
+			out.write(text);
+		}
+		finally
+		{
+			out.close();
+		}
+	}
+
+	private static void stringToFile(final File file, final String text) throws Exception
+	{
+		Writer out = new FileWriter(file);
+		try
+		{
+			out.write(text);
+		}
+		finally
+		{
+			out.close();
+		}
+	}
+
+	private static String stringFromFile(File file) throws Exception
+	{
+		ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+		FileInputStream	inp = new FileInputStream(file);
+		byte[] ba = new byte[1000];
+		int iQ;
+		while (-1 != (iQ=inp.read(ba)))
+			if (iQ > 0)
+				out.write(ba,0,iQ);
+		inp.close();
+		
+		out.close();
+		return out.toString();
+	}
+	
+	private void sendFtpMessage(String text) throws Exception
+	{
+		stringToFile(_initialFile, text) ;
+		
+		final ConfigTree tree = getGatewayConfig().getAllChildren()[0] ;
+		final RemoteFileSystem fileSystem = RemoteFileSystemFactory.getRemoteFileSystem(tree, true) ;
+		final String remoteName = mFtpDir + "/" + System.currentTimeMillis() + tree.getAttribute(ListenerTagNames.FILE_INPUT_SFX_TAG) ;
+		fileSystem.uploadFile(_initialFile, remoteName) ;
+    } //________________________________
+	
+	public static void runBeforeAllTests()
+	{
+		mFtpHostname = System.getProperty("org.jboss.esb.test.ftp.hostname") ;
+		mFtpUser = System.getProperty("org.jboss.esb.test.ftp.user") ;
+		mFtpPwd = System.getProperty("org.jboss.esb.test.ftp.pwd") ;
+		mFtpDir = System.getProperty("org.jboss.esb.test.ftp.dir") ;
+		
+		try {
+			DOMConfigurator.configure(TestEnvironmentUtil.getUserDir("product","../product") + "etc/test/resources/log4j.xml");
+			TestEnvironmentUtil.setESBPropertiesFileToUse("product","../product");
+			//Set the juddi properties file in System so juddi will pick it up later and use the test values.
+			String juddiPropertiesFile = "/org/jboss/soa/esb/services/registry/juddi-qatest.properties";
+			System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
+			//Read this properties file to get the db connection string
+			Properties props = new Properties();
+			InputStream inStream = Class.class.getResourceAsStream(juddiPropertiesFile);
+			props.load(inStream);
+			mDbDriver    = props.getProperty("juddi.jdbcDriver");
+			mDbUrl       = props.getProperty("juddi.jdbcUrl");
+			mDbUsername  = props.getProperty("juddi.jdbcUsername");
+			mDbPassword  = props.getProperty("juddi.jdbcPassword");
+			
+			String database="not tested yet";
+			if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+				database = "hsqldb";
+				//Bring up hsql on default port 9001
+				HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir("product","../product") + "build/hsqltestdb", "juddi");
+			} else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
+				database = "mysql";
+			} //add and test your own database..
+			
+			//Get the registry-schema create scripts
+			String sqlDir = TestEnvironmentUtil.getUserDir("product","../product") + "install/jUDDI-registry/sql/" + database + "/";
+			//Drop what is there now, if exists. We want to start fresh.
+			String sqlDropCmd      = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
+			String sqlCreateCmd    = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
+			String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir + "insert_publishers.sql"));
+			
+			try {
+				Class.forName(mDbDriver);
+			} catch (Exception e) {
+				System.out.println("ERROR: failed to load " + database + " JDBC driver.");
+				e.printStackTrace();
+				return;
+			}
+			java.sql.Connection con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
+			Statement stmnt = con.createStatement();
+			System.out.println("Dropping the schema if exist");
+			stmnt.execute(sqlDropCmd);
+			System.out.println("Creating the juddi-schema");
+			stmnt.execute(sqlCreateCmd);
+			System.out.println("Adding the jbossesb publisher");
+			stmnt.execute(sqlInsertPubCmd);
+			
+		} catch (Throwable e) {
+			e.printStackTrace();
+			System.out.println("We should stop testing, since we don't have a db.");
+			assertTrue(false);
+		}
+	}
+	public static junit.framework.Test suite() {
+		return new JUnit4TestAdapter(FtpGatewayListenerIntegrationTest.class);
+	}
+
+}


Property changes on: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FtpGatewayListenerIntegrationTest.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpEsbListenerConfig.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpEsbListenerConfig.xml	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpEsbListenerConfig.xml	2006-12-20 17:17:36 UTC (rev 8448)
@@ -0,0 +1,26 @@
+<FTPListenerController parameterReloadSecs="180">
+   <DummyFTPMessageListener
+        service-category="ftpCategory"
+        service-name="testFtpGateway"
+		service-description="FTP Dummy Service"
+		epr-description="Service endpoint for the FTP gateway"
+	  	listenerClass="org.jboss.soa.esb.listeners.message.JmsQueueListener"
+		connection-factory="ConnectionFactory"
+		destination-type="queue"
+		destination-name="queue/A"
+		jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
+		jndi-URL="localhost"
+		message-selector="service='ftpFileGateway'"
+  	>
+	   <action 
+	   	class="org.jboss.soa.esb.listeners.gateway.FtpGatewayListenerIntegrationTest$MockMessageAwareAction" 
+	   	process="writeToDisk" 
+	   />
+	   <action  class="org.jboss.soa.esb.actions.Notifier"  okMethod="notifyOK">
+		   	<NotificationList type="OK"> 
+				<target class="NotifyConsole" />
+			</NotificationList> 
+	   </action>
+   </DummyFTPMessageListener>
+   
+</FTPListenerController>


Property changes on: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpEsbListenerConfig.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpGatewayConfig.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpGatewayConfig.xml	2006-12-20 17:15:00 UTC (rev 8447)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpGatewayConfig.xml	2006-12-20 17:17:36 UTC (rev 8448)
@@ -0,0 +1,19 @@
+<FtpGateway parameterReloadSecs="600">
+    <RemoteGateway
+        target-service-category="ftpCategory"
+        target-service-name="testFtpGateway"
+     	gatewayClass="org.jboss.soa.esb.listeners.gateway.RemoteGatewayListener"
+	    pollLatencySeconds="60"
+	    protocol="ftp"
+        inputDir="Added by UNIT test"
+        inputSuffix=".dat"
+        postSuffix=".sentToEsb"
+    />
+	    <!-- 
+	    ftpServer="replaced by unit test"
+	    ftpPort="replaced by unit test"
+	    ftpUser="replaced by unit test"
+	    ftpPassword="replaced by unit test"
+	    inputDir="replaced by unit test"
+	    -->
+</FtpGateway>


Property changes on: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/ftpGatewayConfig.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list