1 21 package net.sf.hajdbc.sql; 22 23 import java.sql.Connection ; 24 import java.sql.DriverManager ; 25 import java.sql.DriverPropertyInfo ; 26 import java.sql.SQLException ; 27 import java.util.Collections ; 28 29 import org.testng.annotations.Test; 30 31 import net.sf.hajdbc.DatabaseClusterTestCase; 32 33 38 @Test 39 public class TestDriver extends DatabaseClusterTestCase 40 { 41 private Driver driver = new Driver(); 42 43 46 public void testRegister() 47 { 48 boolean registered = false; 49 50 for (java.sql.Driver 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 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 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 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 e) 108 { 109 assert false : e; 110 } 111 } 112 113 116 public void testGetPropertyInfo() 117 { 118 try 119 { 120 DriverPropertyInfo [] info = this.driver.getPropertyInfo("jdbc:ha-jdbc:test-database-cluster", null); 121 122 assert info != null; 123 } 124 catch (SQLException e) 125 { 126 assert false : e; 127 } 128 } 129 130 133 public void testJdbcCompliant() 134 { 135 boolean compliant = this.driver.jdbcCompliant(); 136 137 assert compliant; 138 } 139 } 140 | Popular Tags |