[jboss-svn-commits] JBL Code SVN: r7362 - 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/internal/soa/esb/services/routing/cbr 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/messagestore 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 08:31:22 EST 2006
Author: kurt.stam at jboss.com
Date: 2006-11-03 08:31:17 -0500 (Fri, 03 Nov 2006)
New Revision: 7362
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
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
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/TestUtil.java
Removed:
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/TestUtil.java
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/message/CbrJmsQueueListener.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/internal/soa/esb/services/routing/cbr/JBossRulesRouter.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/messagestore/MessageStoreTest.java
Log:
Addding CBR qa test
Added: 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 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.log4j.Logger;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.helpers.*;
+import org.jboss.soa.esb.notification.*;
+
+
+/**
+ * Action proxy to call the Content Based Router.
+ *
+ * @author kstam at redhat.com
+ *
+ */
+public class CbrProxyAction
+{
+
+ private static Logger _logger = Logger.getLogger(CbrProxyAction.class);
+
+ protected Message _message;
+ protected ConfigTree _config;
+
+ public CbrProxyAction(ConfigTree config) { _config = config; }
+ public Message noOperation(Message message) { return message; }
+
+ 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() + ">>");
+ return message;
+ } // ________________________________
+
+
+ public void exceptionCallback(Message message, Throwable t)
+ {
+ String sMsg = new StringBuilder(" ExceptionTrower.exceptionCallback CALLED ")
+ .append(_message)
+ .toString();
+ _logger.fatal(sMsg,t);
+ @SuppressWarnings("unused")
+ NotificationList nl = ActionUtils.getNotifyList(_config,"err");
+ // Here you can send notifications to everybody
+ }
+
+ public void okMethod(Message message){
+ //Do something with the callBack info
+ }
+
+} // ____________________________________________________________________________
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 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -2,6 +2,7 @@
public class ListenerTagNames
{
+ public static final String SERVICE_CATEGORY_TAG = "service-category";
public static final String SERVICE_NAME_TAG = "service-name";
public static final String TARGET_SERVICE_NAME_TAG = "target-service-name";
@@ -10,10 +11,12 @@
public static final String PROCESS_METHOD_TAG = "process";
public static final String NORMAL_COMPLETION_METHOD_TAG = "okMethod";
public static final String EXCEPTION_METHOD_TAG = "exceptionMethod";
- public static final String HTTP_ROUTER_ROUTE_URL = "routeUrl";
+ public static final String HTTP_ROUTER_ROUTE_URL = "routeUrl";
+
/** Content Based Routing */
- public static final String CBR = "cbr";
+ public static final String CBR_TAG = "cbr";
/** RuleSet reference (Filename) */
- public static final String RULE_SET = "ruleSet";
+ public static final String RULE_SET_TAG = "ruleSet";
+
}
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 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -60,28 +60,41 @@
*/
public void run()
{
- _controller.register(_eprName,_epr);
- while (_controller.continueLooping()) {
- long lwait = _controller.millisToWait();
- Message message = (lwait > 0 ) ? receiveEsbMessage(100) : null;
- if (null!=message) {
- try {
- _logger.log(Priority.INFO, "Invoking the Content Based Router");
- String ruleSet=null;
- ContentBasedRouter cbr =ContentBasedRouterFactory.getRouter();
- if (_config.getFirstChild(ListenerTagNames.CBR)!=null) {
- ruleSet=_config.getFirstChild(ListenerTagNames.CBR).getAttribute(ListenerTagNames.RULE_SET);
- cbr.route(ruleSet, message);
+ try {
+ ContentBasedRouter cbr =ContentBasedRouterFactory.getRouter();
+ String ruleSet=null;
+ if (_config.getFirstChild(ListenerTagNames.CBR_TAG)==null ||
+ (_config.getFirstChild(ListenerTagNames.CBR_TAG).getAttribute(ListenerTagNames.RULE_SET_TAG)==null)) {
+ _logger.debug("No " + ListenerTagNames.CBR_TAG + " child element was found in " + _config.getName()
+ + ". Assuming the ruleSet will be passed in via the Message");
+ } else {
+ ruleSet =_config.getFirstChild(ListenerTagNames.CBR_TAG).getAttribute(ListenerTagNames.RULE_SET_TAG);
+ }
+ _controller.register(_eprName,_epr);
+ while (_controller.continueLooping()) {
+ long lwait = _controller.millisToWait();
+ Message message = (lwait > 0 ) ? receiveEsbMessage(100) : null;
+ if (null!=message) {
+ if (ruleSet!=null) {
+ _logger.log(Priority.DEBUG, "Sending message to the Content Based Router.");
+ cbr.route(ruleSet, message);
} else {
- _logger.log(Priority.ERROR, "Configuration exception, could not find cbr element " +
- " in the Content Based Routing configuration");
+ //TODO allow for getting the ruleSet from the message and not from the configuration
+ //String messageRuleSet = message.getRuleSet();
+ String messageRuleset=null;
+ if (messageRuleset!=null) {
+ cbr.route(messageRuleset, message);
+ } else {
+ _logger.log(Priority.ERROR, "Ruleset could not be obtained from the message.");
+ }
}
- } catch (MessageRouterException mre) {
- _logger.log(Priority.ERROR, mre.getLocalizedMessage(), mre);
}
- }
- }
- _controller.unRegister(_eprName);
- cleanup();
+ }
+ _controller.unRegister(_eprName);
+ } catch (MessageRouterException mre) {
+ _logger.log(Priority.FATAL, mre.getLocalizedMessage(), mre);
+ } finally {
+ cleanup();
+ }
}
}
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 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -225,6 +225,7 @@
protected String obtainAttribute(String p_sAtt, String p_sDefault)
throws ConfigurationException
{
+ _logger.info("Reading value for " + p_sAtt);
String sVal = _config.getAttribute(p_sAtt);
if ((null == sVal) && (null == p_sDefault))
throw new ConfigurationException("Missing or invalid <" + p_sAtt + "> attribute");
@@ -232,8 +233,6 @@
return (null != sVal) ? sVal : p_sDefault;
} // ________________________________
- protected EsbListenerController _controller;
- protected ConfigTree _config;
protected String _eprName;
protected JMSEpr _epr;
protected MessageConsumer _receiver;
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2006-11-03 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -96,16 +96,16 @@
}
}
if (isSent==false) {
- logger.log(Priority.ERROR, "Could not find any valid EPRs. Message is not routed");
+ logger.log(Priority.ERROR, "Could not find any valid EPRs. Message is not routed.");
//Route to /dev/null?
}
} catch (RegistryException re) {
- logger.log(Priority.ERROR, "Could not obtain an EPR from the Registry. Message is not routed" + re.getLocalizedMessage(), re);
+ logger.log(Priority.ERROR, "Could not obtain an EPR from the Registry. Message is not routed. " + re.getLocalizedMessage(), re);
//Route to /dev/null?
}
}
} catch (Exception e) {
- logger.log(Priority.ERROR, e.getMessage() + ". Message is not routed", e);
+ logger.log(Priority.ERROR, e.getMessage() + ". Message is not routed.", e);
//Route to /dev/null?
}
return destinationServices;
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 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -150,7 +150,7 @@
* @throws Exception
*/
@BeforeClass
- public static void runBeforeAllTests() throws Exception {
+ public static void runBeforeAllTests() {
try {
DOMConfigurator.configure(TestUtil.getPrefix() + "etc/test/resources/log4j.xml");
TestUtil.setESBPropertiesFileToUse();
Added: 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 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrActionTest.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -0,0 +1,110 @@
+/*
+* 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);
+ }
+ }
+
+}
Added: 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 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouting.xml 2006-11-03 13:31:17 UTC (rev 7362)
@@ -0,0 +1,16 @@
+<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>
Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreTest.java 2006-11-03 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/MessageStoreTest.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -40,6 +40,7 @@
import org.jboss.soa.esb.message.format.MessageType;
import org.jboss.soa.esb.services.persistence.MessageStore;
import org.jboss.soa.esb.services.persistence.MessageStoreFactory;
+import org.jboss.soa.esb.util.TestUtil;
/**
* @author dbrum
@@ -49,7 +50,7 @@
private static Logger logger = Logger.getLogger(MessageStoreTest.class);
public void testMultiClientLoad() throws Exception {
- TestUtil.setESBPropertiesFileToUse();
+ TestUtil.setESBPropertiesFileToUse("product");
MessageStoreTest.runBeforeAllTests();
int clients = 5;
@@ -76,7 +77,7 @@
List<URI> uriList = new ArrayList<URI>();
- TestUtil.setESBPropertiesFileToUse();
+ TestUtil.setESBPropertiesFileToUse("product");
MessageStoreTest.runBeforeAllTests();
//get the database store
@@ -123,13 +124,13 @@
protected static void runBeforeAllTests() throws Exception{
- TestUtil.setESBPropertiesFileToUse();
+ TestUtil.setESBPropertiesFileToUse("product");
if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
- HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "build/hsqltestdb", "jbossesb");
+ HsqldbUtil.startHsqldb(TestUtil.getPrefix("product") + "build/hsqltestdb", "jbossesb");
//Get the registry-schema create scripts
String database = "hsqldb";
- logger.info("TestUtil.getPrefixForQA() returns: " + TestUtil.getPrefixForQA());
- String sqlDir = "../" + TestUtil.getPrefixForQA() + "install/message-store/sql/" + database + "/";
+ logger.info("TestUtil.getPrefixForQA() returns: " + TestUtil.getPrefix("product"));
+ String sqlDir = "../" + TestUtil.getPrefix("product") + "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"));
Deleted: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/TestUtil.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/TestUtil.java 2006-11-03 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/messagestore/TestUtil.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -1,65 +0,0 @@
-package org.jboss.soa.esb.messagestore;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.Priority;
-
-public class TestUtil
-{
- private static Logger log = Logger.getLogger(TestUtil.class);
- private static String _prefix=null;
- /**
- * When performing file system interaction, the user.dir may differ (i.e. running the
- * tests from within eclipse).
- */
- public static String getPrefix()
- {
- if (_prefix==null) {
- _prefix="";
- String baseDir = System.getProperty("user.dir");
- log.log(Priority.INFO, baseDir);
- if (!baseDir.endsWith("product")) {
- _prefix = "product/";
- }
- }
- return _prefix;
- }
-
- public static String getPrefixForQA()
- {
- if (_prefix==null) {
- _prefix="";
- String baseDir = System.getProperty("user.dir");
- log.info("user.dir = " + System.getProperty("user.dir"));
- log.log(Priority.INFO, baseDir);
- }
- return _prefix;
- }
- /**
- * Sets the jbossesb-properties.xml to use for test
- */
- public static void setESBPropertiesFileToUse()
- {
-
-// String jbossesbPropertiesFile = getPrefix() + "etc/test/resources/jbossesb-unittest-properties.xml";
- String jbossesbPropertiesFile = "jbossesb-unittest-properties.xml";
- System.setProperty("org.jboss.soa.esb.propertyFile", jbossesbPropertiesFile);
- }
-
- public static String readTextFile(File file) throws IOException
- {
- StringBuffer sb = new StringBuffer(1024);
- BufferedReader reader = new BufferedReader(new FileReader(file.getPath()));
- char[] chars = new char[1];
- while( (reader.read(chars)) > -1){
- sb.append(String.valueOf(chars));
- chars = new char[1];
- }
- reader.close();
- return sb.toString();
- }
-}
Added: 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 11:46:47 UTC (rev 7361)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/TestUtil.java 2006-11-03 13:31:17 UTC (rev 7362)
@@ -0,0 +1,51 @@
+package org.jboss.soa.esb.util;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+
+public class TestUtil
+{
+ private static Logger log = Logger.getLogger(TestUtil.class);
+ /**
+ * When performing file system interaction, the user.dir may differ (i.e. running the
+ * tests from within eclipse).
+ */
+ public static String getPrefix(String dir)
+ {
+ String _prefix="";
+ String baseDir = System.getProperty("user.dir");
+ log.log(Priority.INFO, baseDir);
+ if (!baseDir.endsWith(dir)) {
+ _prefix = dir + "/";
+ }
+ return _prefix;
+ }
+ /**
+ * Sets the jbossesb-properties.xml to use for test
+ */
+ public static void setESBPropertiesFileToUse(String dir)
+ {
+ //Set the jbossesb properties file in System, so we can pick up the one for testing
+ String jbossesbPropertiesFile = getPrefix(dir) + "etc/test/resources/jbossesb-unittest-properties.xml";
+ System.setProperty("org.jboss.soa.esb.propertyFile", jbossesbPropertiesFile);
+ }
+
+ public static String readTextFile(File file) throws IOException
+ {
+ StringBuffer sb = new StringBuffer(1024);
+ BufferedReader reader = new BufferedReader(new FileReader(file.getPath()));
+ char[] chars = new char[1];
+ while( (reader.read(chars)) > -1){
+ sb.append(String.valueOf(chars));
+ chars = new char[1];
+ }
+ reader.close();
+ return sb.toString();
+ }
+
+}
More information about the jboss-svn-commits
mailing list