1 6 7 package com.hp.hpl.jena.mem.test; 8 9 import com.hp.hpl.jena.graph.*; 10 import com.hp.hpl.jena.graph.impl.SimpleReifier; 11 import com.hp.hpl.jena.graph.test.*; 12 import com.hp.hpl.jena.mem.GraphMem; 13 import com.hp.hpl.jena.shared.JenaException; 14 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 15 16 import junit.framework.*; 17 18 21 public class TestGraphMem extends AbstractTestGraph 22 { 23 public TestGraphMem(String name) 24 { super(name); } 25 26 public static TestSuite suite() 27 { return new TestSuite( TestGraphMem.class ); } 28 29 public Graph getGraph() 30 { return new GraphMem(); } 31 32 public void testClosesReifier() 33 { 34 Graph g = getGraph(); 35 SimpleReifier r = (SimpleReifier) g.getReifier(); 36 g.close(); 37 assertTrue( r.isClosed() ); 38 } 39 40 public void testBrokenIndexes() 41 { 42 Graph g = getGraphWith( "x R y; x S z" ); 43 ExtendedIterator it = g.find( Node.ANY, Node.ANY, Node.ANY ); 44 it.next(); it.remove(); it.next(); it.remove(); 45 assertFalse( g.find( node( "x" ), Node.ANY, Node.ANY ).hasNext() ); 46 assertFalse( g.find( Node.ANY, node( "R" ), Node.ANY ).hasNext() ); 47 assertFalse( g.find( Node.ANY, Node.ANY, node( "y" ) ).hasNext() ); 48 } 49 50 public void testBrokenSubject() 51 { 52 Graph g = getGraphWith( "x brokenSubject y" ); 53 ExtendedIterator it = g.find( node( "x" ), Node.ANY, Node.ANY ); 54 it.next(); it.remove(); 55 assertFalse( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() ); 56 } 57 58 public void testBrokenPredicate() 59 { 60 Graph g = getGraphWith( "x brokenPredicate y" ); 61 ExtendedIterator it = g.find( Node.ANY, node( "brokenPredicate"), Node.ANY ); 62 it.next(); it.remove(); 63 assertFalse( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() ); 64 } 65 66 public void testBrokenObject() 67 { 68 Graph g = getGraphWith( "x brokenObject y" ); 69 ExtendedIterator it = g.find( Node.ANY, Node.ANY, node( "y" ) ); 70 it.next(); it.remove(); 71 assertFalse( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() ); 72 } 73 74 public void testRemoveAllDoesntUseFind() 75 { 76 Graph g = new GraphMemWithoutFind(); 77 graphAdd( g, "x P y; a Q b" ); 78 g.getBulkUpdateHandler().removeAll(); 79 assertEquals( 0, g.size() ); 80 } 81 82 public void testContainsConcreteDoesntUseFind() 83 { 84 Graph g = new GraphMemWithoutFind(); 85 graphAdd( g, "x P y; a Q b" ); 86 assertTrue( g.contains( triple( "x P y" ) ) ); 87 assertTrue( g.contains( triple( "a Q b" ) ) ); 88 assertFalse( g.contains( triple( "a P y" ) ) ); 89 assertFalse( g.contains( triple( "y R b" ) ) ); 90 } 91 92 protected final class GraphMemWithoutFind extends GraphMem 93 { 94 public ExtendedIterator graphBaseFind( TripleMatch t ) 95 { throw new JenaException( "find is Not Allowed" ); } 96 } 97 } 98 99 100 | Popular Tags |