01: /*
02: * TableCreatorTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db;
13:
14: import java.util.ArrayList;
15: import junit.framework.TestCase;
16: import java.sql.Statement;
17: import java.util.List;
18: import workbench.TestUtil;
19:
20: /**
21: *
22: * @author support@sql-workbench.net
23: */
24: public class TableCreatorTest extends TestCase {
25: private TestUtil util;
26:
27: public TableCreatorTest(String testName) {
28: super (testName);
29: try {
30: util = new TestUtil(testName);
31: util.prepareEnvironment();
32: } catch (Exception e) {
33: e.printStackTrace();
34: }
35: }
36:
37: public void setUp() throws Exception {
38: super .setUp();
39: util.emptyBaseDirectory();
40: }
41:
42: public void testCreateTable() throws Exception {
43:
44: try {
45: WbConnection con = util.getConnection();
46: Statement stmt = con.createStatement();
47: stmt
48: .executeUpdate("CREATE TABLE create_test (zzz integer, bbb integer, aaa integer, ccc integer)");
49: TableIdentifier oldTable = new TableIdentifier(
50: "create_test");
51: TableIdentifier newTable = new TableIdentifier("new_table");
52:
53: List<ColumnIdentifier> clist = con.getMetadata()
54: .getTableColumns(oldTable);
55:
56: // Make sure the table is created with the same column
57: // ordering as the original table.
58: List<ColumnIdentifier> cols = new ArrayList<ColumnIdentifier>();
59:
60: for (ColumnIdentifier col : clist) {
61: cols.add(col);
62: }
63: ColumnIdentifier c1 = cols.get(0);
64: ColumnIdentifier c2 = cols.get(2);
65: cols.set(0, c2);
66: cols.set(2, c1);
67:
68: TableCreator creator = new TableCreator(con, newTable, cols);
69: creator.createTable();
70:
71: clist = con.getMetadata().getTableColumns(newTable);
72: assertEquals(4, clist.size());
73:
74: assertEquals("ZZZ", clist.get(0).getColumnName());
75: } catch (Exception e) {
76: e.printStackTrace();
77: fail(e.getMessage());
78: } finally {
79: ConnectionMgr.getInstance().disconnectAll();
80: }
81: }
82:
83: }
|