01: /*
02: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package test.org.mandarax.jdbc.parser;
20:
21: import org.mandarax.jdbc.server.parser.SQL;
22: import org.mandarax.jdbc.server.sql.SelectStatement;
23: import junit.framework.TestCase;
24:
25: /**
26: * A generic test case to validate SQL statements.
27: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
28: * @version 3.3.2 <29 December 2004>
29: * @since 3.0
30: */
31:
32: public class SQLValidationTestCase extends TestCase {
33: private boolean shouldFail = false;
34: private String sql = null;
35:
36: public SQLValidationTestCase(String sql, boolean shouldFail) {
37: super ("test");
38: this .shouldFail = shouldFail;
39: this .sql = sql;
40: }
41:
42: public SQLValidationTestCase(String sql) {
43: this (sql, false);
44: }
45:
46: public void test() throws Exception {
47: SQL parser = new SQL(new java.io.StringReader(sql));
48: SelectStatement select = new SelectStatement();
49: if (shouldFail) {
50: try {
51: parser.Select(select);
52: throw new AssertionError("This SQL should fail: " + sql);
53: } catch (Throwable x) {
54: assertTrue(true);
55: }
56: } else {
57: parser.Select(select);
58: }
59: }
60:
61: /**
62: * Convert the object to a string.
63: * @return the string representation of this object
64: */
65: public String toString() {
66: String msg = shouldFail ? "Test whether this SQL is rejected: "
67: : "Test whether this SQL is accepted: ";
68: return msg + sql;
69: }
70: }
|