001: /*
002: * Copyright (C) 2007 Rob Manning
003: * manningr@users.sourceforge.net
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package net.sourceforge.squirrel_sql.fw.sql;
020:
021: import static org.junit.Assert.*;
022:
023: import net.sourceforge.squirrel_sql.BaseSQuirreLJUnit4TestCase;
024: import net.sourceforge.squirrel_sql.test.TestUtil;
025:
026: import org.junit.After;
027: import org.junit.Before;
028: import org.junit.Test;
029:
030: import com.gargoylesoftware.base.testing.EqualsTester;
031:
032: public class DatabaseObjectInfoTest extends BaseSQuirreLJUnit4TestCase {
033:
034: DatabaseObjectInfo dboInfoUnderTest = null;
035:
036: ISQLDatabaseMetaData oracleSQLDatabaseMetaData = null;
037:
038: ISQLDatabaseMetaData h2SQLDatabaseMetaData = null;
039:
040: String testCatalog = "TestCatalog";
041:
042: String testSchema = "TestSchema";
043:
044: @Before
045: public void setUp() throws Exception {
046: oracleSQLDatabaseMetaData = TestUtil.getEasyMockSQLMetaData(
047: "oracle", "jdbc:oracle:thin@", false, true);
048:
049: h2SQLDatabaseMetaData = TestUtil.getEasyMockH2SQLMetaData();
050: }
051:
052: @After
053: public void tearDown() throws Exception {
054: h2SQLDatabaseMetaData = null;
055: oracleSQLDatabaseMetaData = null;
056: }
057:
058: @Test
059: public final void testGetQualifiedNameH2() throws Exception {
060: // Test case for 1742033 (Skipping quoting escape in table dropping)
061: String tableName = "foo\"\"bar";
062: dboInfoUnderTest = new DatabaseObjectInfo(testCatalog,
063: testSchema, tableName, DatabaseObjectType.TABLE,
064: h2SQLDatabaseMetaData);
065:
066: String identifierQuoteString = h2SQLDatabaseMetaData
067: .getIdentifierQuoteString();
068: String sep = h2SQLDatabaseMetaData.getCatalogSeparator();
069: String expectedQualifiedName = identifierQuoteString
070: + testSchema + identifierQuoteString + sep
071: + identifierQuoteString + "foo\"\"\"\"bar"
072: + identifierQuoteString;
073:
074: String qn = dboInfoUnderTest.getQualifiedName();
075: assertEquals(expectedQualifiedName, qn);
076: }
077:
078: @Test
079: public final void testEqualsAndHashcode() {
080: DatabaseObjectInfo a = new DatabaseObjectInfo(testCatalog,
081: testSchema, "table1", DatabaseObjectType.TABLE,
082: h2SQLDatabaseMetaData);
083: DatabaseObjectInfo b = new DatabaseObjectInfo(testCatalog,
084: testSchema, "table1", DatabaseObjectType.TABLE,
085: h2SQLDatabaseMetaData);
086:
087: DatabaseObjectInfo c = new DatabaseObjectInfo(testCatalog,
088: testSchema, "table2", DatabaseObjectType.TABLE,
089: h2SQLDatabaseMetaData);
090:
091: DatabaseObjectInfo d = new MyDatabaseObjectInfo(testCatalog,
092: testSchema, "table1", DatabaseObjectType.TABLE,
093: h2SQLDatabaseMetaData);
094:
095: new EqualsTester(a, b, c, d);
096: }
097:
098: @SuppressWarnings("serial")
099: private static class MyDatabaseObjectInfo extends
100: DatabaseObjectInfo {
101:
102: public MyDatabaseObjectInfo(String catalog, String schema,
103: String simpleName, DatabaseObjectType dboType,
104: ISQLDatabaseMetaData md) {
105: super(catalog, schema, simpleName, dboType, md);
106: }
107: }
108: }
|