1
package org.postgresql.test.jdbc2;
3
import org.postgresql.test.JDBC2Tests;
4
import junit.framework.TestCase;
8
* $Id: DriverTest.java,v 1.4 2001/11/19 22:33:39 momjian Exp $
10
* Tests the dynamically created class org.postgresql.Driver
13
public class DriverTest extends TestCase
16
public DriverTest(String name)
22
* This tests the acceptsURL() method with a couple of good and badly formed
25
public void testAcceptsURL()
30
// Load the driver (note clients should never do it this way!)
31
org.postgresql.Driver drv = new org.postgresql.Driver();
34
// These are always correct
35
assertTrue(drv.acceptsURL("jdbc:postgresql:test"));
36
assertTrue(drv.acceptsURL("jdbc:postgresql://localhost/test"));
37
assertTrue(drv.acceptsURL("jdbc:postgresql://localhost:5432/test"));
38
assertTrue(drv.acceptsURL("jdbc:postgresql://127.0.0.1/anydbname"));
39
assertTrue(drv.acceptsURL("jdbc:postgresql://127.0.0.1:5433/hidden"));
41
// Badly formatted url's
42
assertTrue(!drv.acceptsURL("jdbc:postgres:test"));
43
assertTrue(!drv.acceptsURL("postgresql:test"));
46
catch (SQLException ex)
48
fail(ex.getMessage());
53
* Tests parseURL (internal)
56
* Tests the connect method by connecting to the test database
58
public void testConnect()
60
Connection con = null;
63
Class.forName("org.postgresql.Driver");
65
// Test with the url, username & password
66
con = DriverManager.getConnection(JDBC2Tests.getURL(), JDBC2Tests.getUser(), JDBC2Tests.getPassword());
70
// Test with the username in the url
71
con = DriverManager.getConnection(JDBC2Tests.getURL() + "?user=" + JDBC2Tests.getUser() + "&password=" + JDBC2Tests.getPassword());
75
catch (ClassNotFoundException ex)
77
fail(ex.getMessage());
79
catch (SQLException ex)
81
fail(ex.getMessage());