1 6 package com.hp.hpl.jena.graph.test; 7 8 import com.hp.hpl.jena.graph.*; 9 import com.hp.hpl.jena.graph.impl.ReifierTripleMap; 10 11 15 public abstract class AbstractTestReifierTripleMap extends GraphTestBase 16 { 17 18 public AbstractTestReifierTripleMap( String name ) 19 { super( name ); } 20 21 protected abstract ReifierTripleMap getTripleMap(); 22 23 protected ReifierTripleMap tripleMap = getTripleMap(); 24 25 protected static final Triple triple_xRy = triple( "x R y" ); 26 protected static final Triple triple_aRb = triple( "a R b" ); 27 28 protected static final Node nodeA = node( "a" ); 29 protected static final Node nodeB = node( "b" ); 30 protected static final Node nodeC = node( "c" ); 31 32 public void testEmptyMap() 33 { 34 assertEquals( null, tripleMap.getTriple( nodeA ) ); 35 assertEquals( null, tripleMap.getTriple( nodeB ) ); 36 assertEquals( false, tripleMap.hasTriple( triple_xRy ) ); 37 assertEquals( false, tripleMap.tagIterator().hasNext() ); 38 assertEquals( false, tripleMap.tagIterator( triple_aRb ).hasNext() ); 39 assertFalse( tripleMap.find( Triple.ANY ).hasNext() ); 40 } 41 42 public void testPutTriple_hasTriple() 43 { 44 tripleMap.putTriple( nodeA, triple_xRy ); 45 assertEquals( true, tripleMap.hasTriple( triple_xRy ) ); 46 assertEquals( false, tripleMap.hasTriple( triple( "x R z" ) ) ); 47 } 48 49 public void testPutTriple_getTriple() 50 { 51 tripleMap.putTriple( nodeA, triple_xRy ); 52 assertEquals( triple_xRy, tripleMap.getTriple( nodeA ) ); 53 assertEquals( null, tripleMap.getTriple( nodeB ) ); 54 } 55 56 public void testPutTriple_tagIterator() 57 { 58 tripleMap.putTriple( nodeA, triple_xRy ); 59 assertEquals( nodeSet( "a" ), iteratorToSet( tripleMap.tagIterator() ) ); 60 } 61 62 public void testPutTriple_tagIteratorT() 63 { 64 tripleMap.putTriple( nodeA, triple_xRy ); 65 assertEquals( nodeSet( "a" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) ); 66 assertEquals( nodeSet( "" ), iteratorToSet( tripleMap.tagIterator( triple( "x S y" ) ) ) ); 67 } 68 69 public void testPutTriples_hasTriple() 70 { 71 put_xRy_and_aRb(); 72 assertEquals( true, tripleMap.hasTriple( triple_xRy ) ); 73 assertEquals( true, tripleMap.hasTriple( triple_aRb ) ); 74 } 75 76 public void testPutTriples_getTriple() 77 { 78 put_xRy_and_aRb(); 79 assertEquals( triple_xRy, tripleMap.getTriple( nodeA ) ); 80 assertEquals( triple_aRb, tripleMap.getTriple( nodeB ) ); 81 } 82 83 public void testPutTriples_tagIterator() 84 { 85 put_xRy_and_aRb(); 86 assertEquals( nodeSet( "a b" ), iteratorToSet( tripleMap.tagIterator() ) ); 87 } 88 89 public void testPutTriples_tagIteratorT() 90 { 91 put_xRy_and_aRb(); 92 assertEquals( nodeSet( "a" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) ); 93 assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator( triple_aRb ) ) ); 94 } 95 96 public void testMultipleTagging() 97 { 98 tripleMap.putTriple( nodeA, triple_xRy ); 99 tripleMap.putTriple( nodeB, triple_xRy ); 100 assertEquals( nodeSet( "a b" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) ); 101 } 102 103 public void testRemoveTriplesByTag() 104 { 105 put_xRy_and_aRb(); 106 tripleMap.removeTriple( nodeA ); 107 assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator() ) ); 108 assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator( triple_aRb ) ) ); 109 assertEquals( nodeSet( "" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) ); 110 } 111 112 public void testRemoveTaggedTriple() 113 { 114 put_xRy_and_aRb(); 115 tripleMap.removeTriple( nodeA, triple_xRy ); 116 assertEquals( null, tripleMap.getTriple( nodeA ) ); 117 assertEquals( triple_aRb, tripleMap.getTriple( nodeB ) ); 118 assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator( triple_aRb ) ) ); 119 assertEquals( nodeSet( "" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) ); 120 } 121 122 public void testRemoveTripleDirectly() 123 { 124 put_xRy_and_aRb(); 125 tripleMap.putTriple( nodeC, triple_xRy ); 126 tripleMap.removeTriple( triple_xRy ); 127 assertEquals( null, tripleMap.getTriple( nodeA ) ); 128 assertEquals( null, tripleMap.getTriple( nodeC ) ); 129 assertEquals( triple_aRb, tripleMap.getTriple( nodeB ) ); 130 assertEquals( nodeSet( "b" ), iteratorToSet( tripleMap.tagIterator( triple_aRb ) ) ); 131 assertEquals( nodeSet( "" ), iteratorToSet( tripleMap.tagIterator( triple_xRy ) ) ); 132 } 133 134 protected void put_xRy_and_aRb() 135 { 136 tripleMap.putTriple( nodeA, triple_xRy ); 137 tripleMap.putTriple( nodeB, triple_aRb ); 138 } 139 140 } 141 142 | Popular Tags |