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 compound 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 SQLParserTestCasesForCompoundConditions {
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: SQLParserTestCasesForCompoundConditions.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 parsing where clauses with compound conditions");
051:
052: suite
053: .addTest(new SQLParserTestCase(
054: "select col1,col2,col3 from mytable where not col1='abc'") {
055: public SelectStatement getExpectedSelect() {
056: SelectStatement select = new SelectStatement(
057: "mytable", "col1,col2,col3");
058: WhereClause where = new WhereClause();
059: select.setWhereClause(where);
060: Condition c = new SimpleCondition(
061: SimpleCondition.EQUALS, "col1", "abc");
062: where.add(c);
063: c.setNegated(true);
064: return select;
065: }
066: });
067: suite
068: .addTest(new SQLParserTestCase(
069: "select col1,col2,col3 from mytable where NOT (col1='abc')") {
070: public SelectStatement getExpectedSelect() {
071: SelectStatement select = new SelectStatement(
072: "mytable", "col1,col2,col3");
073: WhereClause where = new WhereClause();
074: select.setWhereClause(where);
075: Condition c = new SimpleCondition(
076: SimpleCondition.EQUALS, "col1", "abc");
077: where.add(c);
078: c.setNegated(true);
079: return select;
080: }
081: });
082: suite
083: .addTest(new SQLParserTestCase(
084: "select col1,col2,col3 from mytable where col1='abc' AND col2='def'") {
085: public SelectStatement getExpectedSelect() {
086: SelectStatement select = new SelectStatement(
087: "mytable", "col1,col2,col3");
088: WhereClause where = new WhereClause();
089: select.setWhereClause(where);
090: Condition c1 = new SimpleCondition(
091: SimpleCondition.EQUALS, "col1", "abc");
092: where.add(c1);
093: Condition c2 = new SimpleCondition(
094: SimpleCondition.EQUALS, "col2", "def");
095: where.add(c2);
096: where.add(CompoundCondition.AND);
097: return select;
098: }
099: });
100:
101: suite
102: .addTest(new SQLParserTestCase(
103: "select col1,col2,col3 from mytable where NOT (col1='abc' AND col2='def')") {
104: public SelectStatement getExpectedSelect() {
105: SelectStatement select = new SelectStatement(
106: "mytable", "col1,col2,col3");
107: WhereClause where = new WhereClause();
108: select.setWhereClause(where);
109: Condition c1 = new SimpleCondition(
110: SimpleCondition.EQUALS, "col1", "abc");
111: Condition c2 = new SimpleCondition(
112: SimpleCondition.EQUALS, "col2", "def");
113: CompoundCondition c = new CompoundCondition(
114: CompoundCondition.AND, c1, c2);
115: c.setNegated(true);
116: where.add(c);
117: return select;
118: }
119: });
120:
121: suite
122: .addTest(new SQLParserTestCase(
123: "select col1,col2,col3 from mytable where col1='abc' OR col2='def'") {
124: public SelectStatement getExpectedSelect() {
125: SelectStatement select = new SelectStatement(
126: "mytable", "col1,col2,col3");
127: WhereClause where = new WhereClause();
128: select.setWhereClause(where);
129: Condition c1 = new SimpleCondition(
130: SimpleCondition.EQUALS, "col1", "abc");
131: where.add(c1);
132: Condition c2 = new SimpleCondition(
133: SimpleCondition.EQUALS, "col2", "def");
134: where.add(c2);
135: where.add(CompoundCondition.OR);
136: return select;
137: }
138: });
139: suite
140: .addTest(new SQLParserTestCase(
141: "select col1,col2,col3 from mytable where (col1='abc' AND col2='def')") {
142: public SelectStatement getExpectedSelect() {
143: SelectStatement select = new SelectStatement(
144: "mytable", "col1,col2,col3");
145: WhereClause where = new WhereClause();
146: select.setWhereClause(where);
147: Condition c1 = new SimpleCondition(
148: SimpleCondition.EQUALS, "col1", "abc");
149: where.add(c1);
150: Condition c2 = new SimpleCondition(
151: SimpleCondition.EQUALS, "col2", "def");
152: where.add(c2);
153: where.add(CompoundCondition.AND);
154: return select;
155: }
156: });
157: suite
158: .addTest(new SQLParserTestCase(
159: "select col1,col2,col3 from mytable where (col1='abc' AND col2='def') OR (col1<'aaa' AND col2<'bbb'))") {
160: public SelectStatement getExpectedSelect() {
161: SelectStatement select = new SelectStatement(
162: "mytable", "col1,col2,col3");
163: WhereClause where = new WhereClause();
164: select.setWhereClause(where);
165: Condition c1 = new CompoundCondition(
166: CompoundCondition.AND,
167: new SimpleCondition(
168: SimpleCondition.EQUALS, "col1",
169: "abc"), new SimpleCondition(
170: SimpleCondition.EQUALS, "col2",
171: "def"));
172: where.add(c1);
173: Condition c2 = new CompoundCondition(
174: CompoundCondition.AND,
175: new SimpleCondition(
176: SimpleCondition.LESS_THAN,
177: "col1", "aaa"),
178: new SimpleCondition(
179: SimpleCondition.LESS_THAN,
180: "col2", "bbb"));
181: where.add(c2);
182: where.add(CompoundCondition.OR);
183: return select;
184: }
185: });
186:
187: return suite;
188: }
189: }
|