[jboss-svn-commits] JBL Code SVN: r13385 - in labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb: dependencies and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 12 00:46:46 EDT 2007


Author: tcunning
Date: 2007-07-12 00:46:46 -0400 (Thu, 12 Jul 2007)
New Revision: 13385

Added:
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/dependencies/
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/dependencies/DatabaseInitializerUnitTest.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/dependencies/test.sql
Log:
bug:JBESB-563
Add Database Initializer unit test.


Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/dependencies/DatabaseInitializerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/dependencies/DatabaseInitializerUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/dependencies/DatabaseInitializerUnitTest.java	2007-07-12 04:46:46 UTC (rev 13385)
@@ -0,0 +1,109 @@
+/*
+ * 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.internal.soa.esb.dependencies;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.helpers.persist.SimpleDataSource;
+import junit.framework.TestCase;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.mockejb.jndi.MockContextFactory;
+
+/**
+ * DatabaseIntializer test - tests the getters/setters and tests whether
+ * a database can be successfully intialized.
+ * 
+ * @author tcunning at redhat.com
+ */
+public class DatabaseInitializerUnitTest extends TestCase {
+    private static final String PERSIST_DB_DIR = System.getProperty("org.jboss.esb.test.persistdb.dir",
+		"./rosetta/tests/resources/etc");
+    
+    private static String JNDI_DATASOURCE = "JNDI.DATASOURCE";
+    private static String TEST_STRING = "TEST";
+    
+    private static Logger logger = Logger.getLogger(DatabaseInitializerUnitTest.class);
+    private static String mDbDriver ="org.hsqldb.jdbcDriver";
+    private static String mDbUrl = "jdbc:hsqldb:file:" + PERSIST_DB_DIR + "/persistUnitTestDB";
+    private static String mDbUsername = "sa";
+    private static String mDbPassword ="";
+    
+    private static String flag = null;
+    
+	protected void setUp() throws Exception {
+        try
+        {
+        	if (flag == null) {
+        		HsqldbUtil.startHsqldb(PERSIST_DB_DIR + "/persistUnitTestDB", "persistUnitTestDB");
+            	flag = "set";
+        	}
+        }
+        catch (Exception e)
+        {
+			logger.error("No Database Available - Stop Testing", e);
+            assertTrue(false);
+        }
+        
+        MockContextFactory.setAsInitial();
+    }
+    
+	public void testGetters() {
+		DatabaseInitializer di = new DatabaseInitializer();
+		di.setDatasource(TEST_STRING);
+		assertEquals(di.getDatasource(), TEST_STRING);
+		
+		di.setExistsSql(TEST_STRING);
+		assertEquals(di.getExistsSql(), TEST_STRING);
+		
+		di.setSqlFiles(TEST_STRING);
+		assertEquals(di.getSqlFiles(), TEST_STRING);
+	}
+	
+    public void testInitialization() {
+    	SimpleDataSource simpleDS = new SimpleDataSource(mDbDriver, mDbUrl, mDbUsername, mDbPassword);
+            // Grab the connection created and do a simple Query - we expect a result
+    	try {
+    		Context ctx = new InitialContext();
+    		ctx.rebind(JNDI_DATASOURCE, simpleDS);
+		
+    		DatabaseInitializer di = new DatabaseInitializer();
+    		di.setDatasource(JNDI_DATASOURCE);
+			di.setExistsSql("select * from AUTH_TOKEN");
+			di.setSqlFiles("org/jboss/internal/soa/esb/test.sql");
+			di.initDatabase();
+		} catch (NamingException e) {
+			e.printStackTrace();
+			fail(e.getMessage());
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail(e.getMessage());		
+		}
+	}
+    
+    protected void tearDown() throws Exception {
+    	   MockContextFactory.revertSetAsInitial();
+   	}
+}

Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/dependencies/test.sql
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/dependencies/test.sql	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/dependencies/test.sql	2007-07-12 04:46:46 UTC (rev 13385)
@@ -0,0 +1 @@
+select 'boo'




More information about the jboss-svn-commits mailing list