1 7 8 package com.hp.hpl.jena.rdf.model.test; 9 10 import com.hp.hpl.jena.graph.*; 11 import com.hp.hpl.jena.rdf.model.*; 12 13 import junit.framework.TestSuite; 14 15 18 public class TestModelExtract extends ModelTestBase 19 { 20 protected static final StatementBoundary sbTrue = new StatementBoundaryBase() 21 { 22 public boolean stopAt( Statement s ) { return true; } 23 }; 24 25 protected static final StatementBoundary sbFalse = new StatementBoundaryBase() 26 { 27 public boolean stopAt( Statement s ) { return false; } 28 }; 29 30 public TestModelExtract( String name ) 31 { super( name ); } 32 33 public static TestSuite suite() 34 { return new TestSuite( TestModelExtract.class ); } 35 36 static class MockModelExtract extends ModelExtract 37 { 38 Node root; 39 Graph result; 40 Graph subject; 41 42 public MockModelExtract( StatementBoundary b ) 43 { super( b ); } 44 45 public StatementBoundary getStatementBoundary() 46 { return boundary; } 47 48 protected GraphExtract getGraphExtract( TripleBoundary b ) 49 { 50 return new GraphExtract( b ) 51 { 52 public Graph extractInto( Graph toUpdate, Node n, Graph source ) 53 { 54 root = n; 55 return result = super.extractInto( toUpdate, n, subject = source ); 56 } 57 }; 58 } 59 } 60 61 public void testAsTripleBoundary() 62 { 63 Model m = ModelFactory.createDefaultModel(); 64 assertTrue( sbTrue.asTripleBoundary( m ).stopAt( triple( "x R y" ) ) ); 65 assertFalse( sbFalse.asTripleBoundary( m ).stopAt( triple( "x R y" ) ) ); 66 } 67 68 public void testStatementTripleBoundaryAnon() 69 { 70 TripleBoundary anon = TripleBoundary.stopAtAnonObject; 71 assertSame( anon, new StatementTripleBoundary( anon ).asTripleBoundary( null ) ); 72 assertFalse( new StatementTripleBoundary( anon ).stopAt( statement( "s P o" ) ) ); 73 assertTrue( new StatementTripleBoundary( anon ).stopAt( statement( "s P _o" ) ) ); 74 } 75 76 public void testStatementContinueWith() 77 { 78 StatementBoundary sb = new StatementBoundaryBase() 79 { public boolean continueWith( Statement s ) { return false; } }; 80 assertTrue( sb.stopAt( statement( "x pings y" ) ) ); 81 } 82 83 public void testStatementTripleBoundaryNowhere() 84 { 85 TripleBoundary nowhere = TripleBoundary.stopNowhere; 86 assertSame( nowhere, new StatementTripleBoundary( nowhere ).asTripleBoundary( null ) ); 87 assertFalse( new StatementTripleBoundary( nowhere ).stopAt( statement( "s P _o" ) ) ); 88 assertFalse( new StatementTripleBoundary( nowhere ).stopAt( statement( "s P o" ) ) ); 89 } 90 public void testRemembersBoundary() 91 { 92 assertSame( sbTrue, new MockModelExtract( sbTrue ).getStatementBoundary() ); 93 assertSame( sbFalse, new MockModelExtract( sbFalse ).getStatementBoundary() ); 94 } 95 96 public void testInvokesExtract() 97 { 98 MockModelExtract mock = new MockModelExtract( sbTrue ); 99 Model source = modelWithStatements( "a R b" ); 100 Model m = mock.extract( resource( "a" ), source ); 101 assertEquals( node( "a" ), mock.root ); 102 assertSame( mock.result, m.getGraph() ); 103 assertSame( mock.subject, source.getGraph() ); 104 } 105 106 109 public boolean stopAt( Statement s ) 110 { 111 return false; 113 } 114 115 118 public TripleBoundary asTripleBoundary( Model m ) 119 { 120 return null; 122 } 123 } 124 125 151 | Popular Tags |