forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateSequenceTest.java
More file actions
163 lines (137 loc) · 5.99 KB
/
CreateSequenceTest.java
File metadata and controls
163 lines (137 loc) · 5.99 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2020 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.create;
import static net.sf.jsqlparser.test.TestUtils.*;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.schema.Database;
import net.sf.jsqlparser.schema.Sequence;
import net.sf.jsqlparser.schema.Sequence.Parameter;
import net.sf.jsqlparser.schema.Sequence.ParameterType;
import net.sf.jsqlparser.statement.create.sequence.CreateSequence;
import org.junit.jupiter.api.Test;
public class CreateSequenceTest {
@Test
public void testCreateSequence_noParams() throws JSQLParserException {
String statement = "CREATE SEQUENCE my_seq";
assertSqlCanBeParsedAndDeparsed(statement);
assertDeparse(new CreateSequence().withSequence(new Sequence().withName("my_seq")),
statement);
}
@Test
public void testCreateSequence_withIncrement() throws JSQLParserException {
String statement = "CREATE SEQUENCE db.schema.my_seq INCREMENT BY 1";
assertSqlCanBeParsedAndDeparsed(statement);
assertDeparse(new CreateSequence().withSequence(
new Sequence().withDatabase(new Database("db")).withSchemaName("schema")
.withName("my_seq")
.addParameters(new Parameter(ParameterType.INCREMENT_BY).withValue(1L))),
statement);
}
@Test
public void testCreateSequence_withIncrementPostres() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE db.schema.my_seq INCREMENT 1");
}
@Test
public void testCreateSequence_withStart() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq START WITH 10");
}
@Test
public void testCreateSequence_withStartPostgres() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq START 10");
}
@Test
public void testCreateSequence_withMaxValue() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq MAXVALUE 5");
}
@Test
public void testCreateSequence_withNoMaxValue() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq NOMAXVALUE");
}
@Test
public void testCreateSequence_withMinValue() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq MINVALUE 5");
}
@Test
public void testCreateSequence_withNoMinValue() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq NOMINVALUE");
}
@Test
public void testCreateSequence_withCycle() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq CYCLE");
}
@Test
public void testCreateSequence_withNoCycle() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq NOCYCLE");
}
@Test
public void testCreateSequence_withCache() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq CACHE 10");
}
@Test
public void testCreateSequence_withNoCache() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq NOCACHE");
}
@Test
public void testCreateSequence_withOrder() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq ORDER");
}
@Test
public void testCreateSequence_withNoOrder() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq NOORDER");
}
@Test
public void testCreateSequence_withKeep() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq KEEP");
}
@Test
public void testCreateSequence_withNoKeep() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq NOKEEP");
}
@Test
public void testCreateSequence_withSession() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq SESSION");
}
@Test
public void testCreateSequence_withGlobal() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_seq GLOBAL");
}
/**
* Verifies that we declare the parameter options in the order we found them
*/
@Test
public void testCreateSequence_preservesParamOrder() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("CREATE SEQUENCE my_sec INCREMENT BY 2 START WITH 10");
assertSqlCanBeParsedAndDeparsed(
"CREATE SEQUENCE my_sec START WITH 2 INCREMENT BY 5 NOCACHE");
String statement = "CREATE SEQUENCE my_sec START WITH 2 INCREMENT BY 5 CACHE 200 CYCLE";
assertSqlCanBeParsedAndDeparsed(statement);
assertDeparse(new CreateSequence().withSequence(new Sequence().withName("my_sec")
.addParameters(asList(
new Parameter(ParameterType.START_WITH).withValue(2L),
new Parameter(ParameterType.INCREMENT_BY).withValue(5L),
new Parameter(ParameterType.CACHE).withValue(200L),
new Parameter(ParameterType.CYCLE)))),
statement);
}
@Test
public void testCreateSequence_withAsDataType() throws JSQLParserException {
String statement =
"CREATE SEQUENCE public.activites_activite_id_seq AS integer START WITH 1 INCREMENT BY 1 NOMINVALUE NOMAXVALUE CACHE 1";
assertSqlCanBeParsedAndDeparsed(statement);
}
@Test
public void testCreateSequence_withAsDataTypeSimple() throws JSQLParserException {
String statement = "CREATE SEQUENCE my_seq AS integer";
assertSqlCanBeParsedAndDeparsed(statement);
assertDeparse(new CreateSequence().withSequence(
new Sequence().withName("my_seq").withDataType("integer")),
statement);
}
}