001: package test.org.mandarax.jdbc;
002:
003: /*
004: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: import junit.framework.TestSuite;
022:
023: /**
024: * A test suite for queries.
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 QueryTests1 implements TestURLs {
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(QueryTests1.class,
040: args);
041: }
042:
043: /**
044: * Get the test suite.
045: * @return a test suite
046: */
047: public static TestSuite suite() {
048:
049: TestSuite suite = new TestSuite(
050: "SQL Query test suite 1 - uses xkb, zkb and ruleml sources");
051: addTests1(suite,
052: "select * from is_grandfather_of where slot1='Max'",
053: "slot2", "Klaus");
054: addTests2(suite,
055: "select * from is_grandfather_of where slot1=?",
056: "slot2", "Klaus", "Max");
057: addTests3(
058: suite,
059: "select distinct * from is_oncle_of where slot1='Jens'",
060: 3);
061: addTests3(suite,
062: "select * from is_oncle_of where slot1='Jens'", 6);
063: return suite;
064: }
065:
066: /**
067: * Add a simple query test cases using statements. Check first result, one column.
068: * @param suite the test suite
069: * @param sql the sql
070: * @param column the result column name
071: * @param result the expected result
072: */
073: private static void addTests1(TestSuite suite, String sql,
074: String colName, Object expected) {
075: suite.addTest(new QueryTestCase1(QueryTests1.TEST_FAM_ZKB, sql,
076: colName, expected));
077: suite.addTest(new QueryTestCase1(QueryTests1.TEST_FAM_XKB, sql,
078: colName, expected));
079: suite.addTest(new QueryTestCase1(QueryTests1.TEST_FAM_RULE_ML,
080: sql, colName, expected));
081: }
082:
083: /**
084: * Add a simple query test cases using prepared statements. Check first result, one column.
085: * @param suite the test suite
086: * @param sql the sql
087: * @param column the result column name
088: * @param result the expected result
089: * @param value the value to be inserted into the prepared statement
090: */
091: private static void addTests2(TestSuite suite, String sql,
092: String colName, Object expected, Object value) {
093: suite.addTest(new QueryTestCase2(QueryTests1.TEST_FAM_ZKB, sql,
094: colName, expected, value));
095: suite.addTest(new QueryTestCase2(QueryTests1.TEST_FAM_XKB, sql,
096: colName, expected, value));
097: suite.addTest(new QueryTestCase2(QueryTests1.TEST_FAM_RULE_ML,
098: sql, colName, expected, value));
099: suite.addTest(new QueryTestCase3(QueryTests1.TEST_FAM_ZKB, sql,
100: colName, expected, value));
101: suite.addTest(new QueryTestCase3(QueryTests1.TEST_FAM_XKB, sql,
102: colName, expected, value));
103: suite.addTest(new QueryTestCase3(QueryTests1.TEST_FAM_RULE_ML,
104: sql, colName, expected, value));
105: }
106:
107: /**
108: * Add a simple query tests counting the results (check features such as distinct).
109: * @param suite the test suite
110: * @param sql the sql
111: * @param expected the number of expected results
112: */
113: private static void addTests3(TestSuite suite, String sql,
114: int expected) {
115: suite.addTest(new QueryTestCase4(QueryTests1.TEST_FAM_ZKB, sql,
116: expected));
117: suite.addTest(new QueryTestCase4(QueryTests1.TEST_FAM_XKB, sql,
118: expected));
119: // if test query queries for the oncle, ruleml is incorrect since not_equal is not interpreted !!
120: // suite.addTest(new QueryTestCase4(QueryTests.TEST_FAM_RULE_ML,sql,expected));
121: }
122: }
|