001: /*
002: * CoadunationLib: The hsql db engine daemon test.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * TestHsqlDBEngineImpl.java
020: *
021: * JUnit based test
022: */
023:
024: // package path
025: package com.rift.coad.daemon.hsqldb;
026:
027: // java imports
028: import java.util.Hashtable;
029: import javax.naming.Context;
030: import javax.naming.InitialContext;
031: import javax.rmi.PortableRemoteObject;
032: import java.sql.DriverManager;
033: import java.sql.Connection;
034:
035: // junit imports
036: import junit.framework.*;
037:
038: /**
039: * This is the test client for the hsql db engine.
040: *
041: * @author Brett Chaldecott
042: */
043: public class TestHsqlDBEngineImpl extends TestCase {
044:
045: /**
046: * The runner thread
047: */
048: public class DBRunner extends Thread {
049: // private member variable
050: private HsqlDBEngine instance = null;
051:
052: /**
053: * This method is called to construct the thread.
054: */
055: public DBRunner(HsqlDBEngine instance) {
056: this .instance = instance;
057: }
058:
059: /**
060: * This method is called to run the database
061: */
062: public void run() {
063: instance.process();
064: }
065: }
066:
067: public TestHsqlDBEngineImpl(String testName) {
068: super (testName);
069: }
070:
071: protected void setUp() throws Exception {
072: }
073:
074: protected void tearDown() throws Exception {
075: }
076:
077: /**
078: * This method tests the HsqlDB rmi interface
079: */
080: public void testHSQLDBEngine() throws Exception {
081: HsqlDBEngine instance = new HsqlDBEngine();
082: DBRunner runner = new DBRunner(instance);
083: runner.start();
084:
085: System.out.println("Name : "
086: + instance.getDatabaseName(0, true));
087: System.out.println("Path : "
088: + instance.getDatabasePath(0, true));
089:
090: Class.forName("org.hsqldb.jdbcDriver");
091:
092: Connection connection = DriverManager.getConnection(
093: "jdbc:hsqldb:hsql://localhost/coadunation", "sa", "");
094: connection.close();
095: instance.terminate();
096:
097: try {
098: connection = DriverManager.getConnection(
099: "jdbc:hsqldb:hsql://localhost/coadunation", "sa",
100: "");
101: fail("Could still make a connection to the database");
102: } catch (java.sql.SQLException ex) {
103: // ignore
104: }
105: }
106:
107: }
|