1 6 7 package com.hp.hpl.jena.graph.test; 8 9 import com.hp.hpl.jena.util.CollectionFactory; 10 import com.hp.hpl.jena.util.iterator.*; 11 import com.hp.hpl.jena.graph.*; 12 import com.hp.hpl.jena.graph.query.*; 13 import com.hp.hpl.jena.mem.GraphMem; 14 import com.hp.hpl.jena.shared.*; 15 16 import java.util.*; 17 18 25 public class AbstractTestGraph extends GraphTestBase 26 { 27 public AbstractTestGraph( String name ) 28 { super( name ); } 29 30 34 36 public Graph getGraph() { return new GraphMem(); } 37 38 public Graph getGraphWith( String facts ) 39 { 40 Graph g = getGraph(); 41 graphAdd( g, facts ); 42 return g; 43 } 44 45 49 public void testFindAndContains() 50 { 51 Graph g = getGraph(); 52 Node r = Node.create( "r" ), s = Node.create( "s" ), p = Node.create( "P" ); 53 g.add( Triple.create( r, p, s ) ); 54 assertTrue( g.contains( r, p, Node.ANY ) ); 55 assertTrue( g.find( r, p, Node.ANY ).hasNext() ); 56 } 57 58 public void testFindByFluidTriple() 59 { 60 Graph g = getGraphWith( "x y z " ); 61 assertTrue( g.find( triple( "?? y z" ) ).hasNext() ); 62 assertTrue( g.find( triple( "x ?? z" ) ).hasNext() ); 63 assertTrue( g.find( triple( "x y ??" ) ).hasNext() ); 64 } 65 66 public void testContainsConcrete() 67 { 68 Graph g = getGraphWith( "s P o; _x _R _y; x S 0" ); 69 assertTrue( g.contains( triple( "s P o" ) ) ); 70 assertTrue( g.contains( triple( "_x _R _y" ) ) ); 71 assertTrue( g.contains( triple( "x S 0" ) ) ); 72 73 assertFalse( g.contains( triple( "s P Oh" ) ) ); 74 assertFalse( g.contains( triple( "S P O" ) ) ); 75 assertFalse( g.contains( triple( "s p o" ) ) ); 76 assertFalse( g.contains( triple( "_x _r _y" ) ) ); 77 assertFalse( g.contains( triple( "x S 1" ) ) ); 78 } 79 80 public void testContainsFluid() 81 { 82 Graph g = getGraphWith( "x R y; a P b" ); 83 assertTrue( g.contains( triple( "?? R y" ) ) ); 84 assertTrue( g.contains( triple( "x ?? y" ) ) ); 85 assertTrue( g.contains( triple( "x R ??" ) ) ); 86 assertTrue( g.contains( triple( "?? P b" ) ) ); 87 assertTrue( g.contains( triple( "a ?? b" ) ) ); 88 assertTrue( g.contains( triple( "a P ??" ) ) ); 89 assertTrue( g.contains( triple( "?? R y" ) ) ); 90 91 assertFalse( g.contains( triple( "?? R b" ) ) ); 92 assertFalse( g.contains( triple( "a ?? y" ) ) ); 93 assertFalse( g.contains( triple( "x P ??" ) ) ); 94 assertFalse( g.contains( triple( "?? R x" ) ) ); 95 assertFalse( g.contains( triple( "x ?? R" ) ) ); 96 assertFalse( g.contains( triple( "a S ??" ) ) ); 97 } 98 99 102 public void testIsEmpty() 103 { 104 Graph g = getGraph(); 105 if (canBeEmpty( g )) 106 { 107 assertTrue( g.isEmpty() ); 108 g.add( Triple.create( "S P O" ) ); 109 assertFalse( g.isEmpty() ); 110 g.add( Triple.create( "A B C" ) ); 111 assertFalse( g.isEmpty() ); 112 g.add( Triple.create( "S P O" ) ); 113 assertFalse( g.isEmpty() ); 114 g.delete( Triple.create( "S P O" ) ); 115 assertFalse( g.isEmpty() ); 116 g.delete( Triple.create( "A B C" ) ); 117 assertTrue( g.isEmpty() ); 118 } 119 } 120 121 122 public void testAGraph() 123 { 124 String title = this.getClass().getName(); 125 Graph g = getGraph(); 126 int baseSize = g.size(); 127 graphAdd( g, "x R y; p S q; a T b" ); 128 129 assertContainsAll( title + ": simple graph", g, "x R y; p S q; a T b" ); 130 assertEquals( title + ": size", baseSize + 3, g.size() ); 131 graphAdd( g, "spindizzies lift cities; Diracs communicate instantaneously" ); 132 assertEquals( title + ": size after adding", baseSize + 5, g.size() ); 133 g.delete( triple( "x R y" ) ); 134 g.delete( triple( "a T b" ) ); 135 assertEquals( title + ": size after deleting", baseSize + 3, g.size() ); 136 assertContainsAll( title + ": modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously" ); 137 assertOmitsAll( title + ": modified simple graph", g, "x R y; a T b" ); 138 139 ClosableIterator it = g.find( Node.ANY, node("lift"), Node.ANY ); 140 assertTrue( title + ": finds some triple(s)", it.hasNext() ); 141 assertEquals( title + ": finds a 'lift' triple", triple("spindizzies lift cities"), it.next() ); 142 assertFalse( title + ": finds exactly one triple", it.hasNext() ); 143 } 144 145 160 164 public void testHasTransactions() 165 { 166 Graph g = getGraph(); 167 TransactionHandler th = g.getTransactionHandler(); 168 th.transactionsSupported(); 169 try { th.begin(); } catch (UnsupportedOperationException x) {} 170 try { th.abort(); } catch (UnsupportedOperationException x) {} 171 try { th.commit(); } catch (UnsupportedOperationException x) {} 172 173 Command cmd = new Command() 174 { public Object execute() { return null; } }; 175 try { th.executeInTransaction( cmd ); } 176 catch (UnsupportedOperationException x) {} 177 } 178 179 static final Triple [] tripleArray = tripleArray( "S P O; A R B; X Q Y" ); 180 181 static final List tripleList = Arrays.asList( tripleArray( "i lt j; p equals q" ) ); 182 183 static final Triple [] setTriples = tripleArray 184 ( "scissors cut paper; paper wraps stone; stone breaks scissors" ); 185 186 static final Set tripleSet = CollectionFactory.createHashedSet( Arrays.asList( setTriples ) ); 187 188 public void testBulkUpdate() 189 { 190 Graph g = getGraph(); 191 BulkUpdateHandler bu = g.getBulkUpdateHandler(); 192 Graph items = graphWith( "pigs might fly; dead can dance" ); 193 int initialSize = g.size(); 194 195 bu.add( tripleArray ); 196 testContains( g, tripleArray ); 197 testOmits( g, tripleList ); 198 199 bu.add( tripleList ); 200 testContains( g, tripleList ); 201 testContains( g, tripleArray ); 202 203 bu.add( tripleSet.iterator() ); 204 testContains( g, tripleSet.iterator() ); 205 testContains( g, tripleList ); 206 testContains( g, tripleArray ); 207 208 bu.add( items ); 209 testContains( g, items ); 210 testContains( g, tripleSet.iterator() ); 211 testContains( g, tripleArray ); 212 testContains( g, tripleList ); 213 214 bu.delete( tripleArray ); 215 testOmits( g, tripleArray ); 216 testContains( g, tripleList ); 217 testContains( g, tripleSet.iterator() ); 218 testContains( g, items ); 219 220 bu.delete( tripleSet.iterator() ); 221 testOmits( g, tripleSet.iterator() ); 222 testOmits( g, tripleArray ); 223 testContains( g, tripleList ); 224 testContains( g, items ); 225 226 bu.delete( items ); 227 testOmits( g, tripleSet.iterator() ); 228 testOmits( g, tripleArray ); 229 testContains( g, tripleList ); 230 testOmits( g, items ); 231 232 bu.delete( tripleList ); 233 assertEquals( "graph has original size", initialSize, g.size() ); 234 } 235 236 public void testBulkAddWithReification() 237 { 238 testBulkAddWithReification( false ); 239 testBulkAddWithReification( true ); 240 } 241 242 public void testBulkAddWithReificationPreamble() 243 { 244 Graph g = getGraph(); 245 xSPO( g.getReifier() ); 246 assertFalse( getReificationTriples( g.getReifier() ).isEmpty() ); 247 } 248 249 public void testBulkAddWithReification( boolean withReifications ) 250 { 251 Graph graphToUpdate = getGraph(); 252 BulkUpdateHandler bu = graphToUpdate.getBulkUpdateHandler(); 253 Graph graphToAdd = graphWith( "pigs might fly; dead can dance" ); 254 Reifier updatedReifier = graphToUpdate.getReifier(); 255 Reifier addedReifier = graphToAdd.getReifier(); 256 xSPOyXYZ( addedReifier ); 257 bu.add( graphToAdd, withReifications ); 258 assertIsomorphic 259 ( 260 withReifications ? getReificationTriples( addedReifier ) : graphWith( "" ), 261 getReificationTriples( updatedReifier ) 262 ); 263 } 264 265 protected void xSPOyXYZ( Reifier r ) 266 { 267 xSPO( r ); 268 r.reifyAs( Node.create( "y" ), Triple.create( "X Y Z" ) ); 269 } 270 271 protected void aABC( Reifier r ) 272 { r.reifyAs( Node.create( "a" ), Triple.create( "A B C" ) ); } 273 274 protected void xSPO( Reifier r ) 275 { r.reifyAs( Node.create( "x" ), Triple.create( "S P O" ) ); } 276 277 public void testRemove() 278 { 279 testRemove( "S ?? ??", "S ?? ??" ); 280 testRemove( "S ?? ??", "?? P ??" ); 281 testRemove( "S ?? ??", "?? ?? O" ); 282 testRemove( "?? P ??", "S ?? ??" ); 283 testRemove( "?? P ??", "?? P ??" ); 284 testRemove( "?? P ??", "?? ?? O" ); 285 testRemove( "?? ?? O", "S ?? ??" ); 286 testRemove( "?? ?? O", "?? P ??" ); 287 testRemove( "?? ?? O", "?? ?? O" ); 288 } 289 290 public void testRemove( String findRemove, String findCheck ) 291 { 292 Graph g = getGraphWith( "S P O" ); 293 ExtendedIterator it = g.find( Triple.create( findRemove ) ); 294 try 295 { 296 it.next(); it.remove(); it.close(); 297 assertFalse( g.contains( Triple.create( findCheck ) ) ); 298 } 299 catch (UnsupportedOperationException e) 300 { assertFalse( g.getCapabilities().iteratorRemoveAllowed() ); } 301 } 302 303 public void testBulkRemoveWithReification() 304 { 305 testBulkUpdateRemoveWithReification( true ); 306 testBulkUpdateRemoveWithReification( false ); 307 } 308 309 public void testBulkUpdateRemoveWithReification( boolean withReifications ) 310 { 311 Graph g = getGraph(); 312 BulkUpdateHandler bu = g.getBulkUpdateHandler(); 313 Graph items = graphWith( "pigs might fly; dead can dance" ); 314 Reifier gr = g.getReifier(), ir = items.getReifier(); 315 xSPOyXYZ( ir ); 316 xSPO( gr ); aABC( gr ); 317 bu.delete( items, withReifications ); 318 Graph answer = graphWith( "" ); 319 Reifier ar = answer.getReifier(); 320 if (withReifications) 321 aABC( ar ); 322 else 323 { 324 xSPO( ar ); 325 aABC( ar ); 326 } 327 assertIsomorphic( getReificationTriples( ar ), getReificationTriples( gr ) ); 328 } 329 330 public void testHasCapabilities() 331 { 332 Graph g = getGraph(); 333 Capabilities c = g.getCapabilities(); 334 boolean sa = c.sizeAccurate(); 335 boolean aaSome = c.addAllowed(); 336 boolean aaAll = c.addAllowed( true ); 337 boolean daSome = c.deleteAllowed(); 338 boolean daAll = c.deleteAllowed( true ); 339 boolean cbe = c.canBeEmpty(); 340 } 341 342 public void testFind() 343 { 344 Graph g = getGraph(); 345 graphAdd( g, "S P O" ); 346 assertTrue( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() ); 347 assertTrue( g.find( Triple.ANY ).hasNext() ); 348 } 349 350 public void testFind2() 351 { 352 Graph g = getGraphWith( "S P O" ); 353 TripleIterator waitingForABigRefactoringHere = null; 354 ExtendedIterator it = g.find( Triple.ANY ); 355 } 356 357 protected boolean canBeEmpty( Graph g ) 358 { return g.isEmpty(); } 359 360 public void testEventRegister() 361 { 362 Graph g = getGraph(); 363 GraphEventManager gem = g.getEventManager(); 364 assertSame( gem, gem.register( new RecordingListener() ) ); 365 } 366 367 370 public void testEventUnregister() 371 { 372 getGraph().getEventManager().unregister( L ); 373 } 374 375 378 protected Triple SPO = Triple.create( "S P O" ); 379 protected RecordingListener L = new RecordingListener(); 380 381 384 protected Graph getAndRegister( GraphListener gl ) 385 { 386 Graph g = getGraph(); 387 g.getEventManager().register( gl ); 388 return g; 389 } 390 391 public void testAddTriple() 392 { 393 Graph g = getAndRegister( L ); 394 g.add( SPO ); 395 L.assertHas( new Object [] {"add", g, SPO} ); 396 } 397 398 public void testDeleteTriple() 399 { 400 Graph g = getAndRegister( L ); 401 g.delete( SPO ); 402 L.assertHas( new Object [] { "delete", g, SPO} ); 403 } 404 405 409 public void testEventDeleteByFind() 410 { 411 Graph g = getAndRegister( L ); 412 if (g.getCapabilities().iteratorRemoveAllowed()) 413 { 414 Triple toRemove = triple( "remove this triple" ); 415 g.add( toRemove ); 416 ExtendedIterator rtr = g.find( toRemove ); 417 assertTrue( "ensure a(t least) one triple", rtr.hasNext() ); 418 rtr.next(); 419 rtr.remove(); 420 L.assertHas( new Object [] { "add", g, toRemove, "delete", g, toRemove} ); 421 } 422 } 423 424 public void testTwoListeners() 425 { 426 RecordingListener L1 = new RecordingListener(); 427 RecordingListener L2 = new RecordingListener(); 428 Graph g = getGraph(); 429 GraphEventManager gem = g.getEventManager(); 430 gem.register( L1 ).register( L2 ); 431 g.add( SPO ); 432 L2.assertHas( new Object [] {"add", g, SPO} ); 433 L1.assertHas( new Object [] {"add", g, SPO} ); 434 } 435 436 public void testUnregisterWorks() 437 { 438 Graph g = getGraph(); 439 GraphEventManager gem = g.getEventManager(); 440 gem.register( L ).unregister( L ); 441 g.add( SPO ); 442 L.assertHas( new Object [] {} ); 443 } 444 445 public void testRegisterTwice() 446 { 447 Graph g = getAndRegister( L ); 448 g.getEventManager().register( L ); 449 g.add( SPO ); 450 L.assertHas( new Object [] {"add", g, SPO, "add", g, SPO} ); 451 } 452 453 public void testUnregisterOnce() 454 { 455 Graph g = getAndRegister( L ); 456 g.getEventManager().register( L ).unregister( L ); 457 g.delete( SPO ); 458 L.assertHas( new Object [] {"delete", g, SPO} ); 459 } 460 461 public void testBulkAddArrayEvent() 462 { 463 Graph g = getAndRegister( L ); 464 Triple [] triples = tripleArray( "x R y; a P b" ); 465 g.getBulkUpdateHandler().add( triples ); 466 L.assertHas( new Object [] {"add[]", g, triples} ); 467 } 468 469 public void testBulkAddList() 470 { 471 Graph g = getAndRegister( L ); 472 List elems = Arrays.asList( tripleArray( "bells ring loudly; pigs might fly" ) ); 473 g.getBulkUpdateHandler().add( elems ); 474 L.assertHas( new Object [] {"addList", g, elems} ); 475 } 476 477 public void testBulkDeleteArray() 478 { 479 Graph g = getAndRegister( L ); 480 Triple [] triples = tripleArray( "x R y; a P b" ); 481 g.getBulkUpdateHandler().delete( triples ); 482 L.assertHas( new Object [] {"delete[]", g, triples} ); 483 } 484 485 public void testBulkDeleteList() 486 { 487 Graph g = getAndRegister( L ); 488 List elems = Arrays.asList( tripleArray( "bells ring loudly; pigs might fly" ) ); 489 g.getBulkUpdateHandler().delete( elems ); 490 L.assertHas( new Object [] {"deleteList", g, elems} ); 491 } 492 493 public void testBulkAddIterator() 494 { 495 Graph g = getAndRegister( L ); 496 Triple [] triples = tripleArray( "I wrote this; you read that; I wrote this" ); 497 g.getBulkUpdateHandler().add( asIterator( triples ) ); 498 L.assertHas( new Object [] {"addIterator", g, Arrays.asList( triples )} ); 499 } 500 501 public void testBulkDeleteIterator() 502 { 503 Graph g = getAndRegister( L ); 504 Triple [] triples = tripleArray( "I wrote this; you read that; I wrote this" ); 505 g.getBulkUpdateHandler().delete( asIterator( triples ) ); 506 L.assertHas( new Object [] {"deleteIterator", g, Arrays.asList( triples )} ); 507 } 508 509 public Iterator asIterator( Triple [] triples ) 510 { return Arrays.asList( triples ).iterator(); } 511 512 public void testBulkAddGraph() 513 { 514 Graph g = getAndRegister( L ); 515 Graph triples = graphWith( "this type graph; I type slowly" ); 516 g.getBulkUpdateHandler().add( triples ); 517 L.assertHas( new Object [] {"addGraph", g, triples} ); 518 } 519 520 public void testBulkDeleteGraph() 521 { 522 Graph g = getAndRegister( L ); 523 Graph triples = graphWith( "this type graph; I type slowly" ); 524 g.getBulkUpdateHandler().delete( triples ); 525 L.assertHas( new Object [] {"deleteGraph", g, triples} ); 526 } 527 528 public void testGeneralEvent() 529 { 530 Graph g = getAndRegister( L ); 531 Object value = new int[]{}; 532 g.getEventManager().notifyEvent( g, value ); 533 L.assertHas( new Object [] { "someEvent", g, value } ); 534 } 535 536 public void testRemoveAllEvent() 537 { 538 Graph g = getAndRegister( L ); 539 g.getBulkUpdateHandler().removeAll(); 540 L.assertHas( new Object [] { "someEvent", g, GraphEvents.removeAll } ); 541 } 542 543 public void testRemoveSomeEvent() 544 { 545 Graph g = getAndRegister( L ); 546 Node S = node( "S" ), P = node( "?P" ), O = node( "??" ); 547 g.getBulkUpdateHandler().remove( S, P, O ); 548 Object event = GraphEvents.remove( S, P, O ); 549 L.assertHas( new Object [] { "someEvent", g, event } ); 550 } 551 552 558 public void testContainsNode() 559 { 560 Graph g = getGraph(); 561 graphAdd( g, "a P b; _c _Q _d; a 11 12" ); 562 QueryHandler qh = g.queryHandler(); 563 assertTrue( qh.containsNode( node( "a" ) ) ); 564 assertTrue( qh.containsNode( node( "P" ) ) ); 565 assertTrue( qh.containsNode( node( "b" ) ) ); 566 assertTrue( qh.containsNode( node( "_c" ) ) ); 567 assertTrue( qh.containsNode( node( "_Q" ) ) ); 568 assertTrue( qh.containsNode( node( "_d" ) ) ); 569 assertTrue( qh.containsNode( node( "11" ) ) ); 571 assertTrue( qh.containsNode( node( "12" ) ) ); 572 573 assertFalse( qh.containsNode( node( "x" ) ) ); 574 assertFalse( qh.containsNode( node( "_y" ) ) ); 575 assertFalse( qh.containsNode( node( "99" ) ) ); 576 } 577 578 public void testSubjectsFor() 579 { 580 Graph g = getGraphWith( "a P b; a Q c; a P d; b P x; c Q y" ); 581 testSameSubjects( g, Node.ANY, Node.ANY ); 582 testSameSubjects( g, node( "P" ), Node.ANY ); 583 testSameSubjects( g, node( "Q" ), node( "c" ) ); 584 } 585 586 protected void testSameSubjects( Graph g, Node p, Node o ) 587 { 588 Set bis = iteratorToSet( SimpleQueryHandler.subjectsFor( g, p, o ) ); 589 Set qhs = iteratorToSet( g.queryHandler().subjectsFor( p, o ) ); 590 assertEquals( bis, qhs ); 591 } 592 593 public void testListSubjectsNoRemove() 594 { 595 Graph g = getGraphWith( "a P b; b Q c; c R a" ); 596 Iterator it = g.queryHandler().subjectsFor( Node.ANY, Node.ANY ); 597 it.next(); 598 try { it.remove(); fail( "listSubjects for " + g.getClass() + " should not support .remove()" ); } 599 catch (UnsupportedOperationException e) { pass(); } 600 } 601 602 public void testObjectsFor() 603 { 604 Graph g = getGraphWith( "b P a; c Q a; d P a; x P b; y Q c" ); 605 testSameObjects( g, Node.ANY, Node.ANY ); 606 testSameObjects( g, node( "P" ), Node.ANY ); 607 testSameObjects( g, node( "Q" ), node( "c" ) ); 608 } 609 610 protected void testSameObjects( Graph g, Node s, Node p ) 611 { 612 Set bis = iteratorToSet( SimpleQueryHandler.objectsFor( g, s, p ) ); 613 Set qhs = iteratorToSet( g.queryHandler().objectsFor( s, p ) ); 614 assertEquals( bis, qhs ); 615 } 616 617 public void testListObjectsNoRemove() 618 { 619 Graph g = getGraphWith( "a P b; b Q c; c R a" ); 620 Iterator it = g.queryHandler().objectsFor( Node.ANY, Node.ANY ); 621 it.next(); 622 try { it.remove(); fail( "listObjects for " + g.getClass() + " should not support .remove()" ); } 623 catch (UnsupportedOperationException e) { pass(); } 624 } 625 626 public void testPredicatesFor() 627 { 628 Graph g = getGraphWith( "a P b; c Q d; e R f; g P b; h Q i" ); 629 testSamePredicates( g, Node.ANY, Node.ANY ); 630 testSamePredicates( g, Node.ANY, node( "b" ) ); 631 testSamePredicates( g, node( "g" ), Node.ANY ); 632 testSamePredicates( g, node( "e" ), node( "f" ) ); 633 } 634 635 protected void testSamePredicates( Graph g, Node s, Node o ) 636 { 637 Set bis = iteratorToSet( SimpleQueryHandler.predicatesFor( g, s, o ) ); 638 Set qhs = iteratorToSet( g.queryHandler().predicatesFor( s, o ) ); 639 assertEquals( bis, qhs ); 640 } 641 642 public void testListPredicatesNoRemove() 643 { 644 Graph g = getGraphWith( "a P b; b Q c; c R a" ); 645 Iterator it = g.queryHandler().predicatesFor( Node.ANY, Node.ANY ); 646 it.next(); 647 try { it.remove(); fail( "listPredicates for " + g.getClass() + " should not support .remove()" ); } 648 catch (UnsupportedOperationException e) { pass(); } 649 } 650 651 public void testRemoveAll() 652 { 653 testRemoveAll( "" ); 654 testRemoveAll( "a R b" ); 655 testRemoveAll( "c S d; e:ff GGG hhhh; _i J 27; Ell Em 'en'" ); 656 } 657 658 public void testRemoveAll( String triples ) 659 { 660 Graph g = getGraph(); 661 graphAdd( g, triples ); 662 g.getBulkUpdateHandler().removeAll(); 663 assertTrue( g.isEmpty() ); 664 } 665 666 674 protected String [][] cases = 675 { 676 { "x R y", "x R y", "" }, 677 { "x R y; a P b", "x R y", "a P b" }, 678 { "x R y; a P b", "?? R y", "a P b" }, 679 { "x R y; a P b", "x R ??", "a P b" }, 680 { "x R y; a P b", "x ?? y", "a P b" }, 681 { "x R y; a P b", "?? ?? ??", "" }, 682 { "x R y; a P b; c P d", "?? P ??", "x R y" }, 683 { "x R y; a P b; x S y", "x ?? ??", "a P b" }, 684 }; 685 686 691 public void testRemoveSPO() 692 { 693 for (int i = 0; i < cases.length; i += 1) 694 for (int j = 0; j < 3; j += 1) 695 { 696 Graph content = getGraph(); 697 Graph baseContent = copy( content ); 698 graphAdd( content, cases[i][0] ); 699 Triple remove = triple( cases[i][1] ); 700 Graph expected = graphWith( cases[i][2] ); 701 content.getBulkUpdateHandler().remove( remove.getSubject(), remove.getPredicate(), remove.getObject() ); 702 Graph finalContent = remove( copy( content ), baseContent ); 703 assertIsomorphic( cases[i][1], expected, finalContent ); 704 } 705 } 706 707 protected void add( Graph toUpdate, Graph toAdd ) 708 { 709 toUpdate.getBulkUpdateHandler().add( toAdd ); 710 } 711 712 protected Graph remove( Graph toUpdate, Graph toRemove ) 713 { 714 toUpdate.getBulkUpdateHandler().delete( toRemove ); 715 return toUpdate; 716 } 717 718 protected Graph copy( Graph g ) 719 { 720 Graph result = Factory.createDefaultGraph(); 721 result.getBulkUpdateHandler().add( g ); 722 return result; 723 } 724 725 protected Graph getClosed() 726 { 727 Graph result = getGraph(); 728 result.close(); 729 return result; 730 } 731 732 776 } 777 778 779 | Popular Tags |