KickJava   Java API By Example, From Geeks To Geeks.

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


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

6
7 package com.hp.hpl.jena.graph.test;
8
9 /**
10     Tests that check GraphMem and WrappedGraph for correctness against the Graph
11     and reifier test suites.
12  
13     @author kers
14 */

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 JavaDoc name )
30         { super( name ); }
31         
32     /**
33         Answer a test suite that runs the Graph and Reifier tests on GraphMem and on
34         WrappedGraphMem, the latter standing in for testing WrappedGraph.
35      */

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 JavaDoc classWithTests, Class JavaDoc graphClass )
49         { return MetaTestGraph.suite( classWithTests, graphClass ); }
50         
51     /**
52         Trivial [incomplete] test that a Wrapped graph pokes through to the underlying
53         graph. Really want something using mock classes. Will think about it.
54     */

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     /**
66         Class to provide a constructor that produces a wrapper round a GraphMem.
67         @author kers
68     */

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

153
Popular Tags