1 19 20 package com.hp.hpl.jena.ontology.impl.test; 23 24 25 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 49 public class TestListSyntaxCategories 50 extends TestCase 51 { 52 public static final String NS = "http://jena.hpl.hp.com/testing/ontology#"; 55 56 57 60 protected static DoListTest[] testCases = { 61 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 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 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 ) 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 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 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 460 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 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 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 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 607 610 public TestListSyntaxCategories( String name ) { 611 super( name ); 612 } 613 614 615 616 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 633 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; 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 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 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 extraneous++; 703 } 704 } 705 } 706 } 707 708 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 732 public Iterator doList( OntModel m ) { 733 return null; 735 } 736 737 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 789 | Popular Tags |