01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) Copyright IBM Corporation, 2005. All rights reserved.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */
17: package org.geotools.data.db2;
18:
19: import org.geotools.data.jdbc.ConnectionPool;
20: import java.sql.Connection;
21: import java.sql.SQLException;
22:
23: /**
24: * Exercise DB2ConnectionFactory.
25: *
26: * @author David Adler - IBM Corporation
27: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/db2/src/test/java/org/geotools/data/db2/DB2ConnectionFactoryTest.java $
28: */
29: public class DB2ConnectionFactoryTest extends DB2TestCase {
30: // Test connection factory with 3 parameter constructor
31: public void testConnectionFactory3() {
32: Connection conn = null;
33: DB2ConnectionFactory connFact = null;
34: ConnectionPool pool = null;
35: String dbUrl = null;
36:
37: /* Test connection factory using type 4 connection - port number is non-zero */
38: connFact = new DB2ConnectionFactory(host, String
39: .valueOf(portnum), dbname);
40: connFact.setLogin(user, pw);
41:
42: try {
43: pool = connFact.getConnectionPool();
44: conn = pool.getConnection();
45: conn.close();
46: } catch (SQLException e) {
47: fail("Get connection with valid parameters failed: " + e);
48: }
49:
50: dbUrl = connFact.getDbURL();
51: assertEquals("Check returned dbUrl", dbUrl,
52: "jdbc:db2://localhost:50000/geotools");
53:
54: /* Test connection factory using type 2 connection - port number is zero */
55: connFact = new DB2ConnectionFactory(host, String.valueOf(0),
56: dbname);
57: connFact.setLogin(user, pw);
58:
59: try {
60: pool = connFact.getConnectionPool();
61: conn = pool.getConnection();
62: conn.close();
63: } catch (SQLException e) {
64: fail("Get connection with valid parameters failed: " + e);
65: }
66:
67: dbUrl = connFact.getDbURL();
68: assertEquals("Check returned dbUrl", dbUrl,
69: "jdbc:db2://localhost:0/geotools");
70:
71: connFact.setLogin("nouser", "nopw");
72:
73: try {
74: pool = connFact.getConnectionPool();
75: conn = pool.getConnection();
76: fail("Get connection with invalid parameters didn't fail");
77: } catch (SQLException e) {
78: // Should get here if test is successful
79: }
80:
81: connFact = new DB2ConnectionFactory(host, String
82: .valueOf(portnum), "nodbname");
83: connFact.setLogin(user, pw);
84:
85: try {
86: pool = connFact.getConnectionPool();
87: conn = pool.getConnection();
88: fail("Get connection with invalid parameters didn't fail");
89: } catch (SQLException e) {
90: // Should get here if test is successful
91: }
92: }
93: }
|