[jboss-svn-commits] JBL Code SVN: r7370 - in labs/jbossesb/trunk: product/core/listeners/src/org/jboss/soa/esb/actions product/core/listeners/src/org/jboss/soa/esb/listeners product/core/listeners/src/org/jboss/soa/esb/listeners/message product/core/services/src/org/jboss/soa/esb/services/registry product/core/services/src/org/jboss/soa/esb/services/routing product/core/services/tests/src/org/jboss/soa/esb/services/registry qa/junit/src/org/jboss/soa/esb/actions qa/junit/src/org/jboss/soa/esb/listeners qa/junit/src/org/jboss/soa/esb/listeners/message qa/junit/src/org/jboss/soa/esb/util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Nov 3 11:51:13 EST 2006


Author: kurt.stam at jboss.com
Date: 2006-11-03 11:51:09 -0500 (Fri, 03 Nov 2006)
New Revision: 7370

Added:
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml
Removed:
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrActionTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouting.xml
Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java
   labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
   labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java
   labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/TestUtil.java
Log:
Switching the CBR over to use the real registry.

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -48,13 +48,27 @@
     public Message process(Message message) 
     {
     	_message = message;
-    	Object oCurr = ActionUtils.getTaskObject(message);
-    	if (null==oCurr)
-    		oCurr = "null";
-        _logger.info("Process was called with <<" + oCurr.toString() + ">>");
+    	//Service,
+    	//Send message to service
+    	
+        _logger.info("Process was called.");
         return message;
     } // ________________________________
 
+    
+    public Message addDestinationListToMessage(Message message) {
+    	return null;
+    }
+    
+    public Message deliverToDestinations(Message message) {
+    	return null;
+    }
+    
+    public Message route (Message message) {
+    	return null;
+    }
+    
+    
  
     public void exceptionCallback(Message message, Throwable t)
     {

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -2,8 +2,11 @@
 
 public class ListenerTagNames 
 {
-    public static final String SERVICE_CATEGORY_TAG         = "service-category";
+    public static final String SERVICE_CATEGORY_NAME_TAG    = "service-category";
 	public static final String SERVICE_NAME_TAG			    = "service-name";
+	public static final String SERVICE_DESCRIPTION_TAG      = "service-description";
+	public static final String EPR_DESCRIPTION_TAG          = "epr-description";
+	
 	public static final String TARGET_SERVICE_NAME_TAG	    = "target-service-name";
     
     public static final String ACTION_ELEMENT_TAG		    = "action";

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -28,6 +28,7 @@
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.ListenerTagNames;
 import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.registry.RegistryException;
 import org.jboss.soa.esb.services.routing.MessageRouterException;
 import org.jboss.soa.esb.services.routing.cbr.ContentBasedRouter;
 import org.jboss.soa.esb.services.routing.cbr.ContentBasedRouterFactory;
@@ -70,7 +71,7 @@
 	    	} else {
 	    		ruleSet =_config.getFirstChild(ListenerTagNames.CBR_TAG).getAttribute(ListenerTagNames.RULE_SET_TAG);
 	    	}
-	    	_controller.register(_eprName,_epr);
+	    	_controller.register(_config,_epr);
 	    	while (_controller.continueLooping()) {
 	    		long lwait = _controller.millisToWait();
 	    		Message message = (lwait > 0 ) ? receiveEsbMessage(100) : null;
@@ -90,7 +91,9 @@
 	        		}
         		}
 	        }
-	    	_controller.unRegister(_eprName);
+	    	_controller.unRegister(_eprCategoryName, _eprName, _epr);
+	    } catch (RegistryException mre) {
+		_logger.log(Priority.FATAL, mre.getLocalizedMessage(), mre);
     	} catch (MessageRouterException mre) {
 			_logger.log(Priority.FATAL, mre.getLocalizedMessage(), mre);
 		} finally {

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/EsbListenerController.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -37,8 +37,12 @@
 import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.common.ModulePropertyManager;
 import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
 import org.jboss.soa.esb.parameters.ParamRepositoryException;
 import org.jboss.soa.esb.parameters.ParamRepositoryFactory;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
 import org.jboss.soa.esb.util.Util;
 import org.xml.sax.SAXException;
 
@@ -519,6 +523,11 @@
 		return EPRManager.getInstance(sDir);
 	}
 	
