KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > hajdbc > sql > TestDriver


1 /*
2  * HA-JDBC: High-Availability JDBC
3  * Copyright (c) 2004-2006 Paul Ferraro
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2.1 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: ferraro@users.sourceforge.net
20  */

21 package net.sf.hajdbc.sql;
22
23 import java.sql.Connection JavaDoc;
24 import java.sql.DriverManager JavaDoc;
25 import java.sql.DriverPropertyInfo JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.util.Collections JavaDoc;
28
29 import org.testng.annotations.Test;
30
31 import net.sf.hajdbc.DatabaseClusterTestCase;
32
33 /**
34  * Unit test for {@link Driver}.
35  * @author Paul Ferraro
36  * @since 1.0
37  */

38 @Test
39 public class TestDriver extends DatabaseClusterTestCase
40 {
41     private Driver driver = new Driver();
42
43     /**
44      * Test method for {@link Driver} static initialization.
45      */

46     public void testRegister()
47     {
48         boolean registered = false;
49         
50         for (java.sql.Driver JavaDoc driver: Collections.list(DriverManager.getDrivers()))
51         {
52             if (Driver.class.isInstance(driver))
53             {
54                 registered = true;
55             }
56         }
57         
58         assert registered;
59     }
60
61     /**
62      * Test method for {@link Driver#acceptsURL(String)}.
63      */

64     public void testAcceptsURL()
65     {
66         boolean accepted = this.driver.acceptsURL("jdbc:ha-jdbc:test-database-cluster");
67         
68         assert accepted;
69
70         try
71         {
72             accepted = this.driver.acceptsURL("jdbc:ha-jdbc:no-such-cluster");
73
74             assert false : accepted;
75         }
76         catch (IllegalArgumentException JavaDoc e)
77         {
78             assert true;
79         }
80         
81         accepted = this.driver.acceptsURL("jdbc:ha-jdbc:");
82
83         assert !accepted;
84         
85         accepted = this.driver.acceptsURL("jdbc:ha-jdbc");
86         
87         assert !accepted;
88
89         accepted = this.driver.acceptsURL("jdbc:test:database1");
90         
91         assert !accepted;
92     }
93
94     /**
95      * Test method for {@link Driver#connect(String, Properties)}
96      */

97     public void testConnect()
98     {
99         try
100         {
101             Connection connection = this.driver.connect("jdbc:ha-jdbc:test-database-cluster", null);
102             
103             assert connection != null;
104             
105             assert net.sf.hajdbc.sql.Connection.class.equals(connection.getClass()) : connection.getClass().getName();
106         }
107         catch (SQLException JavaDoc e)
108         {
109             assert false : e;
110         }
111     }
112
113     /**
114      * Test method for {@link Driver#getPropertyInfo(String, Properties)}
115      */

116     public void testGetPropertyInfo()
117     {
118         try
119         {
120             DriverPropertyInfo JavaDoc[] info = this.driver.getPropertyInfo("jdbc:ha-jdbc:test-database-cluster", null);
121             
122             assert info != null;
123         }
124         catch (SQLException JavaDoc e)
125         {
126             assert false : e;
127         }
128     }
129
130     /**
131      * Test method for {@link Driver#jdbcCompliant()}
132      */

133     public void testJdbcCompliant()
134     {
135         boolean compliant = this.driver.jdbcCompliant();
136         
137         assert compliant;
138     }
139 }
140
Popular Tags