Source code: com/hp/hpl/jena/ontology/impl/test/TestListSyntaxCategories.java
1 /*****************************************************************************
2 * Source code information
3 * -----------------------
4 * Original author Ian Dickinson, HP Labs Bristol
5 * Author email Ian.Dickinson@hp.com
6 * Package Jena 2
7 * Web http://sourceforge.net/projects/jena/
8 * Created 02-Apr-2003
9 * Filename $RCSfile: TestListSyntaxCategories.java,v $
10 * Revision $Revision: 1.24 $
11 * Release status $State: Exp $
12 *
13 * Last modified on $Date: 2005/04/06 23:04:51 $
14 * by $Author: ian_dickinson $
15 *
16 * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17 * (see footer for full conditions)
18 *****************************************************************************/
19
20 // Package
21 ///////////////
22 package com.hp.hpl.jena.ontology.impl.test;
23
24
25 // Imports
26 ///////////////
27 import com.hp.hpl.jena.rdf.model.*;
28 import com.hp.hpl.jena.ontology.*;
29 import com.hp.hpl.jena.vocabulary.*;
30
31 import junit.framework.*;
32
33 import java.util.*;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38
39
40 /**
41 * <p>
42 * Unit tests for listXXX methods on ontmodel
43 * </p>
44 *
45 * @author Ian Dickinson, HP Labs
46 * (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
47 * @version CVS $Id: TestListSyntaxCategories.java,v 1.24 2005/04/06 23:04:51 ian_dickinson Exp $
48 */
49 public class TestListSyntaxCategories
50 extends TestCase
51 {
52 // Constants
53 //////////////////////////////////
54 public static final String NS = "http://jena.hpl.hp.com/testing/ontology#";
55
56
57 // Static variables
58 //////////////////////////////////
59
60 protected static DoListTest[] testCases = {
61 // Ontology
62 new DoListTest( "OWL list ontologies", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
63 new String[] {"http://jena.hpl.hp.com/testing/ontology"} )
64 {
65 public Iterator doList( OntModel m ) {
66 return m.listOntologies();
67 }
68 public boolean test( Resource r ) {
69 return r instanceof Ontology;
70 }
71 },
72 new DoListTest( "DAML list ontologies", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
73 new String[] {"http://jena.hpl.hp.com/testing/ontology"} )
74 {
75 public Iterator doList( OntModel m ) {
76 return m.listOntologies();
77 }
78 public boolean test( Resource r ) {
79 return r instanceof Ontology;
80 }
81 },
82 // Properties
83 new DoListTest( "OWL list properties", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
84 new String[] {NS+"p"} )
85 {
86 public Iterator doList( OntModel m ) {
87 return m.listOntProperties();
88 }
89 public boolean test( Resource r ) {
90 return r instanceof OntProperty &&
91 r instanceof Property;
92 }
93 },
94 new DoListTest( "OWL list object properties", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 2,
95 new String[] {NS+"op", NS+"op1"} )
96 {
97 public Iterator doList( OntModel m ) {
98 return m.listObjectProperties();
99 }
100 public boolean test( Resource r ) {
101 return r instanceof OntProperty &&
102 r instanceof Property;
103 }
104 },
105 new DoListTest( "OWL list datatype properties", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
106 new String[] {NS+"dp"} )
107 {
108 public Iterator doList( OntModel m ) {
109 return m.listDatatypeProperties();
110 }
111 public boolean test( Resource r ) {
112 return r instanceof OntProperty &&
113 r instanceof Property;
114 }
115 },
116 new DoListTest( "OWL list functional properties", "file:testing/ontology/owl/list-syntax/test-proptypes.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
117 new String[] {NS+"fp"} )
118 {
119 public Iterator doList( OntModel m ) {
120 return m.listFunctionalProperties();
121 }
122 public boolean test( Resource r ) {
123 return r instanceof OntProperty &&
124 r instanceof FunctionalProperty &&
125 r instanceof Property;
126 }
127 },
128 new DoListTest( "OWL list transitive properties", "file:testing/ontology/owl/list-syntax/test-proptypes.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
129 new String[] {NS+"tp"} )
130 {
131 public Iterator doList( OntModel m ) {
132 return m.listTransitiveProperties();
133 }
134 public boolean test( Resource r ) {
135 return r instanceof OntProperty &&
136 r instanceof TransitiveProperty &&
137 r instanceof Property;
138 }
139 },
140 new DoListTest( "OWL list symmetric properties", "file:testing/ontology/owl/list-syntax/test-proptypes.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
141 new String[] {NS+"sp"} )
142 {
143 public Iterator doList( OntModel m ) {
144 return m.listSymmetricProperties();
145 }
146 public boolean test( Resource r ) {
147 return r instanceof OntProperty &&
148 r instanceof SymmetricProperty &&
149 r instanceof Property;
150 }
151 },
152 new DoListTest( "OWL list inverse functional properties", "file:testing/ontology/owl/list-syntax/test-proptypes.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
153 new String[] {NS+"ifp"} )
154 {
155 public Iterator doList( OntModel m ) {
156 return m.listInverseFunctionalProperties();
157 }
158 public boolean test( Resource r ) {
159 return r instanceof OntProperty &&
160 r instanceof InverseFunctionalProperty &&
161 r instanceof Property;
162 }
163 },
164 new DoListTest( "DAML list properties", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 5,
165 new String[] {NS+"p", NS+"rdf-p", NS+"dp", NS+"op", NS+"op1"} )
166 {
167 public Iterator doList( OntModel m ) {
168 return m.listOntProperties();
169 }
170 public boolean test( Resource r ) {
171 return r instanceof OntProperty &&
172 r instanceof Property;
173 }
174 },
175 new DoListTest( "DAML list object properties", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 2,
176 new String[] {NS+"op", NS+"op1"} )
177 {
178 public Iterator doList( OntModel m ) {
179 return m.listObjectProperties();
180 }
181 public boolean test( Resource r ) {
182 return r instanceof OntProperty &&
183 r instanceof Property;
184 }
185 },
186 new DoListTest( "DAML list datatype properties", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
187 new String[] {NS+"dp"} )
188 {
189 public Iterator doList( OntModel m ) {
190 return m.listDatatypeProperties();
191 }
192 public boolean test( Resource r ) {
193 return r instanceof OntProperty &&
194 r instanceof Property;
195 }
196 },
197 new DoListTest( "DAML list functional properties", "file:testing/ontology/daml/list-syntax/test-proptypes.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
198 new String[] {NS+"fp"} )
199 {
200 public Iterator doList( OntModel m ) {
201 return m.listFunctionalProperties();
202 }
203 public boolean test( Resource r ) {
204 return r instanceof OntProperty &&
205 r instanceof FunctionalProperty &&
206 r instanceof Property;
207 }
208 },
209 new DoListTest( "DAML list transitive properties", "file:testing/ontology/daml/list-syntax/test-proptypes.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
210 new String[] {NS+"tp"} )
211 {
212 public Iterator doList( OntModel m ) {
213 return m.listTransitiveProperties();
214 }
215 public boolean test( Resource r ) {
216 return r instanceof OntProperty &&
217 r instanceof TransitiveProperty &&
218 r instanceof Property;
219 }
220 },
221 new DoListTest( "DAML list inverse functional properties", "file:testing/ontology/daml/list-syntax/test-proptypes.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
222 new String[] {NS+"ifp"} )
223 {
224 public Iterator doList( OntModel m ) {
225 return m.listInverseFunctionalProperties();
226 }
227 public boolean test( Resource r ) {
228 return r instanceof OntProperty &&
229 r instanceof InverseFunctionalProperty &&
230 r instanceof Property;
231 }
232 },
233
234 // individuals
235 new DoListTest( "OWL list individuals", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 8,
236 new String[] {NS+"A0", NS+"A1", NS+"C0", NS+"a0", NS+"a1", NS+"a2", NS+"z0", NS+"z1"} )
237 {
238 public Iterator doList( OntModel m ) {
239 return m.listIndividuals();
240 }
241 public boolean test( Resource r ) {
242 return r instanceof Individual;
243 }
244 },
245 new DoListTest( "empty OWL list individuals", null, OntModelSpec.OWL_MEM, 0, new String[] {} )
246 {
247 public Iterator doList( OntModel m ) {
248 return m.listIndividuals();
249 }
250 public boolean test( Resource r ) {
251 return r instanceof Individual;
252 }
253 },
254 new DoListTest( "empty OWL+rule list individuals", null, OntModelSpec.OWL_MEM_RULE_INF, 0, new String[] {} )
255 {
256 public Iterator doList( OntModel m ) {
257 return m.listIndividuals();
258 }
259 public boolean test( Resource r ) {
260 return r instanceof Individual;
261 }
262 },
263 new DoListTest( "DAML list individuals", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 6,
264 new String[] {NS+"A0", NS+"A1", NS+"C0", NS+"a1", NS+"a2", NS+"a0"} )
265 {
266 public Iterator doList( OntModel m ) {
267 return m.listIndividuals();
268 }
269 public boolean test( Resource r ) {
270 return r instanceof Individual;
271 }
272 },
273 new DoListTest( "empty DAML+rule list individuals", null, OntModelSpec.DAML_MEM_RULE_INF, 0, new String[] {} )
274 {
275 public Iterator doList( OntModel m ) {
276 return m.listIndividuals();
277 }
278 public boolean test( Resource r ) {
279 return r instanceof Individual;
280 }
281 },
282
283 new DoListTest( "OWL list all different", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
284 null )
285 {
286 public Iterator doList( OntModel m ) {
287 return m.listAllDifferent();
288 }
289 public boolean test( Resource r ) {
290 return r instanceof AllDifferent;
291 }
292 },
293 new DoListTest( "DAML list all different", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 0, null,
294 true /* exception expected */ )
295 {
296 public Iterator doList( OntModel m ) {
297 return m.listAllDifferent();
298 }
299 public boolean test( Resource r ) {
300 return r instanceof AllDifferent;
301 }
302 },
303
304 // classes
305 new DoListTest( "OWL list classes", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 11,
306 new String[] {NS+"A", NS+"B", NS+"C", NS+"D", NS+"E", NS+"X0", NS+"X1", NS+"Y0", NS+"Y1", NS+"Z", } )
307 {
308 public Iterator doList( OntModel m ) {
309 return m.listClasses();
310 }
311 public boolean test( Resource r ) {
312 return r instanceof OntClass;
313 }
314 },
315 new DoListTest( "OWL list named classes", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 10,
316 new String[] {NS+"A", NS+"B", NS+"C", NS+"D", NS+"E", NS+"X0", NS+"X1", NS+"Y0", NS+"Y1", NS+"Z", } )
317 {
318 public Iterator doList( OntModel m ) {
319 return m.listNamedClasses();
320 }
321 public boolean test( Resource r ) {
322 return r instanceof OntClass;
323 }
324 },
325 new DoListTest( "OWL list intersection classes", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
326 new String[] {NS+"A" } )
327 {
328 public Iterator doList( OntModel m ) {
329 return m.listIntersectionClasses();
330 }
331 public boolean test( Resource r ) {
332 return r instanceof OntClass;
333 }
334 },
335 new DoListTest( "OWL list union classes", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
336 new String[] {NS+"B"} )
337 {
338 public Iterator doList( OntModel m ) {
339 return m.listUnionClasses();
340 }
341 public boolean test( Resource r ) {
342 return r instanceof OntClass;
343 }
344 },
345 new DoListTest( "OWL list complement classes", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
346 new String[] {NS+"C"} )
347 {
348 public Iterator doList( OntModel m ) {
349 return m.listComplementClasses();
350 }
351 public boolean test( Resource r ) {
352 return r instanceof OntClass;
353 }
354 },
355 new DoListTest( "OWL list enumerated classes", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
356 new String[] {NS+"D"} )
357 {
358 public Iterator doList( OntModel m ) {
359 return m.listEnumeratedClasses();
360 }
361 public boolean test( Resource r ) {
362 return r instanceof OntClass;
363 }
364 },
365 new DoListTest( "OWL list restrictions", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
366 null )
367 {
368 public Iterator doList( OntModel m ) {
369 return m.listRestrictions();
370 }
371 public boolean test( Resource r ) {
372 return r instanceof Restriction;
373 }
374 },
375 new DoListTest( "DAML list classes", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 12,
376 new String[] {NS+"A", NS+"B", NS+"C", NS+"D", NS+"E", NS+"X0", NS+"X1", NS+"Y0", NS+"Y1", NS+"Z", DAML_OIL.Thing.getURI()} )
377 {
378 public Iterator doList( OntModel m ) {
379 return m.listClasses();
380 }
381 public boolean test( Resource r ) {
382 return r instanceof OntClass;
383 }
384 },
385 new DoListTest( "DAML list named classes", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 11,
386 new String[] {NS+"A", NS+"B", NS+"C", NS+"D", NS+"E", NS+"X0", NS+"X1", NS+"Y0", NS+"Y1", NS+"Z", DAML_OIL.Thing.getURI()} )
387 {
388 public Iterator doList( OntModel m ) {
389 return m.listNamedClasses();
390 }
391 public boolean test( Resource r ) {
392 return r instanceof OntClass;
393 }
394 },
395 new DoListTest( "DAML list intersection classes", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
396 new String[] {NS+"A" } )
397 {
398 public Iterator doList( OntModel m ) {
399 return m.listIntersectionClasses();
400 }
401 public boolean test( Resource r ) {
402 return r instanceof OntClass;
403 }
404 },
405 new DoListTest( "DAML list union classes", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
406 new String[] {NS+"B"} )
407 {
408 public Iterator doList( OntModel m ) {
409 return m.listUnionClasses();
410 }
411 public boolean test( Resource r ) {
412 return r instanceof OntClass;
413 }
414 },
415 new DoListTest( "DAML list complement classes", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
416 new String[] {NS+"C"} )
417 {
418 public Iterator doList( OntModel m ) {
419 return m.listComplementClasses();
420 }
421 public boolean test( Resource r ) {
422 return r instanceof OntClass;
423 }
424 },
425 new DoListTest( "DAML list enumerated classes", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
426 new String[] {NS+"D"} )
427 {
428 public Iterator doList( OntModel m ) {
429 return m.listEnumeratedClasses();
430 }
431 public boolean test( Resource r ) {
432 return r instanceof OntClass;
433 }
434 },
435 new DoListTest( "DAML list restrictions", "file:testing/ontology/daml/list-syntax/test.rdf", OntModelSpec.DAML_MEM_RULE_INF, 1,
436 null )
437 {
438 public Iterator doList( OntModel m ) {
439 return m.listRestrictions();
440 }
441 public boolean test( Resource r ) {
442 return r instanceof Restriction;
443 }
444 },
445
446 // Annotation property
447 new DoListTest( "OWL list annotation properties", "file:testing/ontology/owl/list-syntax/test.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 6,
448 null )
449 {
450 public Iterator doList( OntModel m ) {
451 return m.listAnnotationProperties();
452 }
453 public boolean test( Resource r ) {
454 return r instanceof AnnotationProperty;
455 }
456 },
457
458 // !!!!!!! Following tests use ontology that imports owl.owl !!!!!!!!!!!
459
460 // ontologies
461 new DoListTest( "OWL+import list ontologies", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 2,
462 new String[] {"http://jena.hpl.hp.com/testing/ontology", "http://www.w3.org/2002/07/owl"} )
463 {
464 public Iterator doList( OntModel m ) {
465 return m.listOntologies();
466 }
467 public boolean test( Resource r ) {
468 return r instanceof Ontology;
469 }
470 },
471 // Properties
472 new DoListTest( "OWL+import list properties", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 40,
473 null )
474 {
475 public Iterator doList( OntModel m ) {
476 return m.listOntProperties();
477 }
478 public boolean test( Resource r ) {
479 return r instanceof OntProperty &&
480 r instanceof Property;
481 }
482 },
483 new DoListTest( "OWL+import list object properties", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 2,
484 new String[] {NS+"op", NS+"op1"} )
485 {
486 public Iterator doList( OntModel m ) {
487 return m.listObjectProperties();
488 }
489 public boolean test( Resource r ) {
490 return r instanceof OntProperty &&
491 r instanceof Property;
492 }
493 },
494 new DoListTest( "OWL+import list datatype properties", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
495 new String[] {NS+"dp"} )
496 {
497 public Iterator doList( OntModel m ) {
498 return m.listDatatypeProperties();
499 }
500 public boolean test( Resource r ) {
501 return r instanceof OntProperty &&
502 r instanceof Property;
503 }
504 },
505
506 // individuals
507 new DoListTest( "OWL+import list individuals", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 8,
508 null )
509 {
510 public Iterator doList( OntModel m ) {
511 return m.listIndividuals();
512 }
513 public boolean test( Resource r ) {
514 return r instanceof Individual;
515 }
516 },
517
518 new DoListTest( "OWL+import list all different", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
519 null )
520 {
521 public Iterator doList( OntModel m ) {
522 return m.listAllDifferent();
523 }
524 public boolean test( Resource r ) {
525 return r instanceof AllDifferent;
526 }
527 },
528
529 // classes
530 new DoListTest( "OWL+import list classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 14,
531 null )
532 {
533 public Iterator doList( OntModel m ) {
534 return m.listClasses();
535 }
536 public boolean test( Resource r ) {
537 return r instanceof OntClass;
538 }
539 },
540 new DoListTest( "OWL+import list named classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 12,
541 new String[] {NS+"A", NS+"B", NS+"C", NS+"D", NS+"E", NS+"X0", NS+"X1", NS+"Y0", NS+"Y1", NS+"Z",
542 OWL.Thing.getURI(), OWL.Nothing.getURI()} )
543 {
544 public Iterator doList( OntModel m ) {
545 return m.listNamedClasses();
546 }
547 public boolean test( Resource r ) {
548 return r instanceof OntClass;
549 }
550 },
551 new DoListTest( "OWL+import list intersection classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
552 new String[] {NS+"A" } )
553 {
554 public Iterator doList( OntModel m ) {
555 return m.listIntersectionClasses();
556 }
557 public boolean test( Resource r ) {
558 return r instanceof OntClass;
559 }
560 },
561 new DoListTest( "OWL+import list union classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 2,
562 new String[] {NS+"B", OWL.Thing.getURI()} )
563 {
564 public Iterator doList( OntModel m ) {
565 return m.listUnionClasses();
566 }
567 public boolean test( Resource r ) {
568 return r instanceof OntClass;
569 }
570 },
571 new DoListTest( "OWL+import list complement classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 3,
572 null )
573 {
574 public Iterator doList( OntModel m ) {
575 return m.listComplementClasses();
576 }
577 public boolean test( Resource r ) {
578 return r instanceof OntClass;
579 }
580 },
581 new DoListTest( "OWL+import list enumerated classes", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
582 new String[] {NS+"D"} )
583 {
584 public Iterator doList( OntModel m ) {
585 return m.listEnumeratedClasses();
586 }
587 public boolean test( Resource r ) {
588 return r instanceof OntClass;
589 }
590 },
591 new DoListTest( "OWL+import list restrictions", "file:testing/ontology/owl/list-syntax/test-with-import.rdf", OntModelSpec.OWL_MEM_TRANS_INF, 1,
592 null )
593 {
594 public Iterator doList( OntModel m ) {
595 return m.listRestrictions();
596 }
597 public boolean test( Resource r ) {
598 return r instanceof Restriction;
599 }
600 },
601 };
602
603
604 // Instance variables
605 //////////////////////////////////
606
607 // Constructors
608 //////////////////////////////////
609
610 public TestListSyntaxCategories( String name ) {
611 super( name );
612 }
613
614
615
616 // External signature methods
617 //////////////////////////////////
618
619 public static TestSuite suite() {
620 TestSuite s = new TestSuite( "TestListSyntaxCategories" );
621
622 for (int i = 0; i < testCases.length; i++) {
623 s.addTest( testCases[i] );
624 }
625
626 return s;
627 }
628
629
630 // Internal implementation methods
631 //////////////////////////////////
632
633 //==============================================================================
634 // Inner class definitions
635 //==============================================================================
636
637 protected static class DoListTest
638 extends TestCase
639 {
640 protected String m_fileName;
641 protected OntModelSpec m_spec;
642 protected int m_count;
643 protected String[] m_expected;
644 protected boolean m_exExpected; // exception expected during list operation
645
646 protected DoListTest( String name, String fileName, OntModelSpec spec, int count, String[] expected ) {
647 this( name, fileName, spec, count, expected, false );
648 }
649
650 protected DoListTest( String name, String fileName, OntModelSpec spec, int count, String[] expected, boolean exExpected ) {
651 super( name );
652 m_fileName = fileName;
653 m_spec = spec;
654 m_count = count;
655 m_expected = expected;
656 m_exExpected = exExpected;
657 }
658
659 public void setUp() {
660 // ensure the ont doc manager is in a consistent state
661 OntDocumentManager.getInstance().reset( true );
662 }
663
664
665 public void runTest() {
666 OntModel m = ModelFactory.createOntologyModel( m_spec, null );
667 m.getDocumentManager().setMetadataSearchPath( "file:etc/ont-policy-test.rdf", true );
668
669 if (m_fileName != null) {
670 m.read( m_fileName );
671 }
672
673 boolean exOccurred = false;
674 Iterator i = null;
675 try {
676 i = doList( m );
677 }
678 catch (OntologyException e) {
679 exOccurred = true;
680 }
681
682 assertEquals( "Ontology exception" + (m_exExpected ? " was " : " was not ") + "expected", m_exExpected, exOccurred );
683
684 if (!exOccurred) {
685 List expected = expected( m );
686 List actual = new ArrayList();
687 int extraneous = 0;
688
689 // now we walk the iterator
690 while (i.hasNext()) {
691 Resource res = (Resource) i.next();
692 assertTrue( "Should not fail node test on " + res, test( res ));
693
694 actual.add( res );
695 if (expected != null) {
696 if (expected.contains( res )) {
697 expected.remove( res );
698 }
699 else {
700 if (!res.isAnon()) {
701 // since we can't list expected anon resources, we ignore them in this check
702 extraneous++;
703 }
704 }
705 }
706 }
707
708 // debugging
709 if (m_count != actual.size()) {
710 Log logger = LogFactory.getLog( getClass() );
711 logger.debug( getName() + " - expected " + m_count + " results, actual = " + actual.size() );
712 for (Iterator j = actual.iterator(); j.hasNext(); ) {
713 logger.debug( getName() + " - saw actual: " + j.next() );
714 }
715 }
716 if (expected != null && !expected.isEmpty()) {
717 Log logger = LogFactory.getLog( getClass() );
718 for (Iterator j = expected.iterator(); j.hasNext(); ) {
719 logger.debug( getName() + " - expected but did not find: " + j.next() );
720 }
721 }
722
723 assertEquals( getName() + ": wrong number of results returned", m_count, actual.size() );
724 if (expected != null) {
725 assertTrue( "Did not find all expected resources in iterator", expected.isEmpty() );
726 assertEquals( "Found extraneous results, not in expected list", 0, extraneous );
727 }
728 }
729 }
730
731 /* get the iterator */
732 public Iterator doList( OntModel m ) {
733 // should be overriden in sub-classes
734 return null;
735 }
736
737 /* test the Java type of the result, and other tests */
738 public boolean test( Resource r ) {
739 return true;
740 }
741
742 protected List expected( OntModel m ) {
743 if (m_expected != null) {
744 List expected = new ArrayList();
745
746 for (int i = 0; i < m_expected.length; i++) {
747 expected.add( m.getResource( m_expected[i] ) );
748 }
749
750 return expected;
751 }
752 else {
753 return null;
754 }
755 }
756 }
757 }
758
759
760 /*
761 (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
762 All rights reserved.
763
764 Redistribution and use in source and binary forms, with or without
765 modification, are permitted provided that the following conditions
766 are met:
767
768 1. Redistributions of source code must retain the above copyright
769 notice, this list of conditions and the following disclaimer.
770
771 2. Redistributions in binary form must reproduce the above copyright
772 notice, this list of conditions and the following disclaimer in the
773 documentation and/or other materials provided with the distribution.
774
775 3. The name of the author may not be used to endorse or promote products
776 derived from this software without specific prior written permission.
777
778 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
779 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
780 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
781 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
782 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
783 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
784 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
785 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
786 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
787 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
788 */