~ubuntu-branches/ubuntu/wily/libpgjava/wily

« back to all changes in this revision

Viewing changes to src/interfaces/jdbc/org/postgresql/test/jdbc2/DriverTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Gybas
  • Date: 2002-02-06 23:43:06 UTC
  • Revision ID: james.westby@ubuntu.com-20020206234306-hsg7suqr8q56qg40
Tags: upstream-7.2
ImportĀ upstreamĀ versionĀ 7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.postgresql.test.jdbc2;
 
2
 
 
3
import org.postgresql.test.JDBC2Tests;
 
4
import junit.framework.TestCase;
 
5
import java.sql.*;
 
6
 
 
7
/*
 
8
 * $Id: DriverTest.java,v 1.4 2001/11/19 22:33:39 momjian Exp $
 
9
 *
 
10
 * Tests the dynamically created class org.postgresql.Driver
 
11
 *
 
12
 */
 
13
public class DriverTest extends TestCase
 
14
{
 
15
 
 
16
        public DriverTest(String name)
 
17
        {
 
18
                super(name);
 
19
        }
 
20
 
 
21
        /*
 
22
         * This tests the acceptsURL() method with a couple of good and badly formed
 
23
         * jdbc urls
 
24
         */
 
25
        public void testAcceptsURL()
 
26
        {
 
27
                try
 
28
                {
 
29
 
 
30
                        // Load the driver (note clients should never do it this way!)
 
31
                        org.postgresql.Driver drv = new org.postgresql.Driver();
 
32
                        assertNotNull(drv);
 
33
 
 
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"));
 
40
 
 
41
                        // Badly formatted url's
 
42
                        assertTrue(!drv.acceptsURL("jdbc:postgres:test"));
 
43
                        assertTrue(!drv.acceptsURL("postgresql:test"));
 
44
 
 
45
                }
 
46
                catch (SQLException ex)
 
47
                {
 
48
                        fail(ex.getMessage());
 
49
                }
 
50
        }
 
51
 
 
52
        /*
 
53
         * Tests parseURL (internal)
 
54
         */
 
55
        /*
 
56
         * Tests the connect method by connecting to the test database
 
57
         */
 
58
        public void testConnect()
 
59
        {
 
60
                Connection con = null;
 
61
                try
 
62
                {
 
63
                        Class.forName("org.postgresql.Driver");
 
64
 
 
65
                        // Test with the url, username & password
 
66
                        con = DriverManager.getConnection(JDBC2Tests.getURL(), JDBC2Tests.getUser(), JDBC2Tests.getPassword());
 
67
                        assertNotNull(con);
 
68
                        con.close();
 
69
 
 
70
                        // Test with the username in the url
 
71
                        con = DriverManager.getConnection(JDBC2Tests.getURL() + "?user=" + JDBC2Tests.getUser() + "&password=" + JDBC2Tests.getPassword());
 
72
                        assertNotNull(con);
 
73
                        con.close();
 
74
                }
 
75
                catch (ClassNotFoundException ex)
 
76
                {
 
77
                        fail(ex.getMessage());
 
78
                }
 
79
                catch (SQLException ex)
 
80
                {
 
81
                        fail(ex.getMessage());
 
82
                }
 
83
        }
 
84
}