KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > daemon > hsqldb > TestHsqlDBEngineImpl


1 /*
2  * CoadunationLib: The hsql db engine daemon test.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * TestHsqlDBEngineImpl.java
20  *
21  * JUnit based test
22  */

23
24 // package path
25
package com.rift.coad.daemon.hsqldb;
26
27 // java imports
28
import java.util.Hashtable JavaDoc;
29 import javax.naming.Context JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31 import javax.rmi.PortableRemoteObject JavaDoc;
32 import java.sql.DriverManager JavaDoc;
33 import java.sql.Connection JavaDoc;
34
35 // junit imports
36
import junit.framework.*;
37
38 /**
39  * This is the test client for the hsql db engine.
40  *
41  * @author Brett Chaldecott
42  */

43 public class TestHsqlDBEngineImpl extends TestCase {
44     
45     /**
46      * The runner thread
47      */

48     public class DBRunner extends Thread JavaDoc {
49         // private member variable
50
private HsqlDBEngineImpl instance = null;
51         
52         /**
53          * This method is called to construct the thread.
54          */

55         public DBRunner(HsqlDBEngineImpl instance) {
56             this.instance = instance;
57         }
58         
59         
60         /**
61          * This method is called to run the database
62          */

63         public void run() {
64             instance.process();
65         }
66     }
67     
68     public TestHsqlDBEngineImpl(String JavaDoc testName) {
69         super(testName);
70     }
71
72     protected void setUp() throws Exception JavaDoc {
73     }
74
75     protected void tearDown() throws Exception JavaDoc {
76     }
77     
78     /**
79      * This method tests the HsqlDB rmi interface
80      */

81     public void testHSQLDBEngine() throws Exception JavaDoc {
82         HsqlDBEngineImpl instance = new HsqlDBEngineImpl();
83         DBRunner runner = new DBRunner(instance);
84         runner.start();
85         
86         System.out.println("Name : " + instance.getDatabaseName(0,true));
87         System.out.println("Path : " + instance.getDatabasePath(0,true));
88         
89         Class.forName("org.hsqldb.jdbcDriver");
90         
91         Connection JavaDoc connection = DriverManager.getConnection(
92                 "jdbc:hsqldb:hsql://localhost/coadunation","sa","");
93         connection.close();
94         instance.terminate();
95         
96         try {
97             connection = DriverManager.getConnection(
98                 "jdbc:hsqldb:hsql://localhost/coadunation","sa","");
99             fail("Could still make a connection to the database");
100         } catch (java.sql.SQLException JavaDoc ex) {
101             // ignore
102
}
103     }
104
105 }
106
Popular Tags