KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > regression > TestCaseBasic


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP All rights
3  * reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met: 1.
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer. 2. Redistributions in
9  * binary form must reproduce the above copyright notice, this list of
10  * conditions and the following disclaimer in the documentation and/or other
11  * materials provided with the distribution. 3. The name of the author may not
12  * be used to endorse or promote products derived from this software without
13  * specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $Id: TestCaseBasic.java,v 1.7 2005/02/21 12:18:40 andy_seaborne Exp $
27  */

28
29 package com.hp.hpl.jena.regression;
30
31 import com.hp.hpl.jena.rdf.model.*;
32
33
34 import junit.framework.TestCase;
35
36 /**
37  * <p>
38  * This is a wrapper class, which implements a set of basic regression tests as
39  * a set of JUnit tests.
40  * </p>
41  *
42  * <p>
43  * This is the first step of reworking the old Regression tests as a JUnit test
44  * suite. This is a simple wrapper class for the Regression test package. The
45  * idea is that if time permits (fat chance) the old regression tests will be
46  * reworked properly into this framework.
47  * </p>
48  *
49  * <p>
50  * This class is inteded to be subclassed with setup and teardown methods to
51  * create models required for the tests.
52  * </p>
53  *
54  * @author bwm
55  * @version $Name: $ $Revision: 1.7 $ $Date: 2005/02/21 12:18:40 $
56  */

