01: /*
02: * DdlCommandTest.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.commands;
13:
14: import junit.framework.TestCase;
15: import workbench.TestUtil;
16: import workbench.interfaces.StatementRunner;
17: import workbench.sql.StatementRunnerResult;
18:
19: /**
20: *
21: * @author support@sql-workbench.net
22: */
23: public class DdlCommandTest extends TestCase {
24:
25: public DdlCommandTest(String testName) {
26: super (testName);
27: }
28:
29: public void testGetTypeAndObject() throws Exception {
30: try {
31: // detection of the type is already tested for SqlUtil.getCreateType()
32: // so we only need to test getName();
33: String sql = "-- test\ncreate or \t replace\n\nprocedure bla";
34: String name = DdlCommand.CREATE.getObjectName(sql);
35: assertEquals("bla", name);
36:
37: sql = "-- test\ncreate \n\ntrigger test_trg for mytable";
38: name = DdlCommand.CREATE.getObjectName(sql);
39: assertEquals("test_trg", name);
40:
41: sql = "-- test\ncreate function \n\n myfunc\n as something";
42: name = DdlCommand.CREATE.getObjectName(sql);
43: assertEquals("myfunc", name);
44:
45: sql = "-- test\ncreate or replace package \n\n some_package \t\t\n as something";
46: name = DdlCommand.CREATE.getObjectName(sql);
47: assertEquals("some_package", name);
48:
49: sql = "-- test\ncreate package body \n\n some_body \t\t\n as something";
50: name = DdlCommand.CREATE.getObjectName(sql);
51: assertEquals("some_body", name);
52:
53: } catch (Exception e) {
54: e.printStackTrace();
55: fail(e.getMessage());
56: }
57: }
58:
59: public void testIgnoreDropErrors() {
60: try {
61: TestUtil util = new TestUtil("ignoreDrop");
62: StatementRunner runner = util
63: .createConnectedStatementRunner();
64: String sql = "drop table does_not_exist";
65: runner.setIgnoreDropErrors(true);
66: runner.runStatement(sql, 0, 0);
67: StatementRunnerResult result = runner.getResult();
68: assertTrue(result.isSuccess());
69:
70: runner.setIgnoreDropErrors(false);
71: runner.setUseSavepoint(true);
72: runner.runStatement(sql, 0, 0);
73: result = runner.getResult();
74: assertFalse(result.isSuccess());
75:
76: } catch (Exception e) {
77: e.printStackTrace();
78: fail(e.getMessage());
79: }
80: }
81:
82: }
|