+	/**
+	 * @deprecated use register (ConfigTree config, EPR address) instead.
+	 * @param name
+	 * @param address
+	 */
 	public void register (String name, EPR address)
 	{
 		try { getEprManager().saveEPR(name,address); }
@@ -527,7 +536,10 @@
 			_logger.fatal("Cannot register service",e);
 		}
 	} // ________________________________
-
+	/**
+	 * @deprecated use unRegister (String serviceCategoryName, String serviceName, EPR epr) instead.
+	 * @param name
+	 */
 	public void unRegister (String name)
 	{
 		try { getEprManager().removeEPR(name); }
@@ -536,5 +548,36 @@
 			_logger.fatal("Cannot un-register service",e);
 		}
 	} // ________________________________
+	/**
+	 * Register an EPR in the registry.
+	 * 
+	 * @param config - a config tree containing the deployment-configuration of the service.
+	 * @param epr - the epr (EndPoint Reference) of the service.
+	 * 
+	 * @throws RegistryException
+	 */
+	public void register(ConfigTree config , EPR epr) throws RegistryException
+	{
+		String serviceCategoryName = config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+		String serviceName         = config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+		String serviceDescription  = config.getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
+		String eprDescription      = config.getAttribute(ListenerTagNames.EPR_DESCRIPTION_TAG);
+		Registry registry = RegistryFactory.getRegistry();
+		registry.registerEPR(serviceCategoryName, serviceName, serviceDescription, epr, eprDescription);
+	}
+	/**
+	 * Unregister the EPR from the registry.
+	 * 
+	 * @param serviceCategoryName - name of the category of the service ('Content Based Routing')
+	 * @param serviceName         - name of the service ("
+	 * @param epr
+	 * @throws RegistryException
+	 */
+	public void unRegister(String serviceCategoryName, String serviceName , EPR epr) throws RegistryException
+	{
+		Registry registry = RegistryFactory.getRegistry();
+		registry.unRegisterEPR(serviceCategoryName, serviceName, epr);
+	}
 
+
 } // ____________________________________________________________________________

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -42,6 +42,7 @@
 import org.jboss.soa.esb.helpers.AppServerContext;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.services.registry.RegistryException;
 import org.jboss.soa.esb.util.Util;
 import org.xml.sax.SAXException;
 
