01: /*
02: * SourceTableArgumentTest.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.sql.wbcommands;
13:
14: import java.sql.Statement;
15: import java.util.List;
16: import junit.framework.TestCase;
17: import workbench.TestUtil;
18: import workbench.db.ConnectionMgr;
19: import workbench.db.TableIdentifier;
20: import workbench.db.WbConnection;
21: import workbench.util.SqlUtil;
22:
23: /**
24: *
25: * @author support@sql-workbench.net
26: */
27: public class SourceTableArgumentTest extends TestCase {
28:
29: public SourceTableArgumentTest(String testName) {
30: super (testName);
31: }
32:
33: public void testGetTables() {
34: WbConnection con = null;
35: Statement stmt = null;
36: try {
37: TestUtil util = new TestUtil("args");
38: con = util.getConnection();
39: stmt = con.createStatement();
40: stmt
41: .executeUpdate("create table arg_test (nr integer, data varchar(100))");
42: con.commit();
43:
44: SourceTableArgument parser = new SourceTableArgument(null,
45: con);
46: List<TableIdentifier> tables = parser.getTables();
47: assertEquals("Wrong number of table", 0, tables.size());
48:
49: parser = new SourceTableArgument(" ", con);
50: tables = parser.getTables();
51: assertEquals("Wrong number of table", 0, tables.size());
52:
53: parser = new SourceTableArgument(
54: "first_table, second_table, myschema.third_table",
55: con);
56: tables = parser.getTables();
57: assertEquals("Wrong number of table", 3, tables.size());
58: assertEquals("Wrong table retrieved", true, tables.get(0)
59: .getTableName().equalsIgnoreCase("first_table"));
60: assertEquals("Wrong table retrieved", true, tables.get(1)
61: .getTableName().equalsIgnoreCase("second_table"));
62: assertEquals("Wrong table retrieved", true, tables.get(2)
63: .getTableName().equalsIgnoreCase("third_table"));
64: assertEquals("Wrong table retrieved", true, tables.get(2)
65: .getSchema().equalsIgnoreCase("myschema"));
66:
67: parser = new SourceTableArgument("*", con);
68: tables = parser.getTables();
69: assertEquals("Wrong number of table", 1, tables.size());
70: assertEquals("Wrong table retrieved", true, tables.get(0)
71: .getTableName().equalsIgnoreCase("arg_test"));
72: } catch (Exception e) {
73: e.printStackTrace();
74: fail(e.getMessage());
75: } finally {
76: SqlUtil.closeStatement(stmt);
77: ConnectionMgr.getInstance().disconnectAll();
78: }
79: }
80:
81: public void testGetObjectNames() {
82: try {
83: String s = "\"MIND\",\"test\"";
84: SourceTableArgument parser = new SourceTableArgument(null,
85: null);
86: List<String> tables = parser.getObjectNames(s);
87: assertEquals(2, tables.size());
88: assertEquals("\"MIND\"", tables.get(0));
89: assertEquals("\"test\"", tables.get(1));
90: } catch (Exception e) {
91: e.printStackTrace();
92: fail(e.getMessage());
93: }
94: }
95: }
|