forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropTest.java
More file actions
125 lines (107 loc) · 4.62 KB
/
DropTest.java
File metadata and controls
125 lines (107 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.drop;
import java.io.StringReader;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import static net.sf.jsqlparser.test.TestUtils.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class DropTest {
private final CCJSqlParserManager parserManager = new CCJSqlParserManager();
@Test
public void testDrop() throws JSQLParserException {
String statement = "DROP TABLE mytab";
Drop parsed = (Drop) parserManager.parse(new StringReader(statement));
assertEquals("TABLE", parsed.getType());
assertEquals("mytab", parsed.getName().getFullyQualifiedName());
assertEquals(statement, "" + parsed);
Drop created = new Drop().withType("TABLE").withName(new Table("mytab"));
assertDeparse(created, statement);
assertEqualsObjectTree(parsed, created);
}
@Test
public void testDropIndex() throws JSQLParserException {
String statement = "DROP INDEX myindex CASCADE";
Drop parsed = (Drop) parserManager.parse(new StringReader(statement));
assertEquals("INDEX", parsed.getType());
assertEquals("myindex", parsed.getName().getFullyQualifiedName());
assertEquals("CASCADE", parsed.getParameters().get(0));
assertEquals(statement, "" + parsed);
Drop created = new Drop().withType("INDEX").withName(new Table("myindex")).addParameters("CASCADE");
assertDeparse(created, statement);
assertEqualsObjectTree(parsed, created);
}
@Test
public void testDrop2() throws JSQLParserException {
Drop drop = (Drop) parserManager.parse(new StringReader("DROP TABLE \"testtable\""));
assertEquals("TABLE", drop.getType());
assertEquals("\"testtable\"", drop.getName().getFullyQualifiedName());
}
@Test
public void testDropIfExists() throws JSQLParserException {
String statement = "DROP TABLE IF EXISTS my_table";
Statement parsed = assertSqlCanBeParsedAndDeparsed(statement);
Drop created = new Drop().withType("TABLE").withIfExists(true).withName(new Table("my_table"));
assertDeparse(created, statement);
assertEqualsObjectTree(parsed, created);
}
@Test
public void testDropRestrictIssue510() throws JSQLParserException {
String statement = "DROP TABLE TABLE2 RESTRICT";
Statement parsed = assertSqlCanBeParsedAndDeparsed(statement);
Drop created = new Drop().withType("TABLE").withName(new Table("TABLE2")).addParameters(asList("RESTRICT"));
assertDeparse(created, statement);
assertEqualsObjectTree(parsed, created);
}
@Test
public void testDropViewIssue545() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP VIEW myview");
}
@Test
public void testDropViewIssue545_2() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP VIEW IF EXISTS myview");
}
@Test
public void testDropSchemaIssue855() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP SCHEMA myschema");
}
@Test
public void testDropSequence() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP SEQUENCE mysequence");
}
@Test
public void testOracleMultiColumnDrop() throws JSQLParserException {
//assertSqlCanBeParsedAndDeparsed("ALTER TABLE foo DROP (bar, baz)");
assertSqlCanBeParsedAndDeparsed("ALTER TABLE foo DROP (bar, baz) CASCADE");
}
@Test
public void testUniqueFunctionDrop() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP FUNCTION myFunc");
}
@Test
public void testZeroArgDropFunction() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP FUNCTION myFunc()");
}
@Test
public void testDropFunctionWithSimpleType() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP FUNCTION myFunc(integer, varchar)");
}
@Test
public void testDropFunctionWithNameAndType() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP FUNCTION myFunc(amount integer, name varchar)");
}
@Test
public void testDropFunctionWithNameAndParameterizedType() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("DROP FUNCTION myFunc(amount integer, name varchar(255))");
}
}