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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 20 12:29:20 EST 2006


Author: jplenhart
Date: 2006-12-20 12:29:09 -0500 (Wed, 20 Dec 2006)
New Revision: 8450

Added:
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/persist/
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/persist/SimpleDataSourceUnitTest.java
Log:
Adding Unit Tests For Rosetta

Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/persist/SimpleDataSourceUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/persist/SimpleDataSourceUnitTest.java	2006-12-20 17:19:42 UTC (rev 8449)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/helpers/persist/SimpleDataSourceUnitTest.java	2006-12-20 17:29:09 UTC (rev 8450)
@@ -0,0 +1,186 @@
+/*
+ * 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.helpers.persist;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import junit.framework.JUnit4TestAdapter;
+
+
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.apache.log4j.Priority;
+import org.apache.log4j.Logger;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.ResultSet;
+
+/**
+ * Unit tests for the SimpleDataSource class.
+ *
+ * @author <a href="mailto:jplenhart at yahoo.com">jplenhart at yahoo.com</a>
+ */
+
+
+public class SimpleDataSourceUnitTest
+{
+
+
+    private static String mDbDriver ="org.hsqldb.jdbcDriver";
+    private static String mDbUrl = "jdbc:hsqldb:file:./core/rosetta/tests/resources/etc/persistUnitTestDB";
+    private static String mDbUsername = "sa";
+    private static String mDbPassword ="";
+
+    private Logger logger = Logger.getLogger(this.getClass());
+
+
+//Instanitate with incorrect parameters
+
+
+
+    /**
+     * Setup the database.
+     */
+    @BeforeClass
+    public static void runBeforeAllTests()
+    {
+        try
+        {
+            HsqldbUtil.startHsqldb("./core/rosetta/tests/resources/etc/persistUnitTestDB", "persistUnitTestDB");
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            System.out.println("No Database Available - Stop Testing");
+            assertTrue(false);
+        }
+
+    }
+
+
+    /**
+     *
+     * Instantiate with all Correct Parameters
+     * Connect to the Database validate timeout
+     */
+    @Test
+    public void instantiateAndSetTimeout()
+    {
+        try
+        {
+            SimpleDataSource simpleDS = new SimpleDataSource(mDbDriver, mDbUrl, mDbUsername, mDbPassword);
+
+            simpleDS.setLoginTimeout(10000);
+            assertEquals(simpleDS.getLoginTimeout(),10000);
+        }
+        catch (Exception _ex)
+        {
+            logger.log(Priority.ERROR, _ex.getLocalizedMessage(), _ex);
+            assertTrue(false);
+        }
+
+    }
+
+    /**
+     *
+     * Instantiate with all Correct Parameters
+     * Connect to the Database and Run a Simple
+     * Query
+     */
+    @Test
+    public void instantiateWithCorrectParameters()
+    {
+
+        try
+        {
+            SimpleDataSource simpleDS = new SimpleDataSource(mDbDriver, mDbUrl, mDbUsername, mDbPassword);
+            // Grab the connection created and do a simple Query - we expect a result
+            Connection con = simpleDS.getConnection();
+            Statement stat = con.createStatement();
+            ResultSet rs = stat.executeQuery("select * from message");
+
+            if(rs.next())
+                assertTrue(true);
+            else
+                assertTrue(false);
+        }
+        catch (Exception _ex)
+        {
+            logger.log(Priority.ERROR, _ex.getLocalizedMessage(), _ex);
+            assertTrue(false);
+        }
+    }
+
+    /**
+     *
+     * Instantiate with InCorrect Parameters
+     * Connect to the Database - verify it errors properly
+     * by throwing an Exception
+     */
+    @Test
+    public void instantiateWithInCorrectParameters()
+    {
+
+        try
+        {
+            // Setting a Bogus Driver
+            SimpleDataSource simpleDS = new SimpleDataSource("bogusDriver", mDbUrl, mDbUsername, mDbPassword);
+            assertTrue(false);
+        }
+        catch (Exception _ex)
+        {
+            // This is Expected
+            assertTrue(true);
+        }
+
+    }
+
+
+
+    /**
+     * Shutdown the database
+     *
+     * @throws Exception
+     */
+    @AfterClass
+    public static void runAfterAllTests() throws Exception
+    {
+        if ("org.hsqldb.jdbcDriver".equals(mDbDriver))
+        {
+            HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+            System.out.println("Database Shutdown Complete");
+        }
+    }
+
+    public static junit.framework.Test suite()
+    {
+        return new JUnit4TestAdapter(SimpleDataSourceUnitTest.class);
+    }
+
+
+
+}
\ No newline at end of file




More information about the jboss-svn-commits mailing list