001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * Created on 4/08/2003
017: */
018: package org.geotools.data.oracle;
019:
020: import java.util.Properties;
021:
022: import junit.framework.TestCase;
023:
024: import org.geotools.data.jdbc.ConnectionPool;
025: import org.geotools.data.jdbc.ConnectionPoolManager;
026:
027: /**
028: * Test the Connection poolings
029: *
030: * @author Sean Geoghegan, Defence Science and Technology Organisation
031: * @author $Author: seangeo $
032: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/oracle-spatial/src/test/java/org/geotools/data/oracle/OracleConnectionFactoryOnlineTest.java $
033: * @version $Id: OracleConnectionFactoryOnlineTest.java 25819 2007-06-12 20:13:56Z chorner $ Last
034: * Modified: $Date: 2003/08/15 00:42:02 $
035: */
036: public class OracleConnectionFactoryOnlineTest extends TestCase {
037: /** The Oracle driver class name */
038: private static final String JDBC_DRIVER = "oracle.jdbc.driver.OracleDriver";
039: private Properties properties;
040: boolean GO = true;
041:
042: /**
043: * Creates a new OracleConnectionFactory Test.
044: *
045: * @throws ClassNotFoundException If the driver cannot be found
046: */
047: public OracleConnectionFactoryOnlineTest()
048: throws ClassNotFoundException {
049: super ();
050: try {
051: Class.forName(JDBC_DRIVER);
052: } catch (Throwable t) {
053: GO = false;
054: // must be running off dummy jar!
055: }
056: }
057:
058: /**
059: * Creates a new OracleConnectionFactory Test.
060: *
061: * @param arg0 name of the test
062: * @throws ClassNotFoundException If the Oracle Driver cannot be found
063: */
064: public OracleConnectionFactoryOnlineTest(String arg0)
065: throws ClassNotFoundException {
066: super (arg0);
067: try {
068: Class.forName(JDBC_DRIVER);
069: } catch (Throwable t) {
070: // must be running off dummy jar!
071: }
072: }
073:
074: /**
075: * Loads the properties
076: *
077: * @throws Exception
078: * @see junit.framework.TestCase#setUp()
079: */
080: protected void setUp() throws Exception {
081: super .setUp();
082: properties = new Properties();
083: properties.load(this .getClass().getResourceAsStream(
084: "remote.properties"));
085: }
086:
087: /**
088: * Removes the properties
089: *
090: * @throws Exception
091: * @see junit.framework.TestCase#tearDown()
092: */
093: protected void tearDown() throws Exception {
094: super .tearDown();
095: ConnectionPoolManager manager = ConnectionPoolManager
096: .getInstance();
097: manager.closeAll();
098: properties = null;
099: }
100:
101: public void testGetConnection() throws Exception {
102: if (!GO)
103: return;
104: OracleConnectionFactory cFact = new OracleConnectionFactory(
105: properties.getProperty("host"), properties
106: .getProperty("port"), properties
107: .getProperty("instance"));
108: cFact.setLogin(properties.getProperty("user"), properties
109: .getProperty("passwd"));
110:
111: // check that two connection pools from the same fact are the same
112: try {
113: ConnectionPool pool1 = cFact.getConnectionPool();
114: ConnectionPool pool2 = cFact.getConnectionPool();
115: assertTrue("Connection pool was not equal", pool1 == pool2);
116: // check that two connection pools using the same url,user,pass but
117: // from different factories are the same
118: OracleConnectionFactory cFact2 = new OracleConnectionFactory(
119: properties.getProperty("host"), properties
120: .getProperty("port"), properties
121: .getProperty("instance"));
122: cFact2.setLogin(properties.getProperty("user"), properties
123: .getProperty("passwd"));
124: ConnectionPool pool3 = cFact2.getConnectionPool();
125: assertTrue("New factory returned different pool",
126: pool1 == pool3);
127: } catch (Throwable t) {
128: // must be using dummy spatial
129: }
130: }
131: }
|