57 public class TestCaseBasic extends TestCase {
58
59     protected Model m1 = null;
60     protected Model m2 = null;
61     protected Model m3 = null;
62     protected Model m4 = null;
63
64     public TestCaseBasic(String JavaDoc name) {
65         super(name);
66     }
67
68     public void test0() {
69         // empty the test models in case they are persistent
70
empty(m1);
71         empty(m2);
72         empty(m3);
73         empty(m4);
74     }
75
76     protected void empty(Model m) {
77         try {
78             StmtIterator iter = m.listStatements();
79             while (iter.hasNext()) {
80                 iter.nextStatement();
81                 iter.remove();
82             }
83             assertTrue(m.size() == 0);
84         } catch (Exception JavaDoc e) {
85             System.err.println(e);
86             assertTrue(false);
87         }
88     }
89
90     public void test1() {
91         try {
92             Regression test = new Regression();
93             test.test1(m1);
94             assertTrue(!test.getErrors());
95         } catch (Exception JavaDoc e) {
96             System.out.println(e);
97             assertTrue(false);
98         }
99     }
100
101     public void test2() {
102         try {
103             Regression test = new Regression();
104             test.test2(m1);
105             assertTrue(!test.getErrors());
106         } catch (Exception JavaDoc e) {
107             System.out.println(e);
108             assertTrue(false);
109         }
110     }
111
112     public void test3() {
113         try {
114             Regression test = new Regression();
115             test.test3(m1);
116             assertTrue(!test.getErrors());
117         } catch (Exception JavaDoc e) {
118             System.out.println(e);
119             assertTrue(false);
120         }
121     }
122
123     public void test4() {
124         try {
125             Regression test = new Regression();
126             test.test4(m1);
127             assertTrue(!test.getErrors());
128         } catch (Exception JavaDoc e) {
129             System.out.println(e);
130             assertTrue(false);
131         }
132     }
133
134     public void test5() {
135         try {
136             Regression test = new Regression();
137             test.test5(m1);
138             assertTrue(!test.getErrors());
139         } catch (Exception JavaDoc e) {
140             System.out.println(e);
141             assertTrue(false);
142         }
143     }
144
145     public void test6() {
146         try {
147             Regression test = new Regression();
148             test.test6(m1);
149             assertTrue(!test.getErrors());
150         } catch (Exception JavaDoc e) {
151             System.out.println(e);
152             assertTrue(false);
153         }
154     }
155
156     public void test7() {
157         try {
158             Regression test = new Regression();
159             test.test7(m1, m2);
160             assertTrue(!test.getErrors());
161         } catch (Exception JavaDoc e) {
162             System.out.println(e);
163             assertTrue(false);
164         }
165     }
166
167     public void test8() {
168         try {
169             Regression test = new Regression();
170             test.test8(m1);
171             assertTrue(!test.getErrors());
172         } catch (Exception JavaDoc e) {
173             System.out.println(e);
174             assertTrue(false);
175         }
176     }
177
178     public void test9() {
179         try {
180             Regression test = new Regression();
181             test.test9(m2);
182             assertTrue(!test.getErrors());
183         } catch (Exception JavaDoc e) {
184             System.out.println(e);
185             assertTrue(false);
186         }
187     }
188
189     public void test10() {
190         try {
191             Regression test = new Regression();
192             test.test10(m3);
193             assertTrue(!test.getErrors());
194         } catch (Exception JavaDoc e) {
195             System.out.println(e);
196             assertTrue(false);
197         }
198     }
199
200     public void test11() {
201         try {
202             Regression test = new Regression();
203             test.test11(m1, m2);
204             assertTrue(!test.getErrors());
205         } catch (Exception JavaDoc e) {
206             System.out.println(e);
207             assertTrue(false);
208         }
209     }
210
211     public void test12() {
212         try {
213             Regression test = new Regression();
214             test.test12(m1);
215             assertTrue(!test.getErrors());
216         } catch (Exception JavaDoc e) {
217             System.out.println(e);
218             assertTrue(false);
219         }
220     }
221
222     public void test13() {
223         try {
224             Regression test = new Regression();
225             test.test13(m1);
226             assertTrue(!test.getErrors());
227         } catch (Exception JavaDoc e) {
228             System.out.println(e);
229             assertTrue(false);
230         }
231     }
232
233     public void test14() {
234         try {
235             Regression test = new Regression();
236             test.test14(m1);
237             assertTrue(!test.getErrors());
238         } catch (Exception JavaDoc e) {
239             System.out.println(e);
240             assertTrue(false);
241         }
242     }
243
244     public void test15() {
245         try {
246             Regression test = new Regression();
247             test.test15(m1);
248             assertTrue(!test.getErrors());
249         } catch (Exception JavaDoc e) {
250             System.out.println(e);
251             assertTrue(false);
252         }
253     }
254
255     public void test16() {
256         try {
257             Regression test = new Regression();
258             test.test16(m1);
259             assertTrue(!test.getErrors());
260         } catch (Exception JavaDoc e) {
261             System.out.println(e);
262             assertTrue(false);
263         }
264     }
265
266     public void test17() {
267         try {
268             Regression test = new Regression();
269             test.test17(m1);
270             assertTrue(!test.getErrors());
271         } catch (Exception JavaDoc e) {
272             System.out.println(e);
273             assertTrue(false);
274         }
275     }
276
277     public void test18() {
278         try {
279             Regression test = new Regression();
280             test.test18(m4);
281             assertTrue(!test.getErrors());
282         } catch (Exception JavaDoc e) {
283             System.out.println(e);
284             assertTrue(false);
285         }
286     }
287
288     public void test19() {
289         try {
290             Regression test = new Regression();
291             test.test19(m2, m3);
292             assertTrue(!test.getErrors());
293         } catch (Exception JavaDoc e) {
294             System.out.println(e);
295             assertTrue(false);
296         }
297     }
298
299     public void test97() {
300         try {
301             Regression test = new Regression();
302             test.test97(m1);
303             assertTrue(!test.getErrors());
304         } catch (Exception JavaDoc e) {
305             System.out.println(e);
306             assertTrue(false);
307         }
308     }
309     private GetModel getGetModel() {
310         return new GetModel() {
311
312             Model cache[] = new Model[4];
313             int i = 4;
314             public Model get() {
315                 if (i == 4) {
316                     try {
317                         tearDown();
318                         setUp();
319                     } catch (Exception JavaDoc e) {
320                         throw new RuntimeException JavaDoc(e.getMessage());
321                     }
322                     cache[0] = m1;
323                     cache[1] = m2;
324                     cache[2] = m3;
325                     cache[3] = m4;
326                     i = 0;
327                 }
328                 return cache[i++];
329             }
330         };
331     }
332     public void testModelEquals() {
333         try {
334             testModelEquals test = new testModelEquals();
335             test.test(getGetModel());
336             assertTrue(!test.getErrors());
337         } catch (Exception JavaDoc e) {
338             System.out.println(e);
339             assertTrue(false);
340         }
341     }
342     public void testMatch() {
343         try {
344             testMatch test = new testMatch(0xfab, getGetModel());
345             test.test();
346             assertTrue(!test.getErrors());
347         } catch (Exception JavaDoc e) {
348             System.out.println(e);
349             assertTrue(false);
350         }
351     }
352     /*
353      * public void testWriterAndReader() { try { testWriterAndReader test = new
354      * testWriterAndReader(); test.test(m1,m2,m3,m4); assertTrue(!
355      * test.getErrors()); } catch (Exception e) { System.out.println(e);
356      * assertTrue(false); } }
357      */

358     public void testNTripleReader() {
359         try {
360             testNTripleReader test = new testNTripleReader();
361             test.test(m1);
362             assertTrue(!test.getErrors());
363         } catch (Exception JavaDoc e) {
364             System.out.println(e);
365             assertTrue(false);
366         }
367     }
368     /*
369      * public void testWriterInterface() { try { testWriterInterface test = new
370      * testWriterInterface(); test.test(m1); assertTrue(! test.getErrors()); }
371      * catch (Exception e) { System.out.println(e); assertTrue(false); } }
372      */

373     public void testReaderInterface() {
374         try {
375             testReaderInterface test = new testReaderInterface();
376             test.test(m1);
377             assertTrue(!test.getErrors());
378         } catch (Exception JavaDoc e) {
379             System.out.println(e);
380             assertTrue(false);
381         }
382     }
383
384     public void soaktest() { // a very crude soak test
385
try {
386             int errCount = 0;
387
388             for (int i = 1; i <= 100; i++) {
389                 Regression test = new Regression();
390                 test0();
391                 test.test1(m1);
392                 test.test2(m1);
393                 test.test3(m1);
394                 test.test4(m1);
395                 test.test5(m1);
396                 test.test6(m1);
397                 test.test7(m1, m2);
398                 test.test8(m1);
399                 test.test9(m2);
400                 test.test10(m3);
401                 test.test11(m1, m2);
402                 test.test12(m1);
403                 test.test13(m1);
404                 test.test14(m1);
405                 test.test15(m1);
406                 test.test16(m1);
407                 test.test17(m1);
408                 test.test18(m4);
409                 test.test19(m2, m3);
410                 test.test97(m1);
411                 if (test.getErrors())
412                     errCount++;
413                 if ((i % 10) == 0) {
414                     System.out.println(
415                         "error count = " + errCount + " rounds = " + i);
416                 }
417             }
418         } catch (Exception JavaDoc e) {
419             System.out.println(e);
420             assertTrue(false);
421         }
422     }
423 }
Popular Tags