001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-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;
009: * version 2.1 of the License.
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: package org.geotools.data.postgis;
017:
018: import java.io.IOException;
019: import java.sql.Connection;
020: import java.sql.DatabaseMetaData;
021: import java.sql.ResultSet;
022: import java.sql.SQLException;
023: import java.sql.Statement;
024:
025: import org.geotools.data.jdbc.JDBCUtils;
026:
027: public class SupportTableOnlineTest extends
028: AbstractVersionedPostgisDataTestCase {
029:
030: public SupportTableOnlineTest(String name) {
031: super (name);
032: }
033:
034: public void testTableCreation() throws IOException, SQLException {
035: buildDataStore();
036: // now the tables should be there
037: Connection conn = null;
038: ResultSet tables = null;
039: try {
040: boolean changeSets = false;
041: boolean tablesChanged = false;
042: boolean versionedTables = false;
043: conn = pool.getConnection();
044: DatabaseMetaData meta = conn.getMetaData();
045: String[] tableType = { "TABLE" };
046: tables = meta.getTables(null, f.schema, "%", tableType);
047: while (tables.next()) {
048: String tableName = tables.getString(3);
049: if (tableName
050: .equals(VersionedPostgisDataStore.TBL_CHANGESETS))
051: changeSets = true;
052: if (tableName
053: .equals(VersionedPostgisDataStore.TBL_TABLESCHANGED))
054: tablesChanged = true;
055: if (tableName
056: .equals(VersionedPostgisDataStore.TBL_VERSIONEDTABLES))
057: versionedTables = true;
058: }
059: tables.close();
060:
061: assertTrue(changeSets);
062: assertTrue(tablesChanged);
063: assertTrue(versionedTables);
064: } finally {
065: JDBCUtils.close(tables);
066: JDBCUtils.close(conn, null, null);
067: }
068: }
069:
070: public void testPreexistentTables() throws IOException,
071: SQLException {
072: // first call should create them, second one should not fail
073: buildDataStore();
074: buildDataStore();
075: }
076:
077: public void testTablesInTheWay() throws IOException, SQLException {
078: Connection conn = null;
079: Statement st = null;
080: try {
081: conn = pool.getConnection();
082: st = conn.createStatement();
083: st.execute("CREATE TABLE "
084: + VersionedPostgisDataStore.TBL_CHANGESETS
085: + "(ID SERIAL, STUFF VARCHAR(20))");
086: try {
087: buildDataStore();
088: fail("Should have failed because of the pre-existing but alone version support table");
089: } catch (IOException e) {
090: // ok
091: }
092: SqlTestUtils.dropTable(pool,
093: VersionedPostgisDataStore.TBL_CHANGESETS, true);
094:
095: st.execute("CREATE TABLE "
096: + VersionedPostgisDataStore.TBL_TABLESCHANGED
097: + "(ID SERIAL, STUFF VARCHAR(20))");
098: try {
099: buildDataStore();
100: fail("Should have failed because of the pre-existing but alone version support table");
101: } catch (IOException e) {
102: // ok
103: }
104: SqlTestUtils.dropTable(pool,
105: VersionedPostgisDataStore.TBL_TABLESCHANGED, false);
106:
107: st.execute("CREATE TABLE "
108: + VersionedPostgisDataStore.TBL_VERSIONEDTABLES
109: + "(ID SERIAL, STUFF VARCHAR(20))");
110: try {
111: buildDataStore();
112: fail("Should have failed because of the pre-existing but alone version support table");
113: } catch (IOException e) {
114: // ok
115: }
116: SqlTestUtils
117: .dropTable(
118: pool,
119: VersionedPostgisDataStore.TBL_VERSIONEDTABLES,
120: true);
121: } finally {
122: JDBCUtils.close(st);
123: JDBCUtils.close(conn, null, null);
124: }
125: }
126:
127: }
|