[jboss-svn-commits] JBL Code SVN: r13409 - in labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb: persistence and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 12 14:01:52 EDT 2007


Author: tcunning
Date: 2007-07-12 14:01:52 -0400 (Thu, 12 Jul 2007)
New Revision: 13409

Added:
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/manager/
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/manager/ConnectionManagerFactoryUnitTest.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/manager/ConnectionManagerUnitTest.java
Log:
bug:JBESB-563
Adding unit tests for Connection Managers and Connection Manager Factory.


Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/manager/ConnectionManagerFactoryUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/manager/ConnectionManagerFactoryUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/manager/ConnectionManagerFactoryUnitTest.java	2007-07-12 18:01:52 UTC (rev 13409)
@@ -0,0 +1,114 @@
+/*
+ * 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.manager;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.persistence.manager.ConnectionManager;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.common.tests.MockDataSource;
+import org.mockejb.jndi.MockContextFactory;
+
+/**
+ * Test of the ConnectionManagerFactory - test whether it throws exceptions
+ * correctly and whether it can successfully instantiate a ConnectionManagerFactory
+ * instance.
+ * 
+ * @author tcunning at redhat.com
+ */
+public class ConnectionManagerFactoryUnitTest extends BaseTest {
+    private static final String TEST_STRING = "test0123456789";
+    private static final Logger logger = Logger.getLogger(ConnectionManagerFactoryUnitTest.class);
+	
+	protected void setUp() throws Exception {
+        MockContextFactory.setAsInitial();
+    }
+	
+	
+	public void testFactory() {
+		Context ctx = null;
+		com.arjuna.common.util.propertyservice.PropertyManager pm = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE);
+		pm.setProperty(Environment.MSG_STORE_DB_DATASOURCE_NAME, "blah");
+		
+        // Grab the connection created and do a simple Query - we expect a result
+    	try {
+    		ctx = new InitialContext();
+    		MockDataSource mds = new MockDataSource(this);
+    		String dataSourcename = Configuration.getStoreDBDatasourceName();
+    		ctx.rebind(dataSourcename, mds);
+
+    	} catch (NamingException e) {
+			logger.debug("", e);
+    		fail(e.getMessage());
+    	} catch (Exception e) {
+			logger.debug("", e);
+    		fail(e.getMessage());		
+    	}
+		
+		try {
+			ConnectionManager cmf = ConnectionManagerFactory.getConnectionManager();
+			if (cmf == null) {
+				fail ("ConnectionManager returned should not be null.");
+			}
+		} catch (ConnectionManagerException e) {
+			logger.debug("", e);
+			fail(e.getMessage());
+		}		
+	}
+	
+	
+	public void testExceptions() {
+		Context ctx = null;
+		com.arjuna.common.util.propertyservice.PropertyManager pm = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE);
+		pm.setProperty(Environment.MSG_STORE_DB_DATASOURCE_NAME, TEST_STRING);
+		pm.setProperty(Environment.MSG_STORE_DB_CONN_MANAGER, TEST_STRING);
+   
+		// Grab the connection created and do a simple Query - we expect a result
+    	try {
+    		ctx = new InitialContext();
+    		MockDataSource mds = new MockDataSource(this);
+    		String dataSourcename = Configuration.getStoreDBDatasourceName();
+    		ctx.rebind(dataSourcename, mds);
+    		
+    	} catch (NamingException e) {
+			logger.debug("", e);
+    		fail(e.getMessage());
+    	} catch (Exception e) {
+			logger.debug("", e);
+    		fail(e.getMessage());		
+    	}
+		
+		try {
+			@SuppressWarnings("unused")
+			ConnectionManager cmf = ConnectionManagerFactory.getConnectionManager();
+			fail("Fake ConnectionManager class name should have thrown an exception");
+		} catch (ConnectionManagerException e) {
+		}		
+	}
+}

Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/manager/ConnectionManagerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/manager/ConnectionManagerUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/persistence/manager/ConnectionManagerUnitTest.java	2007-07-12 18:01:52 UTC (rev 13409)
@@ -0,0 +1,126 @@
+/*
+ * 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
+ *  */
+package org.jboss.soa.esb.persistence.manager;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.persistence.manager.ConnectionManager;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.common.tests.BaseTest;
+import org.jboss.soa.esb.common.tests.MockDataSource;
+import org.mockejb.jndi.MockContextFactory;
+
+/**
+ * Test the Standalone and the J2EE Connection Managers.
+ * @author tcunning at redhat.com
+ */
+public class ConnectionManagerUnitTest extends BaseTest {
+    private static final String JEE_CONNECTIONMGR_CLASS = "org.jboss.soa.esb.persistence.manager.J2eeConnectionManager";
+    private static final String STANDALONE_CONNECTIONMGR_CLASS = "org.jboss.soa.esb.persistence.manager.StandaloneConnectionManager";
+    private static final Logger logger = Logger.getLogger(ConnectionManagerFactoryUnitTest.class);
+	
+	protected void setUp() throws Exception {
+        MockContextFactory.setAsInitial();
+    }
+	
+	public void testJ2EEConnectionManager() {
+		Context ctx = null;
+		com.arjuna.common.util.propertyservice.PropertyManager pm = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE);
+		pm.setProperty(Environment.MSG_STORE_DB_DATASOURCE_NAME, "datasource");
+		pm.setProperty(Environment.MSG_STORE_DB_CONN_MANAGER, JEE_CONNECTIONMGR_CLASS);
+   
+    	try {
+    		ctx = new InitialContext();
+    		MockDataSource mds = new MockDataSource(this);
+    		String dataSourcename = Configuration.getStoreDBDatasourceName();
+    		ctx.rebind(dataSourcename, mds);
+    		
+    	} catch (NamingException e) {
+    		e.printStackTrace();
+    		logger.debug("", e);
+    		fail(e.getMessage());
+    	} catch (Exception e) {
+			logger.debug("", e);
+    		fail(e.getMessage());		
+    	}
+		
+		try {
+			ConnectionManager cmf = ConnectionManagerFactory.getConnectionManager();
+			@SuppressWarnings("unused")
+			ConnectionManager test = cmf.getInstance();
+			Connection conn = cmf.getConnection();
+			if (conn == null) {
+				fail("Connection returned by StandaloneConnectionManager should not be null");
+			}
+		} catch (ConnectionManagerException e) {
+			logger.debug("", e);
+			fail(e.getMessage());
+		} catch (SQLException e) {
+			logger.debug("", e);
+			fail(e.getMessage());
+		}	
+	}
+	
+	public void testStandaloneConnectionManager() {
+		Context ctx = null;
+		com.arjuna.common.util.propertyservice.PropertyManager pm = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE);
+		pm.setProperty(Environment.MSG_STORE_DB_DATASOURCE_NAME, "datasource");
+		pm.setProperty(Environment.MSG_STORE_DB_CONN_MANAGER, STANDALONE_CONNECTIONMGR_CLASS);
+		pm.setProperty(Environment.MSG_STORE_DB_POOL_MAX_SIZE, "1");
+		pm.setProperty(Environment.MSG_STORE_DB_POOL_MIN_SIZE, "1");
+		pm.setProperty(Environment.MSG_STORE_DB_POOL_INITIAL_SIZE, "1");
+		pm.setProperty(Environment.MSG_STORE_DB_POOL_TIMEOUT_MILLIS, "20000");
+		
+    	try {
+    		ctx = new InitialContext();
+    		MockDataSource mds = new MockDataSource(this);
+    		String dataSourcename = Configuration.getStoreDBDatasourceName();
+    		ctx.rebind(dataSourcename, mds);
+    		
+    	} catch (NamingException e) {
+    		e.printStackTrace();
+
+			logger.debug("", e);
+    		fail(e.getMessage());
+    	} catch (Exception e) {
+			logger.debug("", e);
+    		fail(e.getMessage());		
+    	}
+		
+		try {
+			ConnectionManager cmf = ConnectionManagerFactory.getConnectionManager();
+			@SuppressWarnings("unused")
+			ConnectionManager test = cmf.getInstance();
+		} catch (ConnectionManagerException e) {
+			logger.debug("", e);
+			fail(e.getMessage());
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail(e.getMessage());
+		}
+	}
+}




More information about the jboss-svn-commits mailing list