[jboss-svn-commits] JBL Code SVN: r7431 - labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Nov 7 13:19:30 EST 2006


Author: daniel.brum at jboss.com
Date: 2006-11-07 13:19:28 -0500 (Tue, 07 Nov 2006)
New Revision: 7431

Added:
   labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/TestLauncher.java
Log:
refactoring

Copied: labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/TestLauncher.java (from rev 7430, labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/MockLauncher.java)
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/MockLauncher.java	2006-11-07 18:18:47 UTC (rev 7430)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/util/TestLauncher.java	2006-11-07 18:19:28 UTC (rev 7431)
@@ -0,0 +1,95 @@
+package org.jboss.soa.esb.samples.trailblazer.util;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.Statement;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.persistence.format.db.DBConnectionManager;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.Configuration;
+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.messagestore.HsqldbUtil;
+import org.jboss.soa.esb.common.tests.TestUtil;
+
+
+public class TestLauncher {
+	
+	private static EsbListenerController _proc = null;
+	private static EPR _epr = null;
+	
+	private static final String SERVICE_NAME = "LoanRequestService";
+	
+	@SuppressWarnings("unused")
+	private static Logger _logger = Logger.getLogger(TestLauncher.class);
+	
+	public static void main (String args[]) throws Exception {
+		TestLauncher.runBeforeAllTests();
+		triggerListener("/home/dbrum/dev/jbossesb/product/samples/trailblazer2/esb/conf/loanbroker-esb.xml");
+		// 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());
+		TestLauncher.runAfterAllTests();
+	}
+	
+	private static void triggerListener(String paramFile) throws Exception {
+		_proc = new EsbListenerController(paramFile);
+		new Thread(_proc).start();
+	}
+		
+	private static void sendOneMessage() throws Exception{		
+		Message msg = MessageFactory.getInstance().getMessage();
+		msg.getBody().setContents("Foooooooooooooo".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);
+		
+	}
+	
+protected static void runBeforeAllTests() throws Exception{
+TestUtil.setESBPropertiesFileToUse();
+							
+	if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
+		HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "build/hsqltestdb", "jbossesb");
+		//Get the registry-schema create scripts
+		String database = "hsqldb";
+		String sqlDir = TestUtil.getPrefix() + "install/message-store/sql/" + database + "/";
+		//Drop what is there now, if exists. We want to start fresh.				
+		String sqlCreateCmd    = TestUtil.readTextFile(new File(sqlDir + "create_database.sql"));
+		String sqlDropCmd      = TestUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
+		
+		DBConnectionManager mgr = DBConnectionManager.getInstance();
+		Connection con = mgr.getConnection();
+		Statement stmnt = con.createStatement();
+		System.out.println("Dropping the schema if exist");
+		stmnt.execute(sqlDropCmd);
+		System.out.println("Creating the message store schema");
+		stmnt.execute(sqlCreateCmd);
+	}
+		
+	}
+	
+	private static void runAfterAllTests() throws Exception{
+		
+		if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
+			HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
+					Configuration.getStoreUser(),Configuration.getStorePwd() );
+		}
+	}
+
+}




More information about the jboss-svn-commits mailing list