01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
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: package org.geotools.data.postgis.referencing;
17:
18: import java.sql.Connection;
19: import java.sql.ResultSet;
20: import java.sql.SQLException;
21: import java.sql.Statement;
22:
23: import javax.sql.DataSource;
24:
25: import junit.framework.TestCase;
26:
27: import org.geotools.data.DataSourceException;
28: import org.geotools.data.Transaction;
29: import org.geotools.data.jdbc.JDBCUtils;
30: import org.geotools.data.jdbc.datasource.ManageableDataSource;
31: import org.geotools.data.postgis.PostgisDataStoreFactory;
32: import org.geotools.data.postgis.PostgisTests;
33: import org.opengis.referencing.crs.CoordinateReferenceSystem;
34:
35: /**
36: * Test PostgisAuthorityFactory
37: *
38: * @author Jesse Eichar, Refractions Research Inc.
39: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/postgis/src/test/java/org/geotools/data/postgis/referencing/PostgisAuthorityFactoryOnlineTest.java $
40: */
41: public class PostgisAuthorityFactoryOnlineTest extends TestCase {
42:
43: private String TABLE_NAME = "SPATIAL_REF_SYS";
44: private String SRID_COLUMN = "SRID";
45:
46: public int getSRIDs(DataSource pool) throws Exception {
47: Connection dbConnection = null;
48:
49: try {
50: String sqlStatement = "SELECT " + SRID_COLUMN + " FROM "
51: + TABLE_NAME;
52: dbConnection = pool.getConnection();
53:
54: Statement statement = dbConnection.createStatement();
55: ResultSet result = statement.executeQuery(sqlStatement);
56:
57: if (result.next()) {
58: int srid = result.getInt("srid");
59: JDBCUtils.close(statement);
60:
61: return srid;
62: } else {
63: String mesg = "No srid column row: " + TABLE_NAME;
64: throw new DataSourceException(mesg);
65: }
66: } catch (SQLException sqle) {
67: String message = sqle.getMessage();
68:
69: throw new DataSourceException(message, sqle);
70: } finally {
71: JDBCUtils
72: .close(dbConnection, Transaction.AUTO_COMMIT, null);
73: }
74: }
75:
76: public void testCreateCRS() throws Exception {
77: PostgisTests.Fixture f = PostgisTests.newFixture();
78: String url = "jdbc:postgresql" + "://" + f.host + ":" + f.port
79: + "/" + f.database;
80: ManageableDataSource pool = PostgisDataStoreFactory
81: .getDefaultDataSource(f.host, f.user, f.password,
82: f.port.intValue(), f.database, 10, 2, false);
83: PostgisAuthorityFactory factory = new PostgisAuthorityFactory(
84: pool);
85: CoordinateReferenceSystem crs = factory
86: .createCRS(getSRIDs(pool));
87: assertNotNull(crs);
88: }
89:
90: }
|