[jboss-svn-commits] JBL Code SVN: r8480 - labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Dec 21 02:09:58 EST 2006


Author: estebanschifman
Date: 2006-12-21 02:09:56 -0500 (Thu, 21 Dec 2006)
New Revision: 8480

Added:
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.java
   labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml
Log:
QA test for new CbrListener class

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.java	2006-12-21 07:08:38 UTC (rev 8479)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.java	2006-12-21 07:09:56 UTC (rev 8480)
@@ -0,0 +1,207 @@
+/*
+* 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.FileInputStream;
+import java.io.InputStream;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.Iterator;
+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.couriers.Courier;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierFactory;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerManager;
+import org.jboss.soa.esb.listeners.ListenerUtil;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+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.services.routing.MessageRouter;
+import org.jboss.soa.esb.testutils.FileUtil;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+/**
+ * Testing the Content Based  Router.
+ * 
+ * @author <a href="mailto:kurt.stam at redhat.com">Kurt Stam</a>
+ * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
+ * @since Version 4.0
+ *
+ */
+public class CbrListenerTest 
+{
+	private static Logger logger = Logger.getLogger(CbrListenerTest.class);
+	private static ListenerManager _proc = null;
+	
+	
+	private static String mDbDriver;
+	private static String mDbUrl;
+	private static String mDbUsername;
+	private static String mDbPassword;
+	
+	private static final String SERVICE_CATEGORY_NAME = "MessageRouting";
+	private static final String SERVICE_NAME = "ContentBasedRouterService";
+	
+	/**
+	 * Testing the Content Based Router.
+	 */
+	@Test
+	public void sendMessages()
+	{
+		try {
+			sendMessage("First Message");
+			//The second time the rulesEngine should be primed.
+			sendMessage("Second Message");
+		} catch (RegistryException re) {
+			re.printStackTrace();
+			assertTrue(false);
+		} catch (CourierException ce) {
+			ce.printStackTrace();
+			assertTrue(false);
+		}
+	}
+	/**
+	 * Sends a message to the CbrJmsQueueListener.
+	 * 
+	 * @param body - a String containing the body of the message.
+	 * @throws Exception
+	 */
+	private static void sendMessage(String body) throws RegistryException, CourierException{		
+		Message msg = MessageFactory.getInstance().getMessage();
+		msg.getBody().setContents(body.getBytes());
+		msg.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
+		Registry registry = RegistryFactory.getRegistry();
+		Collection<EPR> eprs = registry.findEPRs(SERVICE_CATEGORY_NAME, SERVICE_NAME);
+		for (Iterator<EPR> eprIterator=eprs.iterator();eprIterator.hasNext();){
+			//Just use the first EPR in the list.
+			EPR epr = eprIterator.next();
+			Courier courier = CourierFactory.getCourier(epr);
+			courier.deliver(msg);
+			break;
+		}
+	}
+
+	public static junit.framework.Test suite() {
+		return new JUnit4TestAdapter(CbrListenerTest.class);
+	}
+	
+	@BeforeClass
+	public static void runBeforeAllTests()
+	{
+		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);
+			
+			//Now we can bring up the ContentBasedRouter
+			String deploymentConfigFile = TestEnvironmentUtil.getUserDir("qa")
+				+ "junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml";
+			ConfigTree tree = ConfigTree.fromInputStream(new FileInputStream(deploymentConfigFile));
+			_proc = ListenerUtil.launchManager(tree, true);
+			_proc.waitUntilReady();
+			logger.info("Testing to see if we can instantiate and start ListenerManager");
+		} catch (Throwable 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 {
+		//Increase Sleep for debugging
+		_proc.requestEnd();
+        //Give the controller time to finish
+		Thread.sleep(2000);
+		
+		System.out.println("ListenerManager:  Exit state = "+_proc.getState());
+
+		if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+			HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+		}
+	}
+
+}

Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml	2006-12-21 07:08:38 UTC (rev 8479)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml	2006-12-21 07:09:56 UTC (rev 8480)
@@ -0,0 +1,46 @@
+<!-- 
+/*
+ * 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.
+ */ 
+ -->
+
+<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.CbrListener"
+   >
+	   <EPR
+	    protocol="jms"
+		connection-factory="ConnectionFactory"
+		destination-type="queue"
+	   	destination-name="queue/A"
+		jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
+		jndi-URL="localhost"
+	    message-selector="service='CBRouting-SerializableOrXml'"
+	   />
+
+	   <cbr ruleSet="JBossESBRules.drl" />
+
+   </ContentBasedRouter>
+   
+</ContentBasedRouterTest>




More information about the jboss-svn-commits mailing list