1 6 7 package com.hp.hpl.jena.graph.test; 8 9 import com.hp.hpl.jena.graph.*; 10 11 import junit.framework.TestSuite; 12 13 17 public class TestGraphExtract extends GraphTestBase 18 { 19 public TestGraphExtract(String name) 20 { super( name ); } 21 22 public static TestSuite suite() 23 { return new TestSuite( TestGraphExtract.class ); } 24 25 public void testExtractNothing() 26 { 27 testExtract( "", "x", "" ); 28 testExtract( "", "x", "a R b" ); 29 testExtract( "", "x", "a R x" ); 30 testExtract( "","x", "a x y" ); 31 } 32 33 public void testExtractOneLevel() 34 { 35 testExtract( "a R b", "a", "a R b" ); 36 testExtract("a R b; a R c", "a", "a R b; a R c" ); 37 testExtract( "a R b; a S d", "a", "a R b; a S d" ); 38 } 39 40 public void testNoJunk() 41 { 42 testExtract( "a R b", "a", "a R b; x R y" ); 43 } 44 45 public void testExtractTwoLevels() 46 { 47 testExtract( "a R b; b S c", "a", "a R b; b S c" ); 48 testExtract( "a R b; b S c", "a", "a R b; b S c; x P y" ); 49 testExtract( "a R b; b S c; b T d", "a", "a R b; b S c; b T d" ); 50 testExtract( "a R b; b S c; a T d", "a", "a R b; a T d; b S c" ); 51 } 52 53 public void testExtractSeveralLevels() 54 { 55 testExtract( "a R b; b S c; c T d; d U e", "a", "a R b; b S c; c T d; d U e" ); 56 } 57 58 public void testExtractNoLoop() 59 { 60 testExtract( "a R a", "a", "a R a" ); 61 testExtract( "a R b; b R a", "a", "a R b; b R a; z P a" ); 62 testExtract( "a R b; b S c; c T a", "a", "a R b; b S c; c T a; junk P junk" ); 63 } 64 65 public void testTripleFilter() 66 { 67 assertTrue( TripleBoundary.stopAtAnonObject.stopAt( triple( "a R _b" ) ) ); 68 assertFalse( TripleBoundary.stopAtAnonObject.stopAt( triple( "a R b" ) ) ); 69 assertFalse( TripleBoundary.stopAtAnonObject.stopAt( triple( "a _R b" ) ) ); 70 assertFalse( TripleBoundary.stopAtAnonObject.stopAt( triple( "_a R b" ) ) ); 71 } 72 73 public void testExtractBoundary() 74 { 75 testExtract( "a R b; b S _c", "a", "a R b; b S _c; _c T d", TripleBoundary.stopAtAnonObject ); 76 } 77 78 84 public void testPartialUpdate() 85 { 86 Graph source = graphWith( "a R b; b S e" ); 87 Graph dest = graphWith( "b R d" ); 88 GraphExtract e = new GraphExtract( TripleBoundary.stopNowhere ); 89 e.extractInto( dest, node( "a" ), source ); 90 assertIsomorphic( graphWith( "a R b; b S e; b R d" ), dest ); 91 } 92 93 public void testExtract( String wanted, String node, String source ) 94 { 95 testExtract( wanted, node, source, TripleBoundary.stopNowhere ); 96 } 97 98 100 private void testExtract( String wanted, String node, String source, TripleBoundary b ) 101 { 102 assertIsomorphic( graphWith( wanted ), extract( node( node ), b, graphWith( source ) ) ); 103 } 104 105 public Graph extract( Node node, TripleBoundary b, Graph graph ) 106 { return new GraphExtract( b ).extract( node, graph ); } 107 108 } 109 110 | Popular Tags |