001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: AbstractTestTripleStore.java,v 1.9 2008/01/02 12:05:34 andy_seaborne Exp $
005: */
006: package com.hp.hpl.jena.graph.test;
007:
008: import com.hp.hpl.jena.graph.impl.TripleStore;
009:
010: /**
011: AbstractTestTripleStore - post-hoc tests for TripleStores.
012: @author kers
013: */
014: public abstract class AbstractTestTripleStore extends GraphTestBase {
015: public AbstractTestTripleStore(String name) {
016: super (name);
017: }
018:
019: /**
020: Subclasses must over-ride to return a new empty TripleStore.
021: */
022: public abstract TripleStore getTripleStore();
023:
024: protected TripleStore store;
025:
026: public void setUp() {
027: store = getTripleStore();
028: }
029:
030: public void testEmpty() {
031: testEmpty(store);
032: }
033:
034: public void testAddOne() {
035: store.add(triple("x P y"));
036: assertEquals(false, store.isEmpty());
037: assertEquals(1, store.size());
038: assertEquals(true, store.contains(triple("x P y")));
039: assertEquals(nodeSet("x"), iteratorToSet(store.listSubjects()));
040: assertEquals(nodeSet("y"), iteratorToSet(store.listObjects()));
041: assertEquals(tripleSet("x P y"), iteratorToSet(store
042: .find(triple("?? ?? ??"))));
043: }
044:
045: public void testListSubjects() {
046: someStatements(store);
047: assertEquals(nodeSet("a x _z r q"), iteratorToSet(store
048: .listSubjects()));
049: }
050:
051: public void testListObjects() {
052: someStatements(store);
053: assertEquals(nodeSet("b y i _j _t 17"), iteratorToSet(store
054: .listObjects()));
055: }
056:
057: public void testContains() {
058: someStatements(store);
059: assertEquals(true, store.contains(triple("a P b")));
060: assertEquals(true, store.contains(triple("x P y")));
061: assertEquals(true, store.contains(triple("a P i")));
062: assertEquals(true, store.contains(triple("_z Q _j")));
063: assertEquals(true, store.contains(triple("x R y")));
064: assertEquals(true, store.contains(triple("r S _t")));
065: assertEquals(true, store.contains(triple("q R 17")));
066: /* */
067: assertEquals(false, store.contains(triple("a P x")));
068: assertEquals(false, store.contains(triple("a P _j")));
069: assertEquals(false, store.contains(triple("b Z r")));
070: assertEquals(false, store.contains(triple("_a P x")));
071: }
072:
073: public void testFind() {
074: someStatements(store);
075: assertEquals(tripleSet(""), iteratorToSet(store
076: .find(triple("no such thing"))));
077: assertEquals(tripleSet("a P b; a P i"), iteratorToSet(store
078: .find(triple("a P ??"))));
079: assertEquals(tripleSet("a P b; x P y; a P i"),
080: iteratorToSet(store.find(triple("?? P ??"))));
081: assertEquals(tripleSet("x P y; x R y"), iteratorToSet(store
082: .find(triple("x ?? y"))));
083: assertEquals(tripleSet("_z Q _j"), iteratorToSet(store
084: .find(triple("?? ?? _j"))));
085: assertEquals(tripleSet("q R 17"), iteratorToSet(store
086: .find(triple("?? ?? 17"))));
087: }
088:
089: public void testRemove() {
090: store.add(triple("nothing before ace"));
091: store.add(triple("ace before king"));
092: store.add(triple("king before queen"));
093: store.delete(triple("ace before king"));
094: assertEquals(
095: tripleSet("king before queen; nothing before ace"),
096: iteratorToSet(store.find(triple("?? ?? ??"))));
097: store.delete(triple("king before queen"));
098: assertEquals(tripleSet("nothing before ace"),
099: iteratorToSet(store.find(triple("?? ?? ??"))));
100: }
101:
102: public void someStatements(TripleStore ts) {
103: ts.add(triple("a P b"));
104: ts.add(triple("x P y"));
105: ts.add(triple("a P i"));
106: ts.add(triple("_z Q _j"));
107: ts.add(triple("x R y"));
108: ts.add(triple("r S _t"));
109: ts.add(triple("q R 17"));
110: }
111:
112: public void testEmpty(TripleStore ts) {
113: assertEquals(true, ts.isEmpty());
114: assertEquals(0, ts.size());
115: assertEquals(false, ts.find(triple("?? ?? ??")).hasNext());
116: assertEquals(false, ts.listObjects().hasNext());
117: assertEquals(false, ts.listSubjects().hasNext());
118: assertFalse(ts.contains(triple("x P y")));
119: }
120: }
121:
122: /*
123: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
124: All rights reserved.
125:
126: Redistribution and use in source and binary forms, with or without
127: modification, are permitted provided that the following conditions
128: are met:
129:
130: 1. Redistributions of source code must retain the above copyright
131: notice, this list of conditions and the following disclaimer.
132:
133: 2. Redistributions in binary form must reproduce the above copyright
134: notice, this list of conditions and the following disclaimer in the
135: documentation and/or other materials provided with the distribution.
136:
137: 3. The name of the author may not be used to endorse or promote products
138: derived from this software without specific prior written permission.
139:
140: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
141: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
142: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
143: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
144: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
145: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
146: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
147: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
148: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
149: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
150: */
|