01: package net.sourceforge.squirrel_sql.fw.sql;
02:
03: import static org.junit.Assert.assertEquals;
04: import static org.junit.Assert.fail;
05:
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: import net.sourceforge.squirrel_sql.BaseSQuirreLJUnit4TestCase;
10: import net.sourceforge.squirrel_sql.client.ApplicationManager;
11:
12: import org.junit.After;
13: import org.junit.Assert;
14: import org.junit.Before;
15: import org.junit.Test;
16:
17: public class SQLUtilitiesTest extends BaseSQuirreLJUnit4TestCase {
18:
19: @Before
20: public void setUp() throws Exception {
21: ApplicationManager.initApplication();
22: }
23:
24: @After
25: public void tearDown() throws Exception {
26:
27: }
28:
29: @Test
30: public void testGetInsertionOrder() {
31:
32: ArrayList<ITableInfo> tables = new ArrayList<ITableInfo>();
33: ITableInfo ti = new MockTableInfo("mockTable", "mockSchema",
34: "mockCatalog");
35: ITableInfo ti2 = new MockTableInfo("mockTable2", "mockSchema2",
36: "mockCatalog2");
37: ITableInfo ti3 = new MockTableInfo("mockTable3", "mockSchema3",
38: "mockCatalog3");
39:
40: tables.add(ti);
41: tables.add(ti2);
42: tables.add(ti3);
43:
44: SQLDatabaseMetaData md = new MockSQLDatabaseMetaData();
45:
46: try {
47: List<ITableInfo> result = SQLUtilities.getInsertionOrder(
48: tables, md, new MyCallback());
49: Assert.assertEquals(tables.size(), result.size());
50: } catch (Exception e) {
51: fail("Unexpected exception: " + e.getMessage());
52: }
53: }
54:
55: @Test
56: public void testNullQuoteIdentifier() {
57: Assert.assertNull(SQLUtilities.quoteIdentifier(null));
58: }
59:
60: @Test
61: public void testQuoteIdentifierWithEmbeddedQuotes() {
62: String tableNameWithAnEmbeddedQuote = "foo\"bar";
63: String newTableName = SQLUtilities
64: .quoteIdentifier(tableNameWithAnEmbeddedQuote);
65: assertEquals("foo\"\"bar", newTableName);
66:
67: tableNameWithAnEmbeddedQuote = "\"foo\"bar\"";
68: newTableName = SQLUtilities
69: .quoteIdentifier(tableNameWithAnEmbeddedQuote);
70: assertEquals("\"foo\"\"bar\"", newTableName);
71:
72: String tableName = "MyTable";
73: String quotedTableName = SQLUtilities
74: .quoteIdentifier(tableName);
75: assertEquals(tableName, quotedTableName);
76: }
77:
78: private static class MyCallback implements ProgressCallBack {
79:
80: public void currentlyLoading(String simpleName) {
81: // Do Nothing
82: }
83:
84: }
85: }
|