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: import org.mandarax.jdbc.server.sql.*;
023:
024: /**
025: * A test suite for SQL parser test cases. Tests simple conditions.
026: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
027: * @version 3.3.2 <29 December 2004>
028: * @since 3.0
029: */
030:
031: public class SQLParserTestCasesForSimpleConditions {
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: SQLParserTestCasesForSimpleConditions.class, args);
041: }
042:
043: /**
044: * Create a test suite.
045: * @return a test suite
046: */
047: public static TestSuite suite() {
048: TestSuite suite = new TestSuite(
049: "Test cases for parsing where clauses with simple conditions");
050:
051: suite.addTest(new SQLParserTestCase(
052: "select col1,col2,col3 from mytable where col1='abc'") {
053: public SelectStatement getExpectedSelect() {
054: SelectStatement select = new SelectStatement("mytable",
055: "col1,col2,col3");
056: WhereClause where = new WhereClause();
057: select.setWhereClause(where);
058: Condition c = new SimpleCondition(
059: SimpleCondition.EQUALS, "col1", "abc");
060: where.add(c);
061: return select;
062: }
063: });
064: suite.addTest(new SQLParserTestCase(
065: "select col1,col2,col3 from mytable where col1<'abc'") {
066: public SelectStatement getExpectedSelect() {
067: SelectStatement select = new SelectStatement("mytable",
068: "col1,col2,col3");
069: WhereClause where = new WhereClause();
070: select.setWhereClause(where);
071: Condition c = new SimpleCondition(
072: SimpleCondition.LESS_THAN, "col1", "abc");
073: where.add(c);
074: return select;
075: }
076: });
077: suite
078: .addTest(new SQLParserTestCase(
079: "select col1,col2,col3 from mytable where col1<='abc'") {
080: public SelectStatement getExpectedSelect() {
081: SelectStatement select = new SelectStatement(
082: "mytable", "col1,col2,col3");
083: WhereClause where = new WhereClause();
084: select.setWhereClause(where);
085: Condition c = new SimpleCondition(
086: SimpleCondition.LESS_THAN_OR_EQUALS,
087: "col1", "abc");
088: where.add(c);
089: return select;
090: }
091: });
092: suite.addTest(new SQLParserTestCase(
093: "select col1,col2,col3 from mytable where col1>'abc'") {
094: public SelectStatement getExpectedSelect() {
095: SelectStatement select = new SelectStatement("mytable",
096: "col1,col2,col3");
097: WhereClause where = new WhereClause();
098: select.setWhereClause(where);
099: Condition c = new SimpleCondition(
100: SimpleCondition.GREATER_THAN, "col1", "abc");
101: where.add(c);
102: return select;
103: }
104: });
105: suite
106: .addTest(new SQLParserTestCase(
107: "select col1,col2,col3 from mytable where col1>='abc'") {
108: public SelectStatement getExpectedSelect() {
109: SelectStatement select = new SelectStatement(
110: "mytable", "col1,col2,col3");
111: WhereClause where = new WhereClause();
112: select.setWhereClause(where);
113: Condition c = new SimpleCondition(
114: SimpleCondition.GREATER_THAN_OR_EQUALS,
115: "col1", "abc");
116: where.add(c);
117: return select;
118: }
119: });
120: suite
121: .addTest(new SQLParserTestCase(
122: "select col1,col2,col3 from mytable where col1!='abc'") {
123: public SelectStatement getExpectedSelect() {
124: SelectStatement select = new SelectStatement(
125: "mytable", "col1,col2,col3");
126: WhereClause where = new WhereClause();
127: select.setWhereClause(where);
128: Condition c = new SimpleCondition(
129: SimpleCondition.NOT_EQUALS, "col1",
130: "abc");
131: where.add(c);
132: return select;
133: }
134: });
135: suite
136: .addTest(new SQLParserTestCase(
137: "select col1,col2,col3 from mytable where col1 like 'abc'") {
138: public SelectStatement getExpectedSelect() {
139: SelectStatement select = new SelectStatement(
140: "mytable", "col1,col2,col3");
141: WhereClause where = new WhereClause();
142: select.setWhereClause(where);
143: Condition c = new SimpleCondition(
144: SimpleCondition.LIKE, "col1", "abc");
145: where.add(c);
146: return select;
147: }
148: });
149: suite
150: .addTest(new SQLParserTestCase(
151: "select col1,col2,col3 from mytable where (col1='abc')") {
152: public SelectStatement getExpectedSelect() {
153: SelectStatement select = new SelectStatement(
154: "mytable", "col1,col2,col3");
155: WhereClause where = new WhereClause();
156: select.setWhereClause(where);
157: Condition c = new SimpleCondition(
158: SimpleCondition.EQUALS, "col1", "abc");
159: where.add(c);
160: return select;
161: }
162: });
163:
164: return suite;
165: }
166: }
|