1 6 package com.hp.hpl.jena.graph.test; 7 8 import com.hp.hpl.jena.graph.impl.TripleStore; 9 10 14 public abstract class AbstractTestTripleStore extends GraphTestBase 15 { 16 public AbstractTestTripleStore( String name ) 17 { super( name ); } 18 19 22 public abstract TripleStore getTripleStore(); 23 24 protected TripleStore store; 25 26 public void setUp() 27 { 28 store = getTripleStore(); 29 } 30 31 public void testEmpty() 32 { testEmpty( store ); } 33 34 public void testAddOne() 35 { 36 store.add( triple( "x P y" ) ); 37 assertEquals( false, store.isEmpty() ); 38 assertEquals( 1, store.size() ); 39 assertEquals( true, store.contains( triple( "x P y" ) ) ); 40 assertEquals( nodeSet( "x" ), iteratorToSet( store.listSubjects() ) ); 41 assertEquals( nodeSet( "y" ), iteratorToSet( store.listObjects() ) ); 42 assertEquals( tripleSet( "x P y" ), iteratorToSet( store.find( triple( "?? ?? ??" ) ) ) ); 43 } 44 45 public void testListSubjects() 46 { 47 someStatements( store ); 48 assertEquals( nodeSet( "a x _z r q" ), iteratorToSet( store.listSubjects() ) ); 49 } 50 51 public void testListObjects() 52 { 53 someStatements( store ); 54 assertEquals( nodeSet( "b y i _j _t 17" ), iteratorToSet( store.listObjects() ) ); 55 } 56 57 public void testContains() 58 { 59 someStatements( store ); 60 assertEquals( true, store.contains( triple( "a P b" ) ) ); 61 assertEquals( true, store.contains( triple( "x P y" ) ) ); 62 assertEquals( true, store.contains( triple( "a P i" ) ) ); 63 assertEquals( true, store.contains( triple( "_z Q _j" ) ) ); 64 assertEquals( true, store.contains( triple( "x R y" ) ) ); 65 assertEquals( true, store.contains( triple( "r S _t" ) ) ); 66 assertEquals( true, store.contains( triple( "q R 17" ) ) ); 67 68 assertEquals( false, store.contains( triple( "a P x" ) ) ); 69 assertEquals( false, store.contains( triple( "a P _j" ) ) ); 70 assertEquals( false, store.contains( triple( "b Z r" ) ) ); 71 assertEquals( false, store.contains( triple( "_a P x" ) ) ); 72 } 73 74 public void testFind() 75 { 76 someStatements( store ); 77 assertEquals( tripleSet( "" ), iteratorToSet( store.find( triple( "no such thing" ) ) ) ); 78 assertEquals( tripleSet( "a P b; a P i" ), iteratorToSet( store.find( triple( "a P ??" ) ) ) ); 79 assertEquals( tripleSet( "a P b; x P y; a P i" ), iteratorToSet( store.find( triple( "?? P ??" ) ) ) ); 80 assertEquals( tripleSet( "x P y; x R y" ), iteratorToSet( store.find( triple( "x ?? y" ) ) ) ); 81 assertEquals( tripleSet( "_z Q _j" ), iteratorToSet( store.find( triple( "?? ?? _j" ) ) ) ); 82 assertEquals( tripleSet( "q R 17" ), iteratorToSet( store.find( triple( "?? ?? 17" ) ) ) ); 83 } 84 85 public void testRemove() 86 { 87 store.add( triple( "nothing before ace" ) ); 88 store.add( triple( "ace before king" ) ); 89 store.add( triple( "king before queen" ) ); 90 store.delete( triple( "ace before king" ) ); 91 assertEquals( tripleSet( "king before queen; nothing before ace" ), iteratorToSet( store.find( triple( "?? ?? ??" ) ) ) ); 92 store.delete( triple( "king before queen" ) ); 93 assertEquals( tripleSet( "nothing before ace" ), iteratorToSet( store.find( triple( "?? ?? ??" ) ) ) ); 94 } 95 96 public void someStatements( TripleStore ts ) 97 { 98 ts.add( triple( "a P b" ) ); 99 ts.add( triple( "x P y" ) ); 100 ts.add( triple( "a P i" ) ); 101 ts.add( triple( "_z Q _j" ) ); 102 ts.add( triple( "x R y" ) ); 103 ts.add( triple( "r S _t" ) ); 104 ts.add( triple( "q R 17" ) ); 105 } 106 107 public void testEmpty( TripleStore ts ) 108 { 109 assertEquals( true, ts.isEmpty() ); 110 assertEquals( 0, ts.size() ); 111 assertEquals( false, ts.find( triple( "?? ?? ??" ) ).hasNext() ); 112 assertEquals( false, ts.listObjects().hasNext() ); 113 assertEquals( false, ts.listSubjects().hasNext() ); 114 assertFalse( ts.contains( triple( "x P y" ) ) ); 115 } 116 } 117 118 119 | Popular Tags |