KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > mem > test > TestGraphMem


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestGraphMem.java,v 1.12 2005/02/21 12:03:59 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.mem.test;
8
9 import com.hp.hpl.jena.graph.*;
10 import com.hp.hpl.jena.graph.impl.SimpleReifier;
11 import com.hp.hpl.jena.graph.test.*;
12 import com.hp.hpl.jena.mem.GraphMem;
13 import com.hp.hpl.jena.shared.JenaException;
14 import com.hp.hpl.jena.util.iterator.ExtendedIterator;
15
16 import junit.framework.*;
17
18 /**
19     @author kers
20 */

21 public class TestGraphMem extends AbstractTestGraph
22     {
23     public TestGraphMem(String JavaDoc name)
24         { super(name); }
25     
26     public static TestSuite suite()
27         { return new TestSuite( TestGraphMem.class ); }
28         
29     public Graph getGraph()
30         { return new GraphMem(); }
31         
32     public void testClosesReifier()
33         {
34         Graph g = getGraph();
35         SimpleReifier r = (SimpleReifier) g.getReifier();
36         g.close();
37         assertTrue( r.isClosed() );
38         }
39     
40     public void testBrokenIndexes()
41         {
42         Graph g = getGraphWith( "x R y; x S z" );
43         ExtendedIterator it = g.find( Node.ANY, Node.ANY, Node.ANY );
44         it.next(); it.remove(); it.next(); it.remove();
45         assertFalse( g.find( node( "x" ), Node.ANY, Node.ANY ).hasNext() );
46         assertFalse( g.find( Node.ANY, node( "R" ), Node.ANY ).hasNext() );
47         assertFalse( g.find( Node.ANY, Node.ANY, node( "y" ) ).hasNext() );
48         }
49             
50     public void testBrokenSubject()
51         {
52         Graph g = getGraphWith( "x brokenSubject y" );
53         ExtendedIterator it = g.find( node( "x" ), Node.ANY, Node.ANY );
54         it.next(); it.remove();
55         assertFalse( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() );
56         }
57         
58     public void testBrokenPredicate()
59         {
60         Graph g = getGraphWith( "x brokenPredicate y" );
61         ExtendedIterator it = g.find( Node.ANY, node( "brokenPredicate"), Node.ANY );
62         it.next(); it.remove();
63         assertFalse( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() );
64         }
65         
66     public void testBrokenObject()
67         {
68         Graph g = getGraphWith( "x brokenObject y" );
69         ExtendedIterator it = g.find( Node.ANY, Node.ANY, node( "y" ) );
70         it.next(); it.remove();
71         assertFalse( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() );
72         }
73     
74     public void testRemoveAllDoesntUseFind()
75         {
76         Graph g = new GraphMemWithoutFind();
77         graphAdd( g, "x P y; a Q b" );
78         g.getBulkUpdateHandler().removeAll();
79         assertEquals( 0, g.size() );
80         }
81     
82     public void testContainsConcreteDoesntUseFind()
83         {
84         Graph g = new GraphMemWithoutFind();
85         graphAdd( g, "x P y; a Q b" );
86         assertTrue( g.contains( triple( "x P y" ) ) );
87         assertTrue( g.contains( triple( "a Q b" ) ) );
88         assertFalse( g.contains( triple( "a P y" ) ) );
89         assertFalse( g.contains( triple( "y R b" ) ) );
90         }
91     
92     protected final class GraphMemWithoutFind extends GraphMem
93         {
94         public ExtendedIterator graphBaseFind( TripleMatch t )
95             { throw new JenaException( "find is Not Allowed" ); }
96         }
97     }
98
99
100 /*
101     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
102     All rights reserved.
103
104     Redistribution and use in source and binary forms, with or without
105     modification, are permitted provided that the following conditions
106     are met:
107
108     1. Redistributions of source code must retain the above copyright
109        notice, this list of conditions and the following disclaimer.
110
111     2. Redistributions in binary form must reproduce the above copyright
112        notice, this list of conditions and the following disclaimer in the
113        documentation and/or other materials provided with the distribution.
114
115     3. The name of the author may not be used to endorse or promote products
116        derived from this software without specific prior written permission.
117
118     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
119     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
120     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
121     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
122     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
123     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
124     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
125     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
126     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
127     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
128 */
Popular Tags