1- package com .googlecode .scheme2ddl ;
2-
3-
4- import org .testng .annotations .Test ;
5-
6- import static org .testng .Assert .assertNotEquals ;
7- import static org .testng .AssertJUnit .assertEquals ;
8-
9-
10- /**
11- * @author ar
12- * @since Date: 18.04.2015
13- */
14- public class DDLFormatterTest {
15-
16- private DDLFormatter ddlFormatter = new DDLFormatter ();
17-
18- @ Test
19- public void testReplaceActualSequenceValueWithOne () throws Exception {
20-
21- String s = "CREATE SEQUENCE \" TEST01\" .\" SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 2122 CACHE 20 NOORDER NOCYCLE ;\n " ;
22- String res = ddlFormatter .replaceActualSequenceValueWithOne (s );
23- assertEquals (
24- "CREATE SEQUENCE \" TEST01\" .\" SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;\n " +
25- "\r \n " +
26- "/* -- actual sequence value was replaced by scheme2ddl to 1 */"
27- , res );
28-
29- }
30-
31- @ Test
32- public void testReplaceActualSequenceValueWithOneOnWrongDDL () throws Exception {
33-
34- String s = "CREATE TABLE \" TEST01\" .\" SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 2122 CACHE 20 NOORDER NOCYCLE ;\n " ;
35- String res = ddlFormatter .replaceActualSequenceValueWithOne (s );
36- assertNotEquals (
37- "CREATE TABLE \" TEST01\" .\" SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;\n "
38- , res );
39-
40- }
1+ package com .googlecode .scheme2ddl ;
2+
3+
4+ import org .testng .annotations .Test ;
5+
6+ import static org .testng .Assert .assertNotEquals ;
7+ import static org .testng .AssertJUnit .assertEquals ;
8+
9+
10+ /**
11+ * @author ar
12+ * @since Date: 18.04.2015
13+ */
14+ public class DDLFormatterTest {
15+
16+ private DDLFormatter ddlFormatter = new DDLFormatter ();
17+
18+ @ Test
19+ public void testReplaceActualSequenceValueWithOne () throws Exception {
20+
21+ String s = "CREATE SEQUENCE \" TEST01\" .\" SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 2122 CACHE 20 NOORDER NOCYCLE ;\n " ;
22+ String res = ddlFormatter .replaceActualSequenceValueWithOne (s );
23+ assertEquals (
24+ "CREATE SEQUENCE \" TEST01\" .\" SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;\n " +
25+ "\r \n " +
26+ "/* -- actual sequence value was replaced by scheme2ddl to 1 */"
27+ , res );
28+
29+ }
30+
31+ @ Test
32+ public void testReplaceActualSequenceValueWithOneOnWrongDDL () throws Exception {
33+
34+ String s = "CREATE TABLE \" TEST01\" .\" SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 2122 CACHE 20 NOORDER NOCYCLE ;\n " ;
35+ String res = ddlFormatter .replaceActualSequenceValueWithOne (s );
36+ assertNotEquals (
37+ "CREATE TABLE \" TEST01\" .\" SEQ_01\" MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;\n "
38+ , res );
39+
40+ }
41+
42+
43+ @ Test
44+ public void testSortPreserveOriginalDDLIfNoSort () {
45+ String s = "\n CREATE UNIQUE INDEX \" HR\" .\" REG_ID_PK\" ON \" HR\" .\" REGIONS\" (\" REGION_ID\" ) \n " +
46+ " ;" ;
47+ String res = ddlFormatter .sortIndexesInDDL (s );
48+ assertEquals (s , res );
49+ }
50+
51+ @ Test
52+ public void testSortIndexes () {
53+ String s = " CREATE INDEX \" HR\" .\" A_IDX2\" ON \" HR\" .\" A\" (\" C2\" ) \n " +
54+ " ;\n " +
55+ " CREATE INDEX \" HR\" .\" A_IDX1\" ON \" HR\" .\" A\" (\" C3\" ) \n " +
56+ " ;" ;
57+ String res = ddlFormatter .sortIndexesInDDL (s );
58+ assertEquals (
59+ "\n CREATE INDEX \" HR\" .\" A_IDX1\" ON \" HR\" .\" A\" (\" C3\" ) \n " +
60+ " ;\n " +
61+ "CREATE INDEX \" HR\" .\" A_IDX2\" ON \" HR\" .\" A\" (\" C2\" ) \n " +
62+ " ;"
63+ , res );
64+ }
65+
66+ @ Test
67+ public void testSortIndexesUniq () {
68+ String s =
69+ " \n " +
70+ "CREATE UNIQUE INDEX \" HR\" .\" A_UNIQ2\" ON \" HR\" .\" A\" (\" C1\" , \" B2\" ) \n " +
71+ " ;\n " +
72+ " CREATE INDEX \" HR\" .\" A_IDX1\" ON \" HR\" .\" A\" (\" C1\" ) \n " +
73+ " ; " +
74+ "CREATE BITMAP INDEX \" HR\" .\" A_BITMAP_IDX\" ON \" HR\" .\" A\" (\" C1\" , \" C5\" ) \n " +
75+ " ;\n " ;
76+ String res = ddlFormatter .sortIndexesInDDL (s );
77+ assertEquals ("\n " +
78+ "CREATE BITMAP INDEX \" HR\" .\" A_BITMAP_IDX\" ON \" HR\" .\" A\" (\" C1\" , \" C5\" ) \n " +
79+ " ;\n " +
80+ "CREATE INDEX \" HR\" .\" A_IDX1\" ON \" HR\" .\" A\" (\" C1\" ) \n " +
81+ " ;\n " +
82+ "CREATE UNIQUE INDEX \" HR\" .\" A_UNIQ2\" ON \" HR\" .\" A\" (\" C1\" , \" B2\" ) \n " +
83+ " ;" , res );
84+ }
4185}
0 commit comments