[jboss-svn-commits] JBL Code SVN: r10068 - labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Mar 8 09:21:27 EST 2007


Author: mark.little at jboss.com
Date: 2007-03-08 09:21:27 -0500 (Thu, 08 Mar 2007)
New Revision: 10068

Added:
   labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
   labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListenerUnitTest.java
Log:
http://jira.jboss.com/jira/browse/JBESB-345

Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	2007-03-08 14:21:27 UTC (rev 10068)
@@ -0,0 +1,203 @@
+/*
+ * 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.io.FileOutputStream;
+
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.gateway.FileGatewayListener;
+import org.jboss.soa.esb.listeners.gateway.GatewayException;
+
+public class FileGatewayListenerUnitTest extends BaseTest
+{
+	public FileGatewayListenerUnitTest ()
+	{
+	}
+
+	public void testGateway () throws Exception
+	{
+		ConfigTree tree = new ConfigTree("test");
+		final File tmpDir = new File(System.getProperty("user.dir")) ;
+		final String tmpDirForm = tmpDir.toURL().toExternalForm() ;
+
+		tree.setAttribute("inputDir", tmpDirForm);
+		tree.setAttribute("target-service-category", "Example");
+		tree.setAttribute("target-service-name", "Test");
+		tree.setAttribute("gatewayClass", "org.jboss.soa.esb.listeners.gateway.FileGatewayListener");
+		tree.setAttribute("inputSuffix", "dummy");
+		tree.setAttribute("workSuffix", "work");
+		tree.setAttribute("postDelete", "true");
+		
+		FileGatewayListener gateway = new FileGatewayListener(tree);
+		boolean exception = false;
+		
+		try
+		{
+			gateway.seeIfOkToWorkOnDir(new File("foobarDir"));
+		}
+		catch (GatewayException ex)
+		{
+			exception = true;
+		}
+		
+		if (!exception)
+			fail();
+		
+		File testFile = null;
+		File anTestFile = null;
+		
+		try
+		{
+			testFile = File.createTempFile("foo", "testFile");
+			
+			String testString = "Hello World";
+			FileOutputStream stream = new FileOutputStream(testFile);
+			
+			stream.write(testString.getBytes());
+			stream.close();
+			
+			try
+			{
+				byte[] content = gateway.getFileContents(testFile);
+				String value = new String(content);
+				
+				if (!value.equals(testString))
+					fail();
+				
+				if (!gateway.deleteFile(testFile))
+					fail();
+				
+				testFile = File.createTempFile("foo", "testFile");
+				anTestFile = File.createTempFile("bar", "testFile");
+				
+				File[] files = gateway.getFileList("testFile");
+				
+				// TODO check why getFileList ignores the parameter! Hence this test fails!
+				
+				/*
+				if (files.length != 2)
+				{
+					for (int i = 0; i < files.length; i++)
+						System.err.println(files[i]);
+				
+					fail();	
+				}
+				*/
+				
+				try
+				{
+					gateway.copyFile(testFile, anTestFile);
+				}
+				catch (Exception ex)
+				{
+					ex.printStackTrace();
+					
+					fail();
+				}
+				
+				testString = "Hello World";
+				stream = new FileOutputStream(testFile);
+				
+				stream.write(testString.getBytes());
+				stream.close();
+				
+				try
+				{
+					gateway.copyFile(testFile, anTestFile);
+				}
+				catch (Exception ex)
+				{
+					ex.printStackTrace();
+					
+					fail();
+				}
+				
+				exception = false;
+				
+				File badTo = new File("");
+				File badFrom = new File("barfoo");
+				
+				try
+				{
+					try
+					{
+						gateway.copyFile(badFrom, anTestFile);
+					}
+					catch (GatewayException ex)
+					{
+						exception = true;
+					}
+					
+					if (!exception)
+						fail();
+					
+					exception = false;
+					
+					try
+					{
+						gateway.copyFile(testFile, badTo);
+					}
+					catch (GatewayException ex)
+					{
+						exception = true;
+					}
+					
+					if (!exception)
+						fail();
+				}
+				finally
+				{
+					badTo.delete();
+					badFrom.delete();
+				}
+				
+				File nFile = new File("foobar");
+				
+				if (gateway.renameFile(anTestFile, nFile))
+				{
+					anTestFile = nFile;
+				}
+				else
+					fail();
+			}
+			catch (Exception ex)
+			{
+				fail();
+			}
+		}
+		catch (Throwable ex)
+		{
+			ex.printStackTrace();
+			
+			fail();
+		}
+		finally
+		{
+			testFile.delete();
+			anTestFile.delete();
+		}
+	}
+	
+}

Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListenerUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListenerUnitTest.java	2007-03-08 14:21:27 UTC (rev 10068)
@@ -0,0 +1,161 @@
+/*
+ * 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.sql.SQLException;
+import java.sql.Statement;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+
+public class SqlTableGatewayListenerUnitTest extends BaseTest
+{
+	public SqlTableGatewayListenerUnitTest ()
+	{
+	}
+
+	public void setUp()
+	{
+		try
+		{
+			Statement stmt = getDbConnection().createStatement();
+
+			try
+			{
+				stmt.executeUpdate("DROP TABLE esb_messages");
+			}
+			catch (Exception e)
+			{
+				// Ignore
+			}
+
+			stmt.executeUpdate("CREATE TABLE esb_messages (message_id varchar NOT NULL, message varchar, status varchar, insert_timestamp bigint, CONSTRAINT pkey_esb_messages PRIMARY KEY (message_id))");
+		}
+		catch (SQLException ex)
+		{
+			ex.printStackTrace();
+
+			fail();
+		}
+	}
+	
+	public void testGateway () throws Exception
+	{
+		ConfigTree tree = new ConfigTree("test");
+
+		tree.setAttribute(JDBCEpr.URL_TAG, "jdbc:postgresql://myhost:5432/testDB");
+		tree.setAttribute(JDBCEpr.POST_DEL_TAG, "true");
+		tree.setAttribute(JDBCEpr.ERROR_DEL_TAG, "true");
+		tree.setAttribute(JDBCEpr.DRIVER_TAG, "org.postgresql.Driver");
+		tree.setAttribute(JDBCEpr.TIMESTAMP_COLUMN_TAG, "insert_timestamp");
+		tree.setAttribute(JDBCEpr.MESSAGE_ID_COLUMN_TAG, "message_id");
+		tree.setAttribute(JDBCEpr.PASSWORD_TAG, "secret");
+		tree.setAttribute(JDBCEpr.STATUS_COLUMN_TAG, "status");
+		tree.setAttribute(JDBCEpr.TABLE_NAME_TAG, "testtable");
+		tree.setAttribute(JDBCEpr.USERNAME_TAG, "joe");
+		tree.setAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG, "abcde");
+		tree.setAttribute("target-service-category", "Example");
+		tree.setAttribute("target-service-name", "Test");
+		tree.setAttribute("gatewayClass", "org.jboss.soa.esb.listeners.gateway.JdbcTableGatewayListener");
+		
+		SqlTableGatewayListener gateway = new SqlTableGatewayListener(tree);
+		
+		try
+		{
+			gateway.resolveComposerClass();
+		}
+		catch (ConfigurationException ex)
+		{
+			fail();
+		}
+		
+		boolean exception = false;
+		
+		try
+		{
+			gateway.prepareStatements();
+		}
+		catch (RuntimeException ex)
+		{
+			exception = true;
+		}
+		
+		if (!exception)
+			fail();
+		
+		tree = new ConfigTree("test");
+
+		tree.setAttribute(JDBCEpr.URL_TAG, getDbUrl());
+		tree.setAttribute(JDBCEpr.POST_DEL_TAG, "true");
+		tree.setAttribute(JDBCEpr.ERROR_DEL_TAG, "true");
+		tree.setAttribute(JDBCEpr.DRIVER_TAG, getDbDriver());
+		tree.setAttribute(JDBCEpr.TIMESTAMP_COLUMN_TAG, "insert_timestamp");
+		tree.setAttribute(JDBCEpr.MESSAGE_ID_COLUMN_TAG, "message_id");
+		tree.setAttribute(JDBCEpr.PASSWORD_TAG, getDbPassword());
+		tree.setAttribute(JDBCEpr.STATUS_COLUMN_TAG, "status");
+		tree.setAttribute(JDBCEpr.TABLE_NAME_TAG, "esb_messages");
+		tree.setAttribute(JDBCEpr.USERNAME_TAG, getDbUser());
+		tree.setAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG, "1000");
+		tree.setAttribute("target-service-category", "Example");
+		tree.setAttribute("target-service-name", "Test");
+		tree.setAttribute("gatewayClass", "org.jboss.soa.esb.listeners.gateway.JdbcTableGatewayListener");
+		
+		gateway = new SqlTableGatewayListener(tree);
+		
+		try
+		{
+			gateway.prepareStatements();
+		}
+		catch (RuntimeException ex)
+		{
+			ex.printStackTrace();
+			
+			fail();
+		}
+		
+		exception = false;
+		
+		try
+		{
+			gateway.doInitialise();
+		}
+		catch (ManagedLifecycleException ex)
+		{
+			exception = true;
+		}
+		
+		if (!exception)
+			fail();
+		
+		gateway.pollForCandidates();
+		
+		gateway.changeStatusToDone();
+		
+		gateway.deleteCurrentRow();
+	}
+	
+}




More information about the jboss-svn-commits mailing list