@@ -81,27 +82,32 @@
      */
     public void run()
     {
-    	_controller.register(_eprName,_epr);
-
-    	while (_controller.continueLooping())
-        {
-    		long lwait = _controller.millisToWait();
-    		org.jboss.soa.esb.message.Message message = (lwait > 0 ) ? receiveEsbMessage(100) : null;
-        	if (null!=message)
-        	{	
-        		ActionProcessingPipeline chain = null;
-
-        		try	{ chain = new ActionProcessingPipeline(message,_config); }
-        		catch (IllegalArgumentException e)	
-        			{	_logger.error(e); 	continue; }
-        		catch (ConfigurationException e)
-    				{	_logger.error(e); 	continue; }
-
-        		this.pipelineExecutorPool.submit(chain);        		
-        	}
-        }
-    	_controller.unRegister(_eprName);
-    	cleanup();
+    	try {
+	    	_controller.register(_config,_epr);
+	
+	    	while (_controller.continueLooping())
+	        {
+	    		long lwait = _controller.millisToWait();
+	    		org.jboss.soa.esb.message.Message message = (lwait > 0 ) ? receiveEsbMessage(100) : null;
+	        	if (null!=message)
+	        	{	
+	        		ActionProcessingPipeline chain = null;
+	
+	        		try	{ chain = new ActionProcessingPipeline(message,_config); }
+	        		catch (IllegalArgumentException e)	
+	        			{	_logger.error(e); 	continue; }
+	        		catch (ConfigurationException e)
+	    				{	_logger.error(e); 	continue; }
+	
+	        		this.pipelineExecutorPool.submit(chain);        		
+	        	}
+	        }
+	    	_controller.unRegister(_eprCategoryName, _eprName, _epr);
+    	} catch (RegistryException re) {
+    		_logger.fatal("Could not register myself. " + re.getLocalizedMessage(),re);
+    	} finally {
+    		cleanup();
+    	}
     } // _______________________________
     
     /**
@@ -116,6 +122,7 @@
         // Default value of obtainAttribute is null - Exception will be thrown
         String sQueue	= obtainAttribute(JMSEpr.DESTINATION_NAME_TAG, null);
 
+        _eprCategoryName= obtainAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG,null);
         _eprName		= obtainAttribute(ListenerTagNames.SERVICE_NAME_TAG,null);
 
         // No problem if selector is null - everything in queue will be returned
@@ -233,6 +240,7 @@
     	return (null != sVal) ? sVal : p_sDefault;
 	} // ________________________________
 
+    protected String            _eprCategoryName;
     protected String			_eprName;
     protected JMSEpr			_epr;
     protected MessageConsumer 	_receiver;

Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -51,7 +51,7 @@
 	 * @param eprDescription	 - human readable description of the EPR
 	 * @throws RegistryException
 	 */
-	public void registerEPR(String category, String serviceName, String serviceDescription, EPR epr, String eprDescription) 
+	public void registerEPR(String serviceCategoryName, String serviceName, String serviceDescription, EPR epr, String eprDescription) 
 	throws RegistryException;
 	/**
 	 * Removes an EPR from the Registry. 

Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -32,6 +32,7 @@
  */
 public interface MessageRouter 
 {
+	String ROUTING_DESTINATION_SERVICE_LIST = "routing.destinationServiceList";
 	/**
 	 * Routes the message to the next destination. 
 	 * 

Modified: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -76,6 +76,16 @@
 			logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
 			assertTrue(false);
 		}
+		try {
+			Registry registry = RegistryFactory.getRegistry();
+			registry.registerEPR(null, SERVICE_NAME, null, 
+					epr, null);
+		} catch (RegistryException re) {
+			logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+			assertTrue(false);
+		}
+		//make sure we can handle some null arguments
+		
 	}
 	/**
 	 * This test will try to find all services in the "travel" category.

Deleted: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrActionTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrActionTest.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrActionTest.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -1,110 +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.actions;
-
-import static org.junit.Assert.assertTrue;
-import junit.framework.JUnit4TestAdapter;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.xml.DOMConfigurator;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.couriers.Courier;
-import org.jboss.soa.esb.couriers.CourierFactory;
-import org.jboss.soa.esb.listeners.message.EsbListenerController;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageFactory;
-import org.jboss.soa.esb.util.TestUtil;
-import org.junit.BeforeClass;
-import org.junit.Test;
-/**
- * Testing the Content Based  Router.
- * 
- * @author kurt.stam at redhat.com
- *
- */
-public class CbrActionTest 
-{
-	private Logger logger = Logger.getLogger(this.getClass());
-	private static EsbListenerController _proc = null;
-	private static EPR _epr = null;
-	
-	private static final String SERVICE_NAME = "ContentBasedRouterService";
-	
-	/**
-	 * Testing the Content Based Router.
-	 */
-	@Test
-	public void instantiate() 
-	{
-		try {
-			logger.info("Testing to see if we can instantiate one");
-			String deploymentConfigFile = TestUtil.getPrefix("qa") 
-				+ "junit/src/org/jboss/soa/esb/actions/ContentBasedRouting.xml";
-			_proc = new EsbListenerController(deploymentConfigFile);
-			new Thread(_proc).start();
-			// give the listener time to register
-			Thread.sleep(2000);
-//			sendOneMessage();
-			_proc.requestEnd();
-//			//give the action class time to finish
-			Thread.sleep(2000);
-//	
-			EsbListenerController.State oS = _proc.getState();
-			System.out.println("Exit state = "+oS.toString());
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-	}
-	
-	@SuppressWarnings("unused")
-	private static void sendOneMessage() throws Exception{		
-		Message msg = MessageFactory.getInstance().getMessage();
-		msg.getBody().setContents("Routing Test Body".getBytes());		
-		try {
-			_epr = EsbListenerController.getEprManager().loadEPR(SERVICE_NAME); //TODO: replace with a real registry lookup
-		}catch(Exception e) {
-			System.out.println("nobody servicing service " + SERVICE_NAME);
-			return;
-		}
-		Courier courier = CourierFactory.getCourier(_epr);
-		courier.deliver(msg);
-		
-	}
-
-	public static junit.framework.Test suite() {
-		return new JUnit4TestAdapter(CbrActionTest.class);
-	}
-	
-	@BeforeClass
-	public static void runBeforeAllTests()
-	{
-		try {
-			DOMConfigurator.configure(TestUtil.getPrefix("product") + "etc/test/resources/log4j.xml");
-			TestUtil.setESBPropertiesFileToUse("product");
-		} catch (Exception e) {
-			e.printStackTrace();
-			System.out.println("We should stop testing, since we don't have a db.");
-			assertTrue(false);
-		}
-	}
-
-}

Deleted: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouting.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouting.xml	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouting.xml	2006-11-03 16:51:09 UTC (rev 7370)
@@ -1,16 +0,0 @@
-<ContentBasedRouterTest parameterReloadSecs="180">
-   <ContentBasedRouter
-    service-category="MessageRouting"
-	service-name="ContentBasedRoutingService"
-   	listenerClass="org.jboss.soa.esb.listeners.message.CbrJmsQueueListener"
-	connection-factory="ConnectionFactory"
-	destination-type="queue"
-   	destination-name="queue/A"
-	jndi-type="jboss"
-    jndi-URL="localhost"
-    message-selector="service='ContentBasedRouting'"
-   >
-	   <cbr ruleSet="JBossESBRules.drl" />
-   </ContentBasedRouter>
-   
-</ContentBasedRouterTest>

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -0,0 +1,180 @@
+/*
+* 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.message;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+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.addressing.EPR;
+import org.jboss.soa.esb.common.tests.HsqldbUtil;
+import org.jboss.soa.esb.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.util.FileUtil;
+import org.jboss.soa.esb.util.TestUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+/**
+ * Testing the Content Based  Router.
+ * 
+ * @author kurt.stam at redhat.com
+ *
+ */
+public class CbrJmsQueueListenerTest 
+{
+	private Logger logger = Logger.getLogger(this.getClass());
+	private static EsbListenerController _proc = null;
+	private static EPR _epr = null;
+	
+	private static String mDbDriver;
+	private static String mDbUrl;
+	private static String mDbUsername;
+	private static String mDbPassword;
+	
+	private static final String SERVICE_NAME = "ContentBasedRouterService";
+	
+	/**
+	 * Testing the Content Based Router.
+	 */
+	@Test
+	public void instantiate() 
+	{
+		try {
+			logger.info("Testing to see if we can instantiate one");
+			String deploymentConfigFile = TestUtil.getPrefix("qa") 
+				+ "junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml";
+			_proc = new EsbListenerController(deploymentConfigFile);
+			new Thread(_proc).start();
+			// give the listener time to register
+			Thread.sleep(2000);
+//			sendOneMessage();
+			_proc.requestEnd();
+//			//give the action class time to finish
+			Thread.sleep(2000);
+//	
+			EsbListenerController.State oS = _proc.getState();
+			System.out.println("Exit state = "+oS.toString());
+		} catch (Exception e) {
+			assertTrue(false);
+			e.printStackTrace();
+		}
+	}
+	
+	@SuppressWarnings("unused")
+	private static void sendOneMessage() throws Exception{		
+		Message msg = MessageFactory.getInstance().getMessage();
+		msg.getBody().setContents("Routing Test Body".getBytes());		
+		try {
+			_epr = EsbListenerController.getEprManager().loadEPR(SERVICE_NAME); //TODO: replace with a real registry lookup
+		}catch(Exception e) {
+			System.out.println("nobody servicing service " + SERVICE_NAME);
+			return;
+		}
+		Courier courier = CourierFactory.getCourier(_epr);
+		courier.deliver(msg);
+		
+	}
+
+	public static junit.framework.Test suite() {
+		return new JUnit4TestAdapter(CbrJmsQueueListenerTest.class);
+	}
+	
+	@BeforeClass
+	public static void runBeforeAllTests()
+	{
+		try {
+			DOMConfigurator.configure(TestUtil.getPrefix("product") + "etc/test/resources/log4j.xml");
+			TestUtil.setESBPropertiesFileToUse("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-unittest.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(TestUtil.getPrefix("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 = TestUtil.getPrefix("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 (Exception e) {
+			e.printStackTrace();
+			System.out.println("We should stop testing, since we don't have a db.");
+			assertTrue(false);
+		}
+	}
+	
+	/**
+	 * Shutdown the database
+	 * @throws Exception
+	 */
+	@AfterClass
+	public static void runAfterAllTests() throws Exception {
+		if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+			HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+		}
+	}
+
+}

Copied: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml (from rev 7367, labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouting.xml)
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouting.xml	2006-11-03 16:12:37 UTC (rev 7367)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml	2006-11-03 16:51:09 UTC (rev 7370)
@@ -0,0 +1,17 @@
+<ContentBasedRouterTest parameterReloadSecs="180">
+   <ContentBasedRouter
+    service-category="MessageRouting"
+	service-name="ContentBasedRoutingService"
+	service-description="This CBR routs messages to different service destination based whether the messageType is XML or Serializable"
+   	listenerClass="org.jboss.soa.esb.listeners.message.CbrJmsQueueListener"
+	connection-factory="ConnectionFactory"
+	destination-type="queue"
+   	destination-name="queue/A"
+	jndi-type="jboss"
+    jndi-URL="localhost"
+    message-selector="service='ContentBasedRouting-SerializableOrXml'"
+   >
+	   <cbr ruleSet="JBossESBRules.drl" />
+   </ContentBasedRouter>
+   
+</ContentBasedRouterTest>

Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/TestUtil.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/TestUtil.java	2006-11-03 16:48:36 UTC (rev 7369)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/TestUtil.java	2006-11-03 16:51:09 UTC (rev 7370)
@@ -15,17 +15,33 @@
 	 * When performing file system interaction, the user.dir may differ (i.e. running the
 	 * tests from within eclipse).
 	 */
-	public static String getPrefix(String dir)
+	public static String getPrefix(String eclipseDir)
 	{
 		String _prefix="";
 		String baseDir = System.getProperty("user.dir");
 		log.log(Priority.INFO, baseDir);
-		if (!baseDir.endsWith(dir)) {
-			_prefix = dir + "/";
+		if (!baseDir.endsWith(eclipseDir)) {
+			_prefix = eclipseDir + "/";
 		}
 		return _prefix;
 	}
 	/**
+	 * When performing file system interaction, the user.dir may differ (i.e. running the
+	 * tests from within eclipse).
+	 */
+	public static String getPrefix(String eclipseDir, String antDir)
+	{
+		String _prefix="";
+		String baseDir = System.getProperty("user.dir");
+		log.log(Priority.INFO, baseDir);
+		if (!baseDir.endsWith(eclipseDir)) {
+			_prefix = eclipseDir + "/";
+		} else {
+			_prefix = antDir;
+		}
+		return _prefix;
+	}
+	/**
 	 * Sets the jbossesb-properties.xml to use for test
 	 */
 	public static void setESBPropertiesFileToUse(String dir)




More information about the jboss-svn-commits mailing list