1 6 7 package com.hp.hpl.jena.graph.test; 8 9 15 16 import com.hp.hpl.jena.mem.*; 17 import com.hp.hpl.jena.shared.ReificationStyle; 18 import com.hp.hpl.jena.util.CollectionFactory; 19 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 20 import com.hp.hpl.jena.graph.*; 21 import com.hp.hpl.jena.graph.impl.*; 22 23 import java.util.*; 24 25 import junit.framework.*; 26 27 public class TestGraph extends GraphTestBase 28 { 29 public TestGraph( String name ) 30 { super( name ); } 31 32 36 public static TestSuite suite() 37 { 38 TestSuite result = new TestSuite( TestGraph.class ); 39 result.addTest( suite( MetaTestGraph.class, GraphMem.class ) ); 40 result.addTest( suite( TestReifier.class, GraphMem.class ) ); 41 result.addTest( suite( MetaTestGraph.class, SmallGraphMem.class ) ); 42 result.addTest( suite( TestReifier.class, SmallGraphMem.class ) ); 43 result.addTest( suite( MetaTestGraph.class, WrappedGraphMem.class ) ); 44 result.addTest( suite( TestReifier.class, WrappedGraphMem.class ) ); 45 return result; 46 } 47 48 public static TestSuite suite( Class classWithTests, Class graphClass ) 49 { return MetaTestGraph.suite( classWithTests, graphClass ); } 50 51 55 public void testWrappedSame() 56 { 57 Graph m = new GraphMem(); 58 Graph w = new WrappedGraph( m ); 59 graphAdd( m, "a trumps b; c eats d" ); 60 assertIsomorphic( m, w ); 61 graphAdd( w, "i write this; you read that" ); 62 assertIsomorphic( w, m ); 63 } 64 65 69 public static class WrappedGraphMem extends WrappedGraph 70 { 71 public WrappedGraphMem( ReificationStyle style ) 72 { super( new GraphMem( style ) ); } 73 } 74 75 public void testListSubjectsDoesntUseFind() 76 { 77 final boolean [] called = {false}; 78 79 Graph g = new GraphMem() 80 { 81 public ExtendedIterator graphBaseFind( TripleMatch m ) 82 { called[0] = true; return super.find( m ); } 83 }; 84 85 ExtendedIterator subjects = g.queryHandler().subjectsFor( null, null ); 86 Set s = CollectionFactory.createHashedSet(); 87 while (subjects.hasNext()) s.add( subjects.next() ); 88 assertFalse( "find should not have been called", called[0] ); 89 } 90 91 public void testListPredicatesDoesntUseFind() 92 { 93 final boolean [] called = {false}; 94 95 Graph g = new GraphMem() 96 { 97 public ExtendedIterator graphBaseFind( TripleMatch m ) 98 { called[0] = true; return super.find( m ); } 99 }; 100 101 ExtendedIterator predicates = g.queryHandler().predicatesFor( null, null ); 102 Set s = CollectionFactory.createHashedSet(); 103 while (predicates.hasNext()) s.add( predicates.next() ); 104 assertFalse( "find should not have been called", called[0] ); 105 } 106 107 public void testListObjectsDoesntUseFind() 108 { 109 final boolean [] called = {false}; 110 111 Graph g = new GraphMem() 112 { 113 public ExtendedIterator graphBaseFind( TripleMatch m ) 114 { called[0] = true; return super.find( m ); } 115 }; 116 117 ExtendedIterator subjects = g.queryHandler().objectsFor( null, null ); 118 Set s = CollectionFactory.createHashedSet(); 119 while (subjects.hasNext()) s.add( subjects.next() ); 120 assertFalse( "find should not have been called", called[0] ); 121 } 122 } 123 124 153 | Popular Tags |