KickJava   Java API By Example, From Geeks To Geeks.

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


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

6 package com.hp.hpl.jena.graph.test;
7
8 import com.hp.hpl.jena.graph.impl.TripleStore;
9
10 /**
11      AbstractTestTripleStore - post-hoc tests for TripleStores.
12      @author kers
13 */

14 public abstract class AbstractTestTripleStore extends GraphTestBase
15     {
16     public AbstractTestTripleStore( String JavaDoc name )
17         { super( name ); }
18     
19     /**
20          Subclasses must over-ride to return a new empty TripleStore.
21     */

22     public abstract TripleStore getTripleStore();
23     
24     protected TripleStore store;
25     
26     public void setUp()
27         {
28         store = getTripleStore();
29         }
30     
31     public void testEmpty()
32         { testEmpty( store ); }
33     
34     public void testAddOne()
35         {
36         store.add( triple( "x P y" ) );
37         assertEquals( false, store.isEmpty() );
38         assertEquals( 1, store.size() );
39         assertEquals( true, store.contains( triple( "x P y" ) ) );
40         assertEquals( nodeSet( "x" ), iteratorToSet( store.listSubjects() ) );
41         assertEquals( nodeSet( "y" ), iteratorToSet( store.listObjects() ) );
42         assertEquals( tripleSet( "x P y" ), iteratorToSet( store.find( triple( "?? ?? ??" ) ) ) );
43         }
44
45     public void testListSubjects()
46         {
47         someStatements( store );
48         assertEquals( nodeSet( "a x _z r q" ), iteratorToSet( store.listSubjects() ) );
49         }
50     
51     public void testListObjects()
52         {
53         someStatements( store );
54         assertEquals( nodeSet( "b y i _j _t 17" ), iteratorToSet( store.listObjects() ) );
55         }
56     
57     public void testContains()
58         {
59         someStatements( store );
60         assertEquals( true, store.contains( triple( "a P b" ) ) );
61         assertEquals( true, store.contains( triple( "x P y" ) ) );
62         assertEquals( true, store.contains( triple( "a P i" ) ) );
63         assertEquals( true, store.contains( triple( "_z Q _j" ) ) );
64         assertEquals( true, store.contains( triple( "x R y" ) ) );
65         assertEquals( true, store.contains( triple( "r S _t" ) ) );
66         assertEquals( true, store.contains( triple( "q R 17" ) ) );
67     /* */
68         assertEquals( false, store.contains( triple( "a P x" ) ) );
69         assertEquals( false, store.contains( triple( "a P _j" ) ) );
70         assertEquals( false, store.contains( triple( "b Z r" ) ) );
71         assertEquals( false, store.contains( triple( "_a P x" ) ) );
72         }
73     
74     public void testFind()
75         {
76         someStatements( store );
77         assertEquals( tripleSet( "" ), iteratorToSet( store.find( triple( "no such thing" ) ) ) );
78         assertEquals( tripleSet( "a P b; a P i" ), iteratorToSet( store.find( triple( "a P ??" ) ) ) );
79         assertEquals( tripleSet( "a P b; x P y; a P i" ), iteratorToSet( store.find( triple( "?? P ??" ) ) ) );
80         assertEquals( tripleSet( "x P y; x R y" ), iteratorToSet( store.find( triple( "x ?? y" ) ) ) );
81         assertEquals( tripleSet( "_z Q _j" ), iteratorToSet( store.find( triple( "?? ?? _j" ) ) ) );
82         assertEquals( tripleSet( "q R 17" ), iteratorToSet( store.find( triple( "?? ?? 17" ) ) ) );
83         }
84     
85     public void testRemove()
86         {
87         store.add( triple( "nothing before ace" ) );
88         store.add( triple( "ace before king" ) );
89         store.add( triple( "king before queen" ) );
90         store.delete( triple( "ace before king" ) );
91         assertEquals( tripleSet( "king before queen; nothing before ace" ), iteratorToSet( store.find( triple( "?? ?? ??" ) ) ) );
92         store.delete( triple( "king before queen" ) );
93         assertEquals( tripleSet( "nothing before ace" ), iteratorToSet( store.find( triple( "?? ?? ??" ) ) ) );
94         }
95     
96     public void someStatements( TripleStore ts )
97         {
98         ts.add( triple( "a P b" ) );
99         ts.add( triple( "x P y" ) );
100         ts.add( triple( "a P i" ) );
101         ts.add( triple( "_z Q _j" ) );
102         ts.add( triple( "x R y" ) );
103         ts.add( triple( "r S _t" ) );
104         ts.add( triple( "q R 17" ) );
105         }
106     
107     public void testEmpty( TripleStore ts )
108         {
109         assertEquals( true, ts.isEmpty() );
110         assertEquals( 0, ts.size() );
111         assertEquals( false, ts.find( triple( "?? ?? ??" ) ).hasNext() );
112         assertEquals( false, ts.listObjects().hasNext() );
113         assertEquals( false, ts.listSubjects().hasNext() );
114         assertFalse( ts.contains( triple( "x P y" ) ) );
115         }
116     }
117
118
119 /*
120     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
121     All rights reserved.
122     
123     Redistribution and use in source and binary forms, with or without
124     modification, are permitted provided that the following conditions
125     are met:
126     
127     1. Redistributions of source code must retain the above copyright
128        notice, this list of conditions and the following disclaimer.
129     
130     2. Redistributions in binary form must reproduce the above copyright
131        notice, this list of conditions and the following disclaimer in the
132        documentation and/or other materials provided with the distribution.
133     
134     3. The name of the author may not be used to endorse or promote products
135        derived from this software without specific prior written permission.
136     
137     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
138     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
139     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
140     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
141     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
142     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
143     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
144     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
145     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
146     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
147 */
Popular Tags