01: /*
02: * WbDescribeTableTest.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.util.List;
15: import junit.framework.*;
16: import workbench.TestUtil;
17: import workbench.db.ConnectionMgr;
18: import workbench.sql.DefaultStatementRunner;
19: import workbench.sql.StatementRunnerResult;
20: import workbench.storage.DataStore;
21:
22: /**
23: *
24: * @author support@sql-workbench.net
25: */
26: public class WbDescribeTableTest extends TestCase {
27: public WbDescribeTableTest(String testName) {
28: super (testName);
29: }
30:
31: protected void setUp() throws Exception {
32: super .setUp();
33: }
34:
35: protected void tearDown() throws Exception {
36: ConnectionMgr.getInstance().disconnectAll();
37: super .tearDown();
38: }
39:
40: public void testExecute() throws Exception {
41: TestUtil util;
42: DefaultStatementRunner runner;
43:
44: try {
45: util = new TestUtil(getClass().getName() + "_testExecute");
46: util.prepareEnvironment();
47: runner = util.createConnectedStatementRunner();
48: String sql = "create table describe_test (nr integer, info_text varchar(100));";
49: runner.runStatement(sql, -1, -1);
50: StatementRunnerResult result = runner.getResult();
51: assertEquals("Could not create table", true, result
52: .isSuccess());
53:
54: sql = "-- show table definition\ndesc describe_test;";
55: runner.runStatement(sql, -1, -1);
56: result = runner.getResult();
57: assertEquals("Describe failed", true, result.isSuccess());
58:
59: List<DataStore> data = result.getDataStores();
60: assertNotNull("No description returned", data);
61: assertEquals("No data returned", 1, data.size());
62: assertEquals("Wrong number of rows returned", 2, data
63: .get(0).getRowCount());
64:
65: sql = "-- show table definition\ndescribe \"DESCRIBE_TEST\"\n-- for table;";
66: runner.runStatement(sql, -1, -1);
67: result = runner.getResult();
68: assertEquals("Describe failed", true, result.isSuccess());
69:
70: data = result.getDataStores();
71: assertNotNull("No description returned", data);
72: assertEquals("No data returned", 1, data.size());
73:
74: assertEquals("Wrong number of rows returned", 2, data
75: .get(0).getRowCount());
76:
77: } catch (Exception e) {
78: e.printStackTrace();
79: fail(e.getMessage());
80: }
81: }
82:
83: }
|