001: /*
002: * The JTS Topology Suite is a collection of Java classes that
003: * implement the fundamental operations required to validate a given
004: * geo-spatial data set to a known topological specification.
005: *
006: * Copyright (C) 2001 Vivid Solutions
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: *
022: * For more information, contact:
023: *
024: * Vivid Solutions
025: * Suite #1A
026: * 2328 Government Street
027: * Victoria BC V8T 5G5
028: * Canada
029: *
030: * (250)385-6040
031: * www.vividsolutions.com
032: */
033: package com.vividsolutions.jts.io.oracle;
034:
035: import java.net.URL;
036: import java.sql.*;
037: import java.util.Properties;
038:
039: import com.vividsolutions.jts.geom.GeometryFactory;
040: import com.vividsolutions.jts.geom.PrecisionModel;
041:
042: import oracle.jdbc.OracleConnection;
043: import junit.framework.TestCase;
044:
045: /**
046: *
047: * Abstract Test Case. Intended to provide a connection with which test may be performed.
048: *
049: * Sub-classes should not assume that either the connection will always exist, or
050: * the connection has the required permissions.
051: *
052: * @author David Zwiers, Vivid Solutions.
053: */
054: public class ConnectedTestCase extends TestCase {
055:
056: /**
057: * @param arg
058: */
059: public ConnectedTestCase(String arg) {
060: super (arg);
061: }
062:
063: private OracleConnection connection = null;
064:
065: /**
066: * Sub-classes should not assume that either the connection will always exist, or
067: * the connection has the required permissions.
068: *
069: * @return OracleConnection
070: */
071: protected OracleConnection getConnection() {
072: return connection;
073: }
074:
075: /**
076: * @see junit.framework.TestCase#setUp()
077: */
078: protected void setUp() throws Exception {
079: super .setUp();
080:
081: Properties props = new Properties();
082: URL path = ClassLoader
083: .getSystemResource("com/vividsolutions/jts/io/oracle/connection.properties");
084: props.load(path.openStream());
085:
086: connection = getOracleConnection(props
087: .getProperty("test.server"), props
088: .getProperty("test.port"), props
089: .getProperty("test.sid"), props
090: .getProperty("test.user"), props
091: .getProperty("test.pwd"));
092: }
093:
094: private static OracleConnection getOracleConnection(String server,
095: String port, String sid, String userid, String pwd)
096: throws SQLException {
097: String url = "jdbc:oracle:thin:@" + server + ":" + port + ":"
098: + sid;
099: return (OracleConnection) openConnection(
100: "oracle.jdbc.driver.OracleDriver", url, userid, pwd);
101: }
102:
103: private static Connection openConnection(String driver, String url,
104: String uid, String pwd) throws SQLException {
105:
106: Connection conn = null;
107: try {
108: Class.forName(driver);
109: } catch (java.lang.ClassNotFoundException e) {
110: fail(e.getMessage());
111: }
112: conn = DriverManager.getConnection(url, uid, pwd);
113: return conn;
114: }
115:
116: /**
117: * @see junit.framework.TestCase#tearDown()
118: */
119: protected void tearDown() throws Exception {
120: super .tearDown();
121: if (connection != null && !connection.isClosed())
122: connection.close();
123: }
124:
125: protected static PrecisionModel precisionModel = new PrecisionModel(
126: 1000);
127: protected static GeometryFactory geometryFactory = new GeometryFactory(
128: precisionModel);
129:
130: }
|