KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > test > TestGraphExtract


1 /*
2       (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3       [See end of file]
4       $Id: TestGraphExtract.java,v 1.6 2005/02/21 11:52:46 andy_seaborne Exp $
5 */

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 /**
14      Tests for recursive sub-graph extraction.
15      @author hedgehog
16 */

17 public class TestGraphExtract extends GraphTestBase
18     {
19     public TestGraphExtract(String JavaDoc 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     /**
79          This test exposed that the update-existing-graph functionality was broken
80          if the target graph already contained any statements with a subject S
81          appearing as subject in the source graph - no further Spo statements were
82          added.
83     */

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 JavaDoc wanted, String JavaDoc node, String JavaDoc source )
94         {
95         testExtract( wanted, node, source, TripleBoundary.stopNowhere );
96         }
97         
98     /**
99     */

100     private void testExtract( String JavaDoc wanted, String JavaDoc node, String JavaDoc 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 /*
111     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
112     All rights reserved.
113     
114     Redistribution and use in source and binary forms, with or without
115     modification, are permitted provided that the following conditions
116     are met:
117     
118     1. Redistributions of source code must retain the above copyright
119        notice, this list of conditions and the following disclaimer.
120     
121     2. Redistributions in binary form must reproduce the above copyright
122        notice, this list of conditions and the following disclaimer in the
123        documentation and/or other materials provided with the distribution.
124     
125     3. The name of the author may not be used to endorse or promote products
126        derived from this software without specific prior written permission.
127     
128     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
129     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
130     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
131     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
132     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
133     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
134     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
135     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
136     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
137     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
138 */
Popular Tags