[jboss-svn-commits] JBL Code SVN: r6838 - in labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/esb/persistence: . tests

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Oct 16 17:15:12 EDT 2006


Author: daniel.brum at jboss.com
Date: 2006-10-16 17:15:11 -0400 (Mon, 16 Oct 2006)
New Revision: 6838

Added:
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/esb/persistence/tests/
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java
Log:
Message Store added

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java	2006-10-16 21:15:08 UTC (rev 6837)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java	2006-10-16 21:15:11 UTC (rev 6838)
@@ -0,0 +1,166 @@
+/*
+ * 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.esb.persistence.tests;
+
+/**
+ * @author dbrum
+ *
+ *
+ */
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.internal.soa.esb.persistence.format.db.DBConnectionManager;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.tests.HsqldbUtil;
+import org.jboss.soa.esb.common.tests.TestUtil;
+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.MessageStore;
+import org.jboss.soa.esb.persistence.MessageStoreFactory;
+import org.jboss.soa.esb.persistence.format.MessageStoreType;
+import org.junit.Test;
+
+import com.arjuna.common.internal.util.propertyservice.plugins.io.XMLFilePlugin;
+import com.arjuna.common.util.exceptions.LoadPropertiesException;
+import com.arjuna.common.util.propertyservice.PropertyManager;
+import com.arjuna.common.util.propertyservice.PropertyManagerFactory;
+
+import junit.framework.TestCase;
+
+
+public class MessageStoreUnitTest extends TestCase{
+	
+//	private static Logger log = Logger.getLogger(MessageStoreUnitTest.class);
+	
+	@Test
+	public void testDefaultMessageStore() {
+		TestUtil.setESBPropertiesFileToUse();
+		MessageStoreUnitTest.runBeforeAllTests();
+		MessageStore store = MessageStoreFactory.getInstance().getMessageStore();
+		assertEquals((store != null), true);
+		MessageStoreUnitTest.runAfterAllTests();
+	}
+	
+	@Test
+	public void testURIMessageStore() {
+		TestUtil.setESBPropertiesFileToUse();
+		
+		//only DB supported for now
+		MessageStoreUnitTest.runBeforeAllTests();
+		MessageStore store1 = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
+		assertEquals((store1 != null), true);
+		MessageStoreUnitTest.runAfterAllTests();
+	}
+	
+	@Test
+	public void testStoreAndRetrieve() {
+		TestUtil.setESBPropertiesFileToUse();
+		MessageStoreUnitTest.runBeforeAllTests();
+		
+		//add new messages
+		Message msg1 = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+		Message msg2 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+		assertEquals((msg1 != null), true);
+		assertEquals((msg2 != null), true);
+		
+		MessageStore store = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
+		assertEquals((store != null), true);
+		
+		//set some properties inside the Message
+		msg1.getProperties().setProperty("prop1", "val1");
+		msg2.getProperties().setProperty("prop1", "val1");
+		msg1.getProperties().setProperty("prop2", "val2");
+		msg2.getProperties().setProperty("prop2", "val2");
+		
+		//set the body inside the Message
+		msg1.getBody().setContents(("TEST BODY").getBytes());
+		msg2.getBody().setContents(("TEST BODY").getBytes());
+		
+		//set some object attachments inside the Message
+		msg1.getAttachment().addItem(new String("TEST ATTACHMENT1"));
+		msg1.getAttachment().addItem(new String("TEST ATTACHMENT2"));		
+		msg2.getAttachment().addItem(new String("TEST ATTACHMENT1"));
+		msg2.getAttachment().addItem(new String("TEST ATTACHMENT2"));
+		
+		//keep track of the UID to use in retrieving the Message
+		String uid1=null;		
+		uid1 = store.addMessage(msg1);
+		System.out.println(uid1);
+		assertEquals((uid1 != null), true);
+		
+		String uid2 = null;
+		uid2 = store.addMessage(msg2);
+		System.out.println(uid2);
+		assertEquals((uid2 != null), true);
+		
+		//now retrieve the messages		
+		try {
+			Message msgIn1 = store.getMessage(uid1);			
+			assertEquals((msgIn1 != null), true);
+			
+			Message msgIn2 = store.getMessage(uid2);
+			assertEquals((msgIn2 != null), true);
+		} catch (Exception e) {			
+			e.printStackTrace();
+		}
+		
+		MessageStoreUnitTest.runAfterAllTests();
+	}
+	
+	@Test
+	public void testDBConnectionManager() {
+		TestUtil.setESBPropertiesFileToUse();
+		MessageStoreUnitTest.runBeforeAllTests();
+		MessageStore store = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
+		assertEquals((store != null), true);		
+		DBConnectionManager mgr = DBConnectionManager.getInstance();
+		assertEquals((mgr != null), true);
+		MessageStoreUnitTest.runAfterAllTests();
+	}	
+		
+	
+	private static void runBeforeAllTests() {
+		TestUtil.setESBPropertiesFileToUse();				
+		try {			
+			if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
+				HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "create_database.sql", "jbossesb");
+			}
+		} catch (Exception e) {			// 
+			e.printStackTrace();
+		}
+	}
+	
+	private static void runAfterAllTests() {		
+		try {			
+			HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
+					Configuration.getStoreUser(),Configuration.getStorePwd() );
+		} catch (Exception e) {			// 
+			e.printStackTrace();
+		}
+	}	
+
+}




More information about the jboss-svn-commits mailing list