[jboss-svn-commits] JBL Code SVN: r14315 - in labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb: persistence/actions and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Aug 16 13:03:54 EDT 2007


Author: kurt.stam at jboss.com
Date: 2007-08-16 13:03:54 -0400 (Thu, 16 Aug 2007)
New Revision: 14315

Added:
   labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreUnitTest.java
   labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/persistence/actions/MessagePersisterUnitTest.java
Removed:
   labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreTest.java
   labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/persistence/actions/MessagePersisterTest.java
Modified:
   labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreClient.java
Log:
JBESB-838, renaming to UnitTest

Modified: labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreClient.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreClient.java	2007-08-16 16:50:26 UTC (rev 14314)
+++ labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreClient.java	2007-08-16 17:03:54 UTC (rev 14315)
@@ -39,7 +39,7 @@
 public class MessageStoreClient implements Runnable
 {
 
-	private static Logger logger = Logger.getLogger(MessageStoreTest.class);
+	private static Logger logger = Logger.getLogger(MessageStoreUnitTest.class);
 
 	public void run ()
 	{

Deleted: labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreTest.java	2007-08-16 16:50:26 UTC (rev 14314)
+++ labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreTest.java	2007-08-16 17:03:54 UTC (rev 14315)
@@ -1,159 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated 
- * by the @authors tag. All rights reserved. 
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors. 
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A 
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
- * MA  02110-1301, USA.
- * 
- * (C) 2005-2006,
- * @author daniel.brum at jboss.com
- */
-
-package org.jboss.soa.esb.messagestore;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.net.URI;
-import java.sql.Connection;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.xml.DOMConfigurator;
-import org.jboss.internal.soa.esb.persistence.format.MessageStoreFactory;
-import org.jboss.soa.esb.common.Configuration;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageFactory;
-import org.jboss.soa.esb.message.format.MessageType;
-import org.jboss.soa.esb.persistence.manager.ConnectionManager;
-import org.jboss.soa.esb.persistence.manager.ConnectionManagerFactory;
-import org.jboss.soa.esb.services.persistence.MessageStore;
-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;
-
-/**
- * @author dbrum
- *
- */
-public class MessageStoreTest  {
-	private static Logger logger = Logger.getLogger(MessageStoreTest.class);
-
-    
-	@Test
-	public void testMultiClientLoad() throws Exception {
-		int clients = 5;
-		Thread[] xx = new Thread[clients];
-		for (int i=0; i<clients; i++) {
-			xx[i] = new Thread(new MessageStoreClient());
-		}
-		for (int i=0; i<clients; i++) {
-			xx[i].start();
-		}
-		//clean up the threads
-		for (int i=0; i<clients; i++) {
-			xx[i] = null;
-		}
-	}
-	
-	@Test
-	public void testSingleLoad() throws Exception {
-		long startTime=System.currentTimeMillis();
-		int requestors = 1000;	//number of persist calls to make
-		List<URI> uriList = new ArrayList<URI>();
-		//get the database store
-		MessageStore store = MessageStoreFactory.getInstance().getMessageStore();
-		//messages to persist
-		Message msg[] = { MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML), 
-						 MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED)};		
-		//set some content inside the Messages
-		for (int x=0; x<msg.length; x++) {
-			msg[x].getBody().setByteArray("TEST BODY".getBytes());
-			msg[x].getProperties().setProperty("prop"+x, "val"+x);
-			msg[x].getAttachment().addItem(new String("TEST ATTACHMENT"));						
-		}
-		//loop through adding the messages
-		Random rndMsg = new Random();
-		for (int x=0; x<=requestors; x++) {
-			URI uid = store.addMessage(msg[rndMsg.nextInt(2)], MessageStore.CLASSIFICATION_DEFAULT);	
-			if (uid == null) 
-				System.out.println("null returned from addMessage() call to uid");
-			else
-				uriList.add(uid);
-		}
-		logger.info("total messages persisted to db: " + (uriList.size()-1));
-		//loop back reading the messages from the db
-		List<Message> messages = new ArrayList<Message>();
-		for (int x=0; x<uriList.size(); x++) {
-			messages.add(store.getMessage(uriList.get(x)));
-		}
-		logger.info("total messages read from db: " + (uriList.size()));
-		logger.info("time to finish write/read for this client: " + (System.currentTimeMillis() - startTime) + " milliseconds.");
-	}
-	
-    @BeforeClass
-    public static void runBeforeAllTests()
-    {
-        try {
-            File testResourceDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/src/test/resources/");
-            System.out.println("Current dir=" + testResourceDir.getCanonicalPath());
-            DOMConfigurator.configure(testResourceDir.getCanonicalPath() + "/log4j.xml");
-            File buildDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/build/");
-            File resourceDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/src/main/resources/");
-            System.setProperty("org.jboss.soa.esb.propertyFile", "jbossesb-unittest-properties.xml");                    
-            if ("org.hsqldb.jdbcDriver".equals(Configuration.getStoreDriver())) {
-                HsqldbUtil.startHsqldb(buildDir + "/hsqltestdb", "jbossesb");
-                
-                //Drop what is there now, if exists. We want to start fresh.                
-                String sqlCreateCmd    = TestEnvironmentUtil.readTextFile(new File(resourceDir.getCanonicalPath() + "/message-store-sql/hsqldb/create_database.sql"));
-                String sqlDropCmd      = TestEnvironmentUtil.readTextFile(new File(resourceDir.getAbsolutePath() + "/message-store-sql/hsqldb/drop_database.sql"));
-                
-                ConnectionManager mgr = ConnectionManagerFactory.getConnectionManager();
-                mgr.init();
-                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);
-            }
-        } catch (Throwable e) {
-            e.printStackTrace();
-            System.out.println("We should stop testing, since we don't have a db.");
-            assertTrue(false);
-        }
-    }
-	
-	@AfterClass
-	public static void runAfterAllTests() throws Exception{
-		Thread.sleep(2000);
-        System.out.println("Stopping");
-		if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
-			HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
-					Configuration.getStoreUser(),Configuration.getStorePwd() );
-		}
-	}
-	
-	public static junit.framework.Test suite() {
-		return new JUnit4TestAdapter(MessageStoreTest.class);
-	}
-	
-	
-}

Copied: labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreUnitTest.java (from rev 14303, labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreTest.java)
===================================================================
--- labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/messagestore/MessageStoreUnitTest.java	2007-08-16 17:03:54 UTC (rev 14315)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.soa.esb.messagestore;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.internal.soa.esb.persistence.format.MessageStoreFactory;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.persistence.manager.ConnectionManager;
+import org.jboss.soa.esb.persistence.manager.ConnectionManagerFactory;
+import org.jboss.soa.esb.services.persistence.MessageStore;
+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;
+
+/**
+ * @author dbrum
+ *
+ */
+public class MessageStoreUnitTest  {
+	private static Logger logger = Logger.getLogger(MessageStoreUnitTest.class);
+
+    
+	@Test
+	public void testMultiClientLoad() throws Exception {
+		int clients = 5;
+		Thread[] xx = new Thread[clients];
+		for (int i=0; i<clients; i++) {
+			xx[i] = new Thread(new MessageStoreClient());
+		}
+		for (int i=0; i<clients; i++) {
+			xx[i].start();
+		}
+		//clean up the threads
+		for (int i=0; i<clients; i++) {
+			xx[i] = null;
+		}
+	}
+	
+	@Test
+	public void testSingleLoad() throws Exception {
+		long startTime=System.currentTimeMillis();
+		int requestors = 1000;	//number of persist calls to make
+		List<URI> uriList = new ArrayList<URI>();
+		//get the database store
+		MessageStore store = MessageStoreFactory.getInstance().getMessageStore();
+		//messages to persist
+		Message msg[] = { MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML), 
+						 MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED)};		
+		//set some content inside the Messages
+		for (int x=0; x<msg.length; x++) {
+			msg[x].getBody().setByteArray("TEST BODY".getBytes());
+			msg[x].getProperties().setProperty("prop"+x, "val"+x);
+			msg[x].getAttachment().addItem(new String("TEST ATTACHMENT"));						
+		}
+		//loop through adding the messages
+		Random rndMsg = new Random();
+		for (int x=0; x<=requestors; x++) {
+			URI uid = store.addMessage(msg[rndMsg.nextInt(2)], MessageStore.CLASSIFICATION_DEFAULT);	
+			if (uid == null) 
+				System.out.println("null returned from addMessage() call to uid");
+			else
+				uriList.add(uid);
+		}
+		logger.info("total messages persisted to db: " + (uriList.size()-1));
+		//loop back reading the messages from the db
+		List<Message> messages = new ArrayList<Message>();
+		for (int x=0; x<uriList.size(); x++) {
+			messages.add(store.getMessage(uriList.get(x)));
+		}
+		logger.info("total messages read from db: " + (uriList.size()));
+		logger.info("time to finish write/read for this client: " + (System.currentTimeMillis() - startTime) + " milliseconds.");
+	}
+	
+    @BeforeClass
+    public static void runBeforeAllTests()
+    {
+        try {
+            File testResourceDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/src/test/resources/");
+            System.out.println("Current dir=" + testResourceDir.getCanonicalPath());
+            DOMConfigurator.configure(testResourceDir.getCanonicalPath() + "/log4j.xml");
+            File buildDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/build/");
+            File resourceDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/src/main/resources/");
+            System.setProperty("org.jboss.soa.esb.propertyFile", "jbossesb-unittest-properties.xml");                    
+            if ("org.hsqldb.jdbcDriver".equals(Configuration.getStoreDriver())) {
+                HsqldbUtil.startHsqldb(buildDir + "/hsqltestdb", "jbossesb");
+                
+                //Drop what is there now, if exists. We want to start fresh.                
+                String sqlCreateCmd    = TestEnvironmentUtil.readTextFile(new File(resourceDir.getCanonicalPath() + "/message-store-sql/hsqldb/create_database.sql"));
+                String sqlDropCmd      = TestEnvironmentUtil.readTextFile(new File(resourceDir.getAbsolutePath() + "/message-store-sql/hsqldb/drop_database.sql"));
+                
+                ConnectionManager mgr = ConnectionManagerFactory.getConnectionManager();
+                mgr.init();
+                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);
+            }
+        } catch (Throwable e) {
+            e.printStackTrace();
+            System.out.println("We should stop testing, since we don't have a db.");
+            assertTrue(false);
+        }
+    }
+	
+	@AfterClass
+	public static void runAfterAllTests() throws Exception{
+		Thread.sleep(2000);
+        System.out.println("Stopping");
+		if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
+			HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
+					Configuration.getStoreUser(),Configuration.getStorePwd() );
+		}
+	}
+	
+	public static junit.framework.Test suite() {
+		return new JUnit4TestAdapter(MessageStoreUnitTest.class);
+	}
+	
+	
+}

Deleted: labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/persistence/actions/MessagePersisterTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/persistence/actions/MessagePersisterTest.java	2007-08-16 16:50:26 UTC (rev 14314)
+++ labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/persistence/actions/MessagePersisterTest.java	2007-08-16 17:03:54 UTC (rev 14315)
@@ -1,161 +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.persistence.actions;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URI;
-import java.sql.Connection;
-import java.sql.Statement;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.apache.log4j.xml.DOMConfigurator;
-import org.jboss.internal.soa.esb.persistence.format.MessageStoreFactory;
-import org.jboss.soa.esb.actions.MessagePersister;
-import org.jboss.soa.esb.common.Configuration;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageFactory;
-import org.jboss.soa.esb.persistence.manager.ConnectionManager;
-import org.jboss.soa.esb.persistence.manager.ConnectionManagerFactory;
-import org.jboss.soa.esb.services.persistence.MessageStore;
-import org.jboss.soa.esb.testutils.HsqldbUtil;
-import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
-import org.jboss.soa.esb.util.ClassUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Testing the MessagePersister.
- * 
- * @author <a href="mailto:kurt.stam at redhat.com">Kurt Stam</a>
- * 
- */
-public class MessagePersisterTest
-{
-	/**
-	 * Testing the MessagePersister.
-	 */
-	@Test
-	public void sendMessage()
-	{
-		try
-		{
-            Date now = new Date();
-            String body = "<message>First Message " + now + " </message>";
-            Message msg = MessageFactory.getInstance().getMessage();
-            msg.getBody().setByteArray(body.getBytes());
-            
-           
-            InputStream inputStream = ClassUtil.getResourceAsStream("MessagePersisterTest.xml", this.getClass());
-            ConfigTree config = ConfigTree.fromInputStream(inputStream);
-
-            MessagePersister persister = new MessagePersister(config);
-            persister.initialise();
-            persister.process(msg);
-            
-             //now we can check the messageStore to see if our message made it in there.
-            System.out.println("Reading the messages in the messageStore");
-            
-            MessageStore store = MessageStoreFactory.getInstance().getMessageStore();
-            Map<URI, Message> messages = store.getAllMessages("TEST");
-            messages = store.getAllMessages("TEST");
-            Iterator<Message> iter=messages.values().iterator();
-            while (iter.hasNext()) {
-                Message message=iter.next();
-                String bodyFromStore = new String(message.getBody().getByteArray());
-                System.out.println("Body=" + bodyFromStore);
-            }
-            System.out.println("Getting message for classification TEST:" + messages);
-            assertEquals(1, messages.size());
-            
-            //Now check if it is the same message
-            Message message=messages.values().iterator().next();
-            String bodyFromStore = new String(message.getBody().getByteArray());
-            assertEquals(body, bodyFromStore);
-		}
-		catch (Exception re)
-		{
-			re.printStackTrace();
-			assertTrue(false);
-		}
-	}
-
-
-	public static junit.framework.Test suite()
-	{
-		return new JUnit4TestAdapter(MessagePersisterTest.class);
-	}
-    
-    @BeforeClass
-    public static void runBeforeAllTests()
-    {
-        try {
-            File testResourceDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/src/test/resources/");
-            System.out.println("Current dir=" + testResourceDir.getCanonicalPath());
-            DOMConfigurator.configure(testResourceDir.getCanonicalPath() + "/log4j.xml");
-            File buildDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/build/");
-            File resourceDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/src/main/resources/");
-            System.setProperty("org.jboss.soa.esb.propertyFile", "jbossesb-unittest-properties.xml");                    
-            if ("org.hsqldb.jdbcDriver".equals(Configuration.getStoreDriver())) {
-                HsqldbUtil.startHsqldb(buildDir + "/hsqltestdb", "jbossesb");
-                
-                //Drop what is there now, if exists. We want to start fresh.                
-                String sqlCreateCmd    = TestEnvironmentUtil.readTextFile(new File(resourceDir.getCanonicalPath() + "/message-store-sql/hsqldb/create_database.sql"));
-                String sqlDropCmd      = TestEnvironmentUtil.readTextFile(new File(resourceDir.getAbsolutePath() + "/message-store-sql/hsqldb/drop_database.sql"));
-                
-                ConnectionManager mgr = ConnectionManagerFactory.getConnectionManager();
-                mgr.init();
-                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);
-            }
-        } catch (Throwable e) {
-            e.printStackTrace();
-            System.out.println("We should stop testing, since we don't have a db.");
-            assertTrue(false);
-        }
-        
-    }
-    
-    @AfterClass
-    public static void runAfterAllTests() throws Exception{
-        Thread.sleep(2000);
-        if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
-            HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
-                    Configuration.getStoreUser(),Configuration.getStorePwd() );
-        }
-    }
-
-}

Copied: labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/persistence/actions/MessagePersisterUnitTest.java (from rev 14303, labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/persistence/actions/MessagePersisterTest.java)
===================================================================
--- labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/persistence/actions/MessagePersisterUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/services/jbossesb/src/test/java/org/jboss/soa/esb/persistence/actions/MessagePersisterUnitTest.java	2007-08-16 17:03:54 UTC (rev 14315)
@@ -0,0 +1,161 @@
+/*
+ * 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.persistence.actions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.internal.soa.esb.persistence.format.MessageStoreFactory;
+import org.jboss.soa.esb.actions.MessagePersister;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.persistence.manager.ConnectionManager;
+import org.jboss.soa.esb.persistence.manager.ConnectionManagerFactory;
+import org.jboss.soa.esb.services.persistence.MessageStore;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Testing the MessagePersister.
+ * 
+ * @author <a href="mailto:kurt.stam at redhat.com">Kurt Stam</a>
+ * 
+ */
+public class MessagePersisterUnitTest
+{
+	/**
+	 * Testing the MessagePersister.
+	 */
+	@Test
+	public void sendMessage()
+	{
+		try
+		{
+            Date now = new Date();
+            String body = "<message>First Message " + now + " </message>";
+            Message msg = MessageFactory.getInstance().getMessage();
+            msg.getBody().setByteArray(body.getBytes());
+            
+           
+            InputStream inputStream = ClassUtil.getResourceAsStream("MessagePersisterTest.xml", this.getClass());
+            ConfigTree config = ConfigTree.fromInputStream(inputStream);
+
+            MessagePersister persister = new MessagePersister(config);
+            persister.initialise();
+            persister.process(msg);
+            
+             //now we can check the messageStore to see if our message made it in there.
+            System.out.println("Reading the messages in the messageStore");
+            
+            MessageStore store = MessageStoreFactory.getInstance().getMessageStore();
+            Map<URI, Message> messages = store.getAllMessages("TEST");
+            messages = store.getAllMessages("TEST");
+            Iterator<Message> iter=messages.values().iterator();
+            while (iter.hasNext()) {
+                Message message=iter.next();
+                String bodyFromStore = new String(message.getBody().getByteArray());
+                System.out.println("Body=" + bodyFromStore);
+            }
+            System.out.println("Getting message for classification TEST:" + messages);
+            assertEquals(1, messages.size());
+            
+            //Now check if it is the same message
+            Message message=messages.values().iterator().next();
+            String bodyFromStore = new String(message.getBody().getByteArray());
+            assertEquals(body, bodyFromStore);
+		}
+		catch (Exception re)
+		{
+			re.printStackTrace();
+			assertTrue(false);
+		}
+	}
+
+
+	public static junit.framework.Test suite()
+	{
+		return new JUnit4TestAdapter(MessagePersisterUnitTest.class);
+	}
+    
+    @BeforeClass
+    public static void runBeforeAllTests()
+    {
+        try {
+            File testResourceDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/src/test/resources/");
+            System.out.println("Current dir=" + testResourceDir.getCanonicalPath());
+            DOMConfigurator.configure(testResourceDir.getCanonicalPath() + "/log4j.xml");
+            File buildDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/build/");
+            File resourceDir = TestEnvironmentUtil.findResourceDirectory("./product/services/jbossesb/src/main/resources/");
+            System.setProperty("org.jboss.soa.esb.propertyFile", "jbossesb-unittest-properties.xml");                    
+            if ("org.hsqldb.jdbcDriver".equals(Configuration.getStoreDriver())) {
+                HsqldbUtil.startHsqldb(buildDir + "/hsqltestdb", "jbossesb");
+                
+                //Drop what is there now, if exists. We want to start fresh.                
+                String sqlCreateCmd    = TestEnvironmentUtil.readTextFile(new File(resourceDir.getCanonicalPath() + "/message-store-sql/hsqldb/create_database.sql"));
+                String sqlDropCmd      = TestEnvironmentUtil.readTextFile(new File(resourceDir.getAbsolutePath() + "/message-store-sql/hsqldb/drop_database.sql"));
+                
+                ConnectionManager mgr = ConnectionManagerFactory.getConnectionManager();
+                mgr.init();
+                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);
+            }
+        } catch (Throwable e) {
+            e.printStackTrace();
+            System.out.println("We should stop testing, since we don't have a db.");
+            assertTrue(false);
+        }
+        
+    }
+    
+    @AfterClass
+    public static void runAfterAllTests() throws Exception{
+        Thread.sleep(2000);
+        if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
+            HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
+                    Configuration.getStoreUser(),Configuration.getStorePwd() );
+        }
+    }
+
+}




More information about the jboss-svn-commits mailing list