[jboss-svn-commits] JBL Code SVN: r7464 - in labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners: . gateway

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 8 08:35:36 EST 2006


Author: estebanschifman
Date: 2006-11-08 08:35:33 -0500 (Wed, 08 Nov 2006)
New Revision: 7464

Added:
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java
Log:
Move gateway tests to QA

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	2006-11-08 13:24:05 UTC (rev 7463)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	2006-11-08 13:35:33 UTC (rev 7464)
@@ -0,0 +1,176 @@
+/*
+ * 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.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.message.Message;
+
+public class FileGatewayListenerUnitTest extends BaseTest 
+{
+
+	private static final String TMP_DIR	= System.getProperty("java.io.tmpdir","/tmp"); 
+
+	private Logger _logger			= Logger.getLogger(this.getClass());
+	static File _gatewayConfig		= new File(TMP_DIR,"fileGatewayConfig.xml");
+	static File _esbListenerConfig 	= new File(TMP_DIR,"fileEsbListenerConfig.xml");
+	static File _returnFile			= new File(TMP_DIR,"fileMessageBack.txt");
+	static File _droppedFile		= new File(TMP_DIR,"fileLegacy.dat");
+	static String POST_SUFFIX 		= ".sentToEsb";
+	static File _doneFile			= new File(_droppedFile.toString()+POST_SUFFIX);
+
+	static String SERVICE_NAME	= "testFileGateway";
+	static String THE_TEXT		= "This is the FILE text that will travel around";
+
+	String _appServer		= System.getProperty("unit.test.appserver","localhost");
+	EsbListenerController	_esbListController;
+	GatewayListenerController _gatewayController;
+
+	public void setUp() throws Exception
+	{
+		_logger.info("Writing temp files to "+TMP_DIR);
+    	writeGatewayConfig();
+    	writeEsbListenerConfig();
+    	bytesToFile(_droppedFile, THE_TEXT.getBytes());
+
+    	// delete these two just to make sure asserts take the new ones
+    	_doneFile.delete();
+    	_returnFile.delete();
+	}
+	
+	public void tearDown() throws Exception
+	{
+    	_gatewayConfig.delete();
+    	_esbListenerConfig.delete();
+    	_doneFile.delete();
+    	_returnFile.delete();
+	}
+	
+	public void test_FileGatewayListener() throws Exception 
+    {
+        try 
+        {
+    		_esbListController = new EsbListenerController(_esbListenerConfig.toString());
+    		new Thread(_esbListController).start();
+    		Thread.sleep(2000);
+    		_gatewayController = new GatewayListenerController(_gatewayConfig.toString());
+    		new Thread(_gatewayController).start();
+    		Thread.sleep(4000);
+
+    		_esbListController.requestEnd();
+    		_gatewayController.requestEnd();    
+    		
+    		assertEquals(THE_TEXT, stringFromFile(_returnFile));
+    		assertEquals(true,_doneFile.exists());
+        } 
+        catch (Exception e) { }
+    }
+	
+	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;
+	    } // ________________________________
+
+	} // ___________________________________________________
+
+	void writeGatewayConfig() throws Exception
+	{
+		StringBuilder sb = new StringBuilder()
+		.append("<FileGateway parameterReloadSecs=\"180\">\n")
+		 .append("  <GatewayConfig\n")
+		 .append("     target-service-category=\"eprManager\"\n")
+		 .append("     target-service-name=\"").append(SERVICE_NAME).append("\"\n")
+		 .append("     gatewayClass=\"org.jboss.soa.esb.listeners.gateway.FileGatewayListener\"\n")
+		 .append("     pollLatencySeconds=\"5\"\n")
+		 .append("     inputDir=\"").append(TMP_DIR).append("\"\n")
+		 .append("     inputSuffix=\".dat\"\n")
+		 .append("     postSuffix=\"").append(POST_SUFFIX).append("\"\n")
+		 .append("   >\n")
+		 .append("   </GatewayConfig>\n")
+		 .append("</FileGateway>\n")
+		 ;
+		bytesToFile(_gatewayConfig, sb.toString().getBytes());
+		_logger.info("GatewayConfiguration\n"+stringFromFile(_gatewayConfig));
+	}
+	
+	void writeEsbListenerConfig() throws Exception
+	{
+		StringBuilder sb = new StringBuilder()
+		.append("<DummyTester parameterReloadSecs=\"180\">\n")
+		.append("   <DummyActionConfig\n")
+		.append("   service-category=\"eprManager\"\n")
+		.append("	service-name=\"").append(SERVICE_NAME).append("\"\n")
+		.append("	service-description=\"My Dummy Service Name\"\n")
+		.append("	epr-description=\"EPR descriptionnnnnnnnnnnnnnn\"\n")		
+		.append("  	listenerClass=\"org.jboss.soa.esb.listeners.message.JmsQueueListener\"\n")
+		.append("	connection-factory=\"ConnectionFactory\"\n")
+		.append("	destination-type=\"queue\"\n")
+		.append("	destination-name=\"queue/A\"\n")
+		.append("	jndi-type=\"jboss\"\n")
+		.append("	jndi-URL=\"").append(_appServer).append("\"\n")
+		.append("	message-selector=\"service='testFileGateway'\"\n")
+		.append("	>\n")
+		.append("	   <action class=\"").append(MockMessageAwareAction.class.getName()).append("\" process=\"writeToDisk\" />\n")
+		.append("   </DummyActionConfig>\n")
+		.append("</DummyTester>\n")
+		;
+		bytesToFile(_esbListenerConfig, sb.toString().getBytes());
+		_logger.info("EsbListenerConfiguration\n"+stringFromFile(_esbListenerConfig));
+	}
+	
+	static void bytesToFile(File file, byte[] text) throws Exception
+	{
+		OutputStream out = new FileOutputStream(file);
+		out.write(text);
+		out.close();
+	}
+
+	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();
+	}
+}

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java	2006-11-08 13:24:05 UTC (rev 7463)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java	2006-11-08 13:35:33 UTC (rev 7464)
@@ -0,0 +1,223 @@
+/*
+ * 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.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.naming.Context;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.helpers.AppServerContext;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.Util;
+
+public class JmsGatewayListenerUnitTest extends BaseTest 
+{
+
+	private static final String TMP_DIR	= System.getProperty("java.io.tmpdir","/tmp"); 
+
+	private Logger _logger			= Logger.getLogger(this.getClass());
+	static File _gatewayConfig		= new File(TMP_DIR,"jmsGatewayConfig.xml");
+	static File _esbListenerConfig 	= new File(TMP_DIR,"jmsEsbListenerConfig.xml");
+	static File _returnFile			= new File(TMP_DIR,"jmsMessageBack.txt");
+
+	
+	static String SERVICE_NAME	= "testJmsGateway";
+	static String THE_TEXT 		= "This is the JMS text that will travel around";
+
+	String _appServer		= System.getProperty("unit.test.appserver","localhost");
+	EsbListenerController	_esbListController;
+	GatewayListenerController _gatewayController;
+
+	public void setUp() throws Exception
+	{
+		_logger.info("Writing temp files to "+TMP_DIR);
+    	writeGatewayConfig();
+    	writeEsbListenerConfig();
+
+    	// delete this one just to make sure asserts take the new ones
+    	_returnFile.delete();
+    	
+    	// send a message so when gateway comes up, it will have something waiting
+    	sendJmsMessage(THE_TEXT);
+	}
+	
+	public void tearDown() throws Exception
+	{
+    	_gatewayConfig.delete();
+    	_esbListenerConfig.delete();
+    	_returnFile.delete();
+	}
+	
+	public void test_JmsGatewayListener() throws Exception 
+    {
+        try 
+        {
+    		_esbListController = new EsbListenerController(_esbListenerConfig.toString());
+    		new Thread(_esbListController).start();
+    		Thread.sleep(2000);
+    		_gatewayController = new GatewayListenerController(_gatewayConfig.toString());
+    		new Thread(_gatewayController).start();
+    		Thread.sleep(4000);
+
+    		_esbListController.requestEnd();
+    		_gatewayController.requestEnd();    
+    		
+    		assertEquals(THE_TEXT, stringFromFile(_returnFile));
+        } 
+        catch (Exception e) { }
+    }
+	
+	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;
+	    } // ________________________________
+
+	} // ___________________________________________________
+
+	void writeGatewayConfig() throws Exception
+	{
+		StringBuilder sb = new StringBuilder()
+		.append("<JmsGateway parameterReloadSecs=\"180\">\n")
+		 .append("  <GatewayConfig\n")
+		 .append("     target-service-category=\"eprManager\"\n")
+		 .append("     target-service-name=\"").append(SERVICE_NAME).append("\"\n")
+		 .append("     gatewayClass=\"org.jboss.soa.esb.listeners.gateway.JmsGatewayListener\"\n")
+		 .append("     connection-factory=\"ConnectionFactory\"\n")
+		 .append("     destination-type=\"queue\"\n")
+		 .append("     destination-name=\"queue/A\"\n")
+		 .append("     jndi-type=\"jboss\"\n")
+		 .append("     jndi-URL=\"").append(_appServer).append("\"\n")
+		 .append("     message-selector=\"messSelector='testJmsGateway'\"\n")
+		 .append("   >\n")
+		 .append("   </GatewayConfig>\n")
+		 .append("</JmsGateway>\n")
+		 ;
+		bytesToFile(_gatewayConfig, sb.toString().getBytes());
+		_logger.info("GatewayConfiguration\n"+stringFromFile(_gatewayConfig));
+	}
+	
+	void writeEsbListenerConfig() throws Exception
+	{
+		StringBuilder sb = new StringBuilder()
+		.append("<DummyTester parameterReloadSecs=\"180\">\n")
+		.append("   <DummyActionConfig\n")
+		.append("   service-category=\"eprManager\"\n")
+		.append("	service-name=\"").append(SERVICE_NAME).append("\"\n")
+		.append("	service-description=\"My Dummy Service Name\"\n")
+		.append("	epr-description=\"EPR descriptionnnnnnnnnnnnnnn\"\n")		
+		.append("  	listenerClass=\"org.jboss.soa.esb.listeners.message.JmsQueueListener\"\n")
+		.append("	connection-factory=\"ConnectionFactory\"\n")
+		.append("	destination-type=\"queue\"\n")
+		.append("	destination-name=\"queue/A\"\n")
+		.append("	jndi-type=\"jboss\"\n")
+		.append("	jndi-URL=\"").append(_appServer).append("\"\n")
+		.append("	message-selector=\"service='testJmsGateway'\"\n")
+		.append("	>\n")
+		.append("	   <action class=\"").append(MockMessageAwareAction.class.getName()).append("\" process=\"writeToDisk\" />\n")
+		.append("   </DummyActionConfig>\n")
+		.append("</DummyTester>\n")
+		;
+		bytesToFile(_esbListenerConfig, sb.toString().getBytes());
+		_logger.info("EsbListenerConfiguration\n"+stringFromFile(_esbListenerConfig));
+	}
+	
+	static void bytesToFile(File file, byte[] text) throws Exception
+	{
+		OutputStream out = new FileOutputStream(file);
+		out.write(text);
+		out.close();
+	}
+
+	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();
+	}
+	void sendJmsMessage(String text) throws Exception
+	{
+		ConfigTree tree = ConfigTree.fromInputStream(new FileInputStream(_gatewayConfig))
+				.getAllChildren()[0];
+        String sJndiType = tree.getAttribute(JMSEpr.JNDI_TYPE_TAG);
+        String sJndiURL = _appServer;
+        Context oJndiCtx = AppServerContext.getServerContext(sJndiType,sJndiURL);
+        String sFactoryClass = tree.getAttribute(JMSEpr.CONNECTION_FACTORY_TAG);
+        if (Util.isNullString(sFactoryClass))
+        	sFactoryClass = "ConnectionFactory";        
+        Object tmp = oJndiCtx.lookup(sFactoryClass);
+        
+        String sQname = tree.getAttribute(JMSEpr.DESTINATION_NAME_TAG);
+        javax.jms.Queue queue = (javax.jms.Queue) oJndiCtx.lookup(sQname);
+        QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+        QueueConnection qConn = qcf.createQueueConnection();
+        QueueSession qSess = qConn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
+        javax.jms.Message jMess = qSess.createTextMessage(THE_TEXT);
+        String[] sa = tree.getAttribute(JMSEpr.MESSAGE_SELECTOR_TAG).split("=");
+        // strip apostrophes
+        String sVal = sa[1].substring(1).substring(0,-2+sa[1].length());
+        jMess.setStringProperty(sa[0],sVal);
+        MessageProducer producer = qSess.createProducer(queue);
+
+        producer.send(jMess);
+        
+		if (null != producer)
+			try { producer.close(); }
+			catch (JMSException e) {/*  OK do nothing  */ }
+		if (null != qSess)
+			try { qSess.close(); }
+			catch (JMSException e) {/*  OK do nothing  */ }
+		if (null != qConn)
+			try { qConn.close(); }
+			catch (JMSException e) {/*  OK do nothing  */ }
+        
+    } //________________________________
+
+}




More information about the jboss-svn-commits mailing list