[jboss-svn-commits] JBL Code SVN: r8470 - in labs/jbossesb/trunk: product/core/rosetta/src/org/jboss/internal/soa/esb/util 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 18:54:46 EST 2006
Author: kevin.conner at jboss.com
Date: 2006-12-20 18:54:40 -0500 (Wed, 20 Dec 2006)
New Revision: 8470
Added:
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/SftpGatewayListenerIntegrationTest.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/sftpEsbListenerConfig.xml
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/sftpGatewayConfig.xml
Removed:
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/secureFtpEsbListenerConfig.xml
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/secureFtpGatewayListenerConfig.xml
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java
Log:
Added SFTP gateway test
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 23:08:17 UTC (rev 8469)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java 2006-12-20 23:54:40 UTC (rev 8470)
@@ -201,7 +201,7 @@
if (bConnect) {
session = m_oJSch.getSession(m_sUser, m_sFtpServer, m_iPort);
- UserInfo ui = new SecureFtpUserInfo("");
+ UserInfo ui = new SecureFtpUserInfo(m_sPasswd);
session.setUserInfo(ui);
session.connect();
@@ -251,7 +251,11 @@
sAux = m_oParms.getAttribute(PARMS_PASSIVE);
m_bPassive = (null != sAux) && Boolean.parseBoolean(sAux);
- m_oCertificate = new URL(m_oParms.getAttribute(PARMS_CERTIFICATE));
+ final String certificate = m_oParms.getAttribute(PARMS_CERTIFICATE) ;
+ if (certificate != null)
+ {
+ m_oCertificate = new URL(certificate);
+ }
return;
}
@@ -299,7 +303,7 @@
}
}
}
- return (String[]) lFileList.toArray();
+ return (String[]) lFileList.toArray(new String[lFileList.size()]);
}
/*
@@ -401,7 +405,7 @@
}
// TODO check if we have to set the Transfer Type with JSch impl =>
// m_oXferType
- m_oSftpChannel.get(FtpUtils.fileToFtpString(oLclFile), p_sFile);
+ m_oSftpChannel.get(p_sFile, FtpUtils.fileToFtpString(oLclFile));
File oNew = new File(oLocalDir, p_sFinalName);
if (oNew.exists())
@@ -443,7 +447,10 @@
.toString(false));
m_oParms.setAttribute(RemoteFileSystem.PARMS_PASSIVE, Boolean
.toString(m_bPassive));
- m_oParms.setAttribute(RemoteFileSystem.PARMS_CERTIFICATE, m_oCertificate.toString());
+ if (m_oCertificate != null)
+ {
+ m_oParms.setAttribute(RemoteFileSystem.PARMS_CERTIFICATE, m_oCertificate.toString());
+ }
} catch (Exception e) {
throw new RemoteFileSystemException(e);
}
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/SftpGatewayListenerIntegrationTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/SftpGatewayListenerIntegrationTest.java 2006-12-20 23:08:17 UTC (rev 8469)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/SftpGatewayListenerIntegrationTest.java 2006-12-20 23:54:40 UTC (rev 8470)
@@ -0,0 +1,280 @@
+/*
+ * 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 SftpGatewayListenerIntegrationTest
+{
+
+ private static final String TMP_DIR = System.getProperty("java.io.tmpdir","/tmp");
+
+ private static Logger _logger = Logger.getLogger(SftpGatewayListenerIntegrationTest.class);
+ private static String _gatewayConfig = "sftpGatewayConfig.xml";
+ private static String _esbListenerConfig = "sftpEsbListenerConfig.xml";
+ private static File _returnFile = new File(TMP_DIR,"sftpMessageBack.txt");
+ private static File _initialFile = new File(TMP_DIR,"sftpMessage.txt");
+
+
+ private static String THE_TEXT = "This is the SFTP 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 sftpGatewayListener() 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(RemoteFileSystem.PARMS_REMOTE_DIR, mFtpDir) ;
+ 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 = 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(SftpGatewayListenerIntegrationTest.class);
+ }
+
+}
Property changes on: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/SftpGatewayListenerIntegrationTest.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Deleted: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/secureFtpEsbListenerConfig.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/secureFtpEsbListenerConfig.xml 2006-12-20 23:08:17 UTC (rev 8469)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/secureFtpEsbListenerConfig.xml 2006-12-20 23:54:40 UTC (rev 8470)
@@ -1,29 +0,0 @@
-<JmsListenerController parameterReloadSecs="180">
- <CoalMarketRightsMessageListener
- service-category="SecureRemoteFileXfer"
- service-name="CoalMarketRates"
- service-description="Description for the Coal Market Rights esb listener"
- epr-description="JMS endpoint for coal market rights listener"
- listenerClass="org.jboss.soa.esb.listeners.message.JmsQueueListener"
- >
- <toEPR
- connection-factory="ConnectionFactory"
- destination-type="queue"
- destination-name="queue/A"
- jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
- jndi-URL="localhost"
- message-selector="service='coalMarketRights'"
- />
- <faultEPR
- service-category="faults"
- service-name="CoalMarketRigthsFaults"
- />
- <action class="org.jboss.soa.esb.actions.Notifier" okMethod="notifyOK">
- <NotificationList type="OK">
- <target class="NotifyConsole" />
- </NotificationList>
- </action>
-
- </CoalMarketRightsMessageListener>
-
-</JmsListenerController>
Deleted: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/secureFtpGatewayListenerConfig.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/secureFtpGatewayListenerConfig.xml 2006-12-20 23:08:17 UTC (rev 8469)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/secureFtpGatewayListenerConfig.xml 2006-12-20 23:54:40 UTC (rev 8470)
@@ -1,51 +0,0 @@
-<RemoteFileSystemTest parameterReloadSecs="600">
- <CoalMarketRightsGateway
- target-service-category="SecureRemoteFileXfer"
- target-service-name="CoalMarketRates"
- gatewayClass="org.jboss.soa.esb.listeners.gateway.FtpGatewayListener"
- pollLatencySeconds="60"
- >
- <targetEPR
- url="sftp://user:password@host:port/path0/path1"
- suffix=".dat"
- >
- <sftp
- clientAuthEnable="false"
- clientCertFile=""
- passphrase=""
- passive="false"
- />
- </targetEPR>
-
- <postProcessEPR
- url="sftp://user:password@host:port/path0/path1"
- suffix=".sentToEsb"
- postDelete="false"
- >
- <sftp
- clientAuthEnable="false"
- clientCertFile=""
- passphrase=""
- passive="false"
- />
- </postProcessEPR>
-
- <faultEPR
- service-category="faults"
- service-name="faultEprforCoalMarketRights"
- >
- </faultEPR>
-
- <proxy
- enable="false"
- host=""
- port=""
- clientAuth="false"
- username=""
- password=""
- />
- <action> </action>
-
- </CoalMarketRightsGateway>
-
-</RemoteFileSystemTest>
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/sftpEsbListenerConfig.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/sftpEsbListenerConfig.xml 2006-12-20 23:08:17 UTC (rev 8469)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/sftpEsbListenerConfig.xml 2006-12-20 23:54:40 UTC (rev 8470)
@@ -0,0 +1,26 @@
+<FTPListenerController parameterReloadSecs="180">
+ <DummyFTPMessageListener
+ service-category="sftpCategory"
+ service-name="testSftpGateway"
+ service-description="SFTP Dummy Service"
+ epr-description="Service endpoint for the SFTP 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='sftpFileGateway'"
+ >
+ <action
+ class="org.jboss.soa.esb.listeners.gateway.SftpGatewayListenerIntegrationTest$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/sftpEsbListenerConfig.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/sftpGatewayConfig.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/sftpGatewayConfig.xml 2006-12-20 23:08:17 UTC (rev 8469)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/sftpGatewayConfig.xml 2006-12-20 23:54:40 UTC (rev 8470)
@@ -0,0 +1,19 @@
+<SftpGateway parameterReloadSecs="600">
+ <RemoteGateway
+ target-service-category="sftpCategory"
+ target-service-name="testSftpGateway"
+ gatewayClass="org.jboss.soa.esb.listeners.gateway.RemoteGatewayListener"
+ pollLatencySeconds="60"
+ protocol="sftp"
+ 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"
+ -->
+</SftpGateway>
Property changes on: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/sftpGatewayConfig.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