001: /*
002: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">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: package test.org.mandarax.zkb;
019:
020: import junit.framework.Test;
021: import junit.framework.TestSuite;
022: import org.mandarax.zkb.*;
023: import org.mandarax.zkb.framework.*;
024: import org.mandarax.util.comparators.*;
025: import java.util.*;
026:
027: /**
028: * Test suite for ZKB.
029: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
030: * @version 3.4 <7 March 05>
031: * @since 2.2
032: */
033: public class ZKBTests {
034:
035: /**
036: * Launch the test suite. See TestRunner for interpretation
037: * of command line parameters.
038: * @see test.org.mandarax.testsupport.TestRunner
039: * @param args parameters
040: */
041: public static void main(String[] args) {
042: org.apache.log4j.BasicConfigurator.configure();
043: test.org.mandarax.testsupport.TestRunner.run(ZKBTests.class,
044: args);
045: }
046:
047: /**
048: * Get the test suite.
049: * @return the test suite
050: */
051: public static Test suite() {
052: TestSuite suite = new TestSuite(
053: "Test cases for the mandarax ZKB module");
054:
055: addTests(new ZKBDriver_1_0(), suite);
056: addTests(new ZKBDriver_1_1(), suite);
057: addTests(new ZKBDriver_2_0(), suite);
058:
059: return suite;
060: }
061:
062: /**
063: * Add tests for a certain driver to a test suite.
064: * @param driver the ZKB driver tested
065: * @param suite a test suite
066: */
067: private static void addTests(ZKBDriver driver, TestSuite suite) {
068: addTests(driver, BinarySerializationOPS.class, suite, true);
069: addTests(driver, XMLSerializationOPS.class, suite, true);
070: addTests(driver, BinarySerializationOPS.class, suite, false);
071: addTests(driver, XMLSerializationOPS.class, suite, false);
072: }
073:
074: /**
075: * Add tests for a certain driver / OPS combination to a test suite.
076: * @param driver the ZKB driver tested
077: * @param ops the object persistency service class
078: * @param suite a test suite
079: * @param zipOrFolder whether the zkb is stored in a zip file or folder true - zip, false - folder
080: */
081: private static void addTests(ZKBDriver driver, Class opsClass,
082: TestSuite suite, boolean zipOrFolder) {
083: try {
084:
085: // 1 clause set
086: suite.addTest(new ZKBTestCase4ClauseSets(driver,
087: (ObjectPersistencyService) opsClass.newInstance(),
088: TestData.fact1(), "tc1", zipOrFolder));
089: suite.addTest(new ZKBTestCase4ClauseSets(driver,
090: (ObjectPersistencyService) opsClass.newInstance(),
091: TestData.fact2(), "tc2", zipOrFolder));
092: suite.addTest(new ZKBTestCase4ClauseSets(driver,
093: (ObjectPersistencyService) opsClass.newInstance(),
094: TestData.fact3(), "tc3", zipOrFolder));
095: suite.addTest(new ZKBTestCase4ClauseSets(driver,
096: (ObjectPersistencyService) opsClass.newInstance(),
097: TestData.fact4(), "tc4", zipOrFolder));
098: suite.addTest(new ZKBTestCase4ClauseSets(driver,
099: (ObjectPersistencyService) opsClass.newInstance(),
100: TestData.fact5(), "tc5", zipOrFolder));
101: suite.addTest(new ZKBTestCase4ClauseSets(driver,
102: (ObjectPersistencyService) opsClass.newInstance(),
103: TestData.fact6(), "tc6", zipOrFolder));
104: suite.addTest(new ZKBTestCase4ClauseSets(driver,
105: (ObjectPersistencyService) opsClass.newInstance(),
106: TestData.fact7(), "tc7", zipOrFolder));
107: suite.addTest(new ZKBTestCase4ClauseSets(driver,
108: (ObjectPersistencyService) opsClass.newInstance(),
109: TestData.fact8(), "tc8", zipOrFolder));
110: suite.addTest(new ZKBTestCase4ClauseSets(driver,
111: (ObjectPersistencyService) opsClass.newInstance(),
112: TestData.fact9(), "tc9", zipOrFolder));
113: suite.addTest(new ZKBTestCase4ClauseSets(driver,
114: (ObjectPersistencyService) opsClass.newInstance(),
115: TestData.fact10(), "tc10", zipOrFolder));
116: suite.addTest(new ZKBTestCase4ClauseSets(driver,
117: (ObjectPersistencyService) opsClass.newInstance(),
118: TestData.rule1(), "tc11", zipOrFolder));
119: suite.addTest(new ZKBTestCase4ClauseSets(driver,
120: (ObjectPersistencyService) opsClass.newInstance(),
121: TestData.andRule(), "tc12", zipOrFolder));
122: suite.addTest(new ZKBTestCase4ClauseSets(driver,
123: (ObjectPersistencyService) opsClass.newInstance(),
124: TestData.orRule(), "tc13", zipOrFolder));
125: suite.addTest(new ZKBTestCase4ClauseSets(driver,
126: (ObjectPersistencyService) opsClass.newInstance(),
127: TestData.sqlClauseSet(), "tc14", zipOrFolder));
128: suite.addTest(new ZKBTestCase4ClauseSets(driver,
129: (ObjectPersistencyService) opsClass.newInstance(),
130: TestData.negRule(), "tc15", zipOrFolder));
131:
132: // attachment
133: Object attachment = new java.util.Date();
134: suite.addTest(new ZKBTestCase4ClauseSets(driver,
135: (ObjectPersistencyService) opsClass.newInstance(),
136: TestData.fact1(), attachment, "tc16", zipOrFolder));
137:
138: // 1 query
139: suite.addTest(new ZKBTestCase4Queries(driver,
140: (ObjectPersistencyService) opsClass.newInstance(),
141: TestData.query1(), "tc17", zipOrFolder));
142: suite.addTest(new ZKBTestCase4Queries(driver,
143: (ObjectPersistencyService) opsClass.newInstance(),
144: TestData.query2(), "tc18", zipOrFolder));
145: suite.addTest(new ZKBTestCase4Queries(driver,
146: (ObjectPersistencyService) opsClass.newInstance(),
147: TestData.query3(), "tc19", zipOrFolder));
148:
149: // 2 clause sets/ 2 queries - check whether order is maintained
150: suite.addTest(new ZKBTestCase4ClauseSets(driver,
151: (ObjectPersistencyService) opsClass.newInstance(),
152: TestData.fact1(), TestData.fact2(), "tc20",
153: zipOrFolder));
154: suite.addTest(new ZKBTestCase4Queries(driver,
155: (ObjectPersistencyService) opsClass.newInstance(),
156: TestData.query1(), TestData.query2(), "tc21",
157: zipOrFolder));
158:
159: // comparator
160: DefaultClauseSetComparator comp = new DefaultClauseSetComparator();
161: suite.addTest(new ZKBTestCase4Comparators(driver,
162: (ObjectPersistencyService) opsClass.newInstance(),
163: comp, "tc22", zipOrFolder));
164:
165: // comparator with non default top level order
166: comp = new DefaultClauseSetComparator();
167: comp.setTopLevelOrder(new String[] { comp.RULES,
168: comp.FACTS, comp.SQL_CLAUSE_SETS, comp.OTHERS });
169: suite.addTest(new ZKBTestCase4Comparators(driver,
170: (ObjectPersistencyService) opsClass.newInstance(),
171: comp, "tc23", zipOrFolder));
172:
173: // comparator with non default comp order for rules
174: comp = new DefaultClauseSetComparator();
175: comp
176: .setComparators4Rules(new Comparator[] {
177: new PreferRulesWithLessNegatedPrerequisites(),
178: new PreferRulesWithMorePrerequisites(),
179: new PreferRulesWithLessVariablesInPrerequisites() });
180: suite.addTest(new ZKBTestCase4Comparators(driver,
181: (ObjectPersistencyService) opsClass.newInstance(),
182: comp, "tc24", zipOrFolder));
183:
184: // test cases - not supported by older drivers
185: if (!(driver instanceof ZKBDriver_1_0)
186: && !(driver instanceof ZKBDriver_1_1)) {
187: suite.addTest(new ZKBTestCase4Testcases(driver,
188: (ObjectPersistencyService) opsClass
189: .newInstance(), TestData.testCase1(),
190: "tc25", zipOrFolder));
191: suite.addTest(new ZKBTestCase4Testcases(driver,
192: (ObjectPersistencyService) opsClass
193: .newInstance(), TestData.testCase2(),
194: "tc26", zipOrFolder));
195: suite.addTest(new ZKBTestCase4Testcases(driver,
196: (ObjectPersistencyService) opsClass
197: .newInstance(), TestData.testCase3(),
198: "tc27", zipOrFolder));
199: suite.addTest(new ZKBTestCase4Testcases(driver,
200: (ObjectPersistencyService) opsClass
201: .newInstance(), TestData.testCase4(),
202: "tc28", zipOrFolder));
203: suite.addTest(new ZKBTestCase4Testcases(driver,
204: (ObjectPersistencyService) opsClass
205: .newInstance(), TestData.testCase5(),
206: "tc29", zipOrFolder));
207: suite.addTest(new ZKBTestCase4Testcases(driver,
208: (ObjectPersistencyService) opsClass
209: .newInstance(), TestData.testCase5(),
210: "tc30", zipOrFolder));
211: }
212: } catch (Exception x) {
213: x.printStackTrace();
214: }
215:
216: }
217:
218: }
|