001: /*
002: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package test.org.mandarax.jdbc.parser;
020:
021: import junit.framework.TestSuite;
022:
023: /**
024: * A test suite for SQL validation test cases.
025: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
026: * @version 3.3.2 <29 December 2004>
027: * @since 3.0
028: */
029:
030: public class SQLValidationTestCases {
031:
032: /**
033: * Launch the test suite. See TestRunner for interpretation
034: * of command line parameters.
035: * @see test.org.mandarax.testsupport.TestRunner
036: * @param args parameters
037: */
038: public static void main(String[] args) {
039: test.org.mandarax.testsupport.TestRunner.run(
040: SQLValidationTestCases.class, args);
041: }
042:
043: /**
044: * Create a test suite.
045: * @return a test suite
046: */
047: public static TestSuite suite() {
048:
049: TestSuite suite = new TestSuite(
050: "Test cases for the SQL parser (check whether SQL commands are accepted)");
051:
052: suite
053: .addTest(new SQLValidationTestCase(
054: "select * from mytable"));
055: suite.addTest(new SQLValidationTestCase(
056: "select * from default.mytable"));
057: suite
058: .addTest(new SQLValidationTestCase(
059: "SELECT * FROM mytable"));
060: suite
061: .addTest(new SQLValidationTestCase(
062: "Select * From mytable"));
063: suite
064: .addTest(new SQLValidationTestCase(
065: "seLecT * fRoM mytable"));
066: suite.addTest(new SQLValidationTestCase(
067: "select col1 from mytable"));
068: suite.addTest(new SQLValidationTestCase(
069: "select col1,col2 from mytable"));
070: suite.addTest(new SQLValidationTestCase(
071: "select col1,col2 from mytable where col1='test'"));
072: suite.addTest(new SQLValidationTestCase(
073: "select col1,col2 from mytable WHERE col1='test'"));
074: suite.addTest(new SQLValidationTestCase(
075: "select col1,col2 from mytable Where col1='test'"));
076: suite.addTest(new SQLValidationTestCase(
077: "select col1,col2 from mytable wHerE col1='test'"));
078: suite.addTest(new SQLValidationTestCase(
079: "select col1,col2 from mytable where col1!='test'"));
080: suite
081: .addTest(new SQLValidationTestCase(
082: "select col1,col2 from mytable where col1=test",
083: false));
084: // bugfix reported in Mandarax 3.2 / 3.3 - literals with whitespaces not parsed correctly
085: suite
086: .addTest(new SQLValidationTestCase(
087: "select col1,col2 from mytable where col1='test with whitespaces'"));
088: suite.addTest(new SQLValidationTestCase(
089: "select col1,col2 from mytable where col1=42"));
090: suite.addTest(new SQLValidationTestCase(
091: "select col1,col2 from mytable where col1<42"));
092: suite.addTest(new SQLValidationTestCase(
093: "select col1,col2 from mytable where col1>42"));
094: suite.addTest(new SQLValidationTestCase(
095: "select col1,col2 from mytable where col1<=42"));
096: suite.addTest(new SQLValidationTestCase(
097: "select col1,col2 from mytable where col1>=42"));
098: suite
099: .addTest(new SQLValidationTestCase(
100: "select col1,col2 from mytable where col1 like 'abc%_'"));
101: suite.addTest(new SQLValidationTestCase(
102: "select col1,col2 from mytable where col1=null"));
103: suite
104: .addTest(new SQLValidationTestCase(
105: "select col1,col2 from mytable where col1=nulle",
106: false));
107: suite
108: .addTest(new SQLValidationTestCase(
109: "select col1,col2 from mytable where col1='a' and col2='b'"));
110: suite
111: .addTest(new SQLValidationTestCase(
112: "select col1,col2 from mytable where col1='a' and col2='b' and col3='c'"));
113: suite
114: .addTest(new SQLValidationTestCase(
115: "select col1,col2 from mytable where not (col1=null and col2=null)"));
116: suite
117: .addTest(new SQLValidationTestCase(
118: "select col1,col2 from mytable where col1='a' or col2='b'"));
119: suite
120: .addTest(new SQLValidationTestCase(
121: "select col1,col2 from mytable where col1='a' or col2='b' or col3='c'"));
122: suite
123: .addTest(new SQLValidationTestCase(
124: "select col1,col2 from mytable where not (col1=null or col2=null)"));
125: suite
126: .addTest(new SQLValidationTestCase(
127: "select distinct col1,col2 from mytable where not (col1=null or col2=null)"));
128: // order by
129: suite.addTest(new SQLValidationTestCase(
130: "select col1,col2 from mytable order by col1"));
131: suite.addTest(new SQLValidationTestCase(
132: "select col1,col2 from mytable order by col1,col2"));
133: suite
134: .addTest(new SQLValidationTestCase(
135: "select col1,col2 from mytable order by col1,col2 asc"));
136: suite
137: .addTest(new SQLValidationTestCase(
138: "select col1,col2 from mytable order by col1,col2 desc"));
139: suite
140: .addTest(new SQLValidationTestCase(
141: "select col1,col2 from mytable order by col1 asc,col2 desc"));
142: suite.addTest(new SQLValidationTestCase(
143: "select col1,col2 from mytable order by col1 asc"));
144: suite.addTest(new SQLValidationTestCase(
145: "select col1,col2 from mytable order by col1 desc"));
146: suite
147: .addTest(new SQLValidationTestCase(
148: "select col1,col2 from mytable where col1='a' order by col1 desc"));
149: suite
150: .addTest(new SQLValidationTestCase(
151: "select col1,col2 from mytable where col1='a' or col1='b' order by col1 desc"));
152: // group by
153: suite.addTest(new SQLValidationTestCase(
154: "select col1,col2 from mytable group by col1"));
155: suite.addTest(new SQLValidationTestCase(
156: "select col1,col2 from mytable group by col1, col2"));
157: suite
158: .addTest(new SQLValidationTestCase(
159: "select col1,col2 from mytable group by col1, col2 having col1='a'"));
160: // bugfix reported in Mandarax 3.2 / 3.3 - literals with whitespaces not parsed correctly
161: suite
162: .addTest(new SQLValidationTestCase(
163: "select col1,col2 from mytable group by col1, col2 having col1='a and whitespace'"));
164: suite
165: .addTest(new SQLValidationTestCase(
166: "select col1,col2 from mytable group by col1, col2 having col1='a' and col2='a'"));
167: suite
168: .addTest(new SQLValidationTestCase(
169: "select col1,col2 from mytable group by col1, col2 having avg(col3)='a'"));
170: suite
171: .addTest(new SQLValidationTestCase(
172: "select col2,avg(col1),col2,min(col1),max(col1),sum(col1) from mytable group by col1, col2 having avg(col3)='a'"));
173: suite
174: .addTest(new SQLValidationTestCase(
175: "select col2,avg(col1),col2,min(col1),max(col1),sum(col1) from mytable group by col1, col2 order by avg(col3)"));
176: suite
177: .addTest(new SQLValidationTestCase(
178: "select col2,avg(col1),col2,min(col1),max(col1),sum(col1) from mytable group by col1, col2 order by avg(col3) desc"));
179: suite
180: .addTest(new SQLValidationTestCase(
181: "select col2,avg(col1),col2,min(col1),max(col1),sum(col1) from mytable group by col1, col2 order by avg(col3) asc"));
182: suite
183: .addTest(new SQLValidationTestCase(
184: "select col2,avg(col1),col2,min(col1),max(col1),sum(col1) from mytable group by col1, col2 order by col1 desc,avg(col3) asc"));
185: suite
186: .addTest(new SQLValidationTestCase(
187: "select col2,avg(col1),col2,min(col1),max(col1),sum(col1) from mytable where col3='magic' group by col1, col2 order by col1 desc,avg(col3) asc"));
188: suite
189: .addTest(new SQLValidationTestCase(
190: "select col2,avg(col1),col2,min(col1),max(col1),sum(col1) from mytable where col3='magic' group by col1, col2 having col1='b' and avg(col3)='a' order by col1 desc, avg(col3) asc"));
191: // count
192: suite.addTest(new SQLValidationTestCase(
193: "select count(*) from mytable"));
194: suite.addTest(new SQLValidationTestCase(
195: "select count(*) from mytable group by col1"));
196: suite.addTest(new SQLValidationTestCase(
197: "select count(*),col1 from mytable"));
198:
199: //
200: suite.addTest(new SQLValidationTestCase(
201: "select * from is_father_of where father='F '"));
202: return suite;
203: }
204: }
|