001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: AbstractTestGraphMem.java,v 1.2 2008/01/02 12:09:00 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.mem.test;
008:
009: import java.util.Iterator;
010:
011: import com.hp.hpl.jena.graph.*;
012: import com.hp.hpl.jena.graph.impl.SimpleReifier;
013: import com.hp.hpl.jena.graph.test.AbstractTestGraph;
014: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
015:
016: public class AbstractTestGraphMem extends AbstractTestGraph {
017: public AbstractTestGraphMem(String name) {
018: super (name);
019: }
020:
021: public void testClosesReifier() {
022: Graph g = getGraph();
023: SimpleReifier r = (SimpleReifier) g.getReifier();
024: g.close();
025: assertTrue(r.isClosed());
026: }
027:
028: public void testBrokenIndexes() {
029: Graph g = getGraphWith("x R y; x S z");
030: ExtendedIterator it = g.find(Node.ANY, Node.ANY, Node.ANY);
031: it.removeNext();
032: it.removeNext();
033: assertFalse(g.find(node("x"), Node.ANY, Node.ANY).hasNext());
034: assertFalse(g.find(Node.ANY, node("R"), Node.ANY).hasNext());
035: assertFalse(g.find(Node.ANY, Node.ANY, node("y")).hasNext());
036: }
037:
038: public void testBrokenSubject() {
039: Graph g = getGraphWith("x brokenSubject y");
040: ExtendedIterator it = g.find(node("x"), Node.ANY, Node.ANY);
041: it.removeNext();
042: assertFalse(g.find(Node.ANY, Node.ANY, Node.ANY).hasNext());
043: }
044:
045: public void testBrokenPredicate() {
046: Graph g = getGraphWith("x brokenPredicate y");
047: ExtendedIterator it = g.find(Node.ANY, node("brokenPredicate"),
048: Node.ANY);
049: it.removeNext();
050: assertFalse(g.find(Node.ANY, Node.ANY, Node.ANY).hasNext());
051: }
052:
053: public void testBrokenObject() {
054: Graph g = getGraphWith("x brokenObject y");
055: ExtendedIterator it = g.find(Node.ANY, Node.ANY, node("y"));
056: it.removeNext();
057: assertFalse(g.find(Node.ANY, Node.ANY, Node.ANY).hasNext());
058: }
059:
060: public void testSizeAfterRemove() {
061: Graph g = getGraphWith("x p y");
062: ExtendedIterator it = g.find(triple("x ?? ??"));
063: it.removeNext();
064: assertEquals(0, g.size());
065: }
066:
067: public void testUnnecessaryMatches() {
068: Node special = new Node_URI("eg:foo") {
069: public boolean matches(Node s) {
070: fail("Matched called superfluously.");
071: return true;
072: }
073: };
074: Graph g = getGraphWith("x p y");
075: g.add(new Triple(special, special, special));
076: exhaust(g.find(special, Node.ANY, Node.ANY));
077: exhaust(g.find(Node.ANY, special, Node.ANY));
078: exhaust(g.find(Node.ANY, Node.ANY, special));
079: }
080:
081: protected void exhaust(Iterator it) {
082: while (it.hasNext())
083: it.next();
084: }
085: }
086:
087: /*
088: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
089: * All rights reserved.
090: *
091: * Redistribution and use in source and binary forms, with or without
092: * modification, are permitted provided that the following conditions
093: * are met:
094: * 1. Redistributions of source code must retain the above copyright
095: * notice, this list of conditions and the following disclaimer.
096: * 2. Redistributions in binary form must reproduce the above copyright
097: * notice, this list of conditions and the following disclaimer in the
098: * documentation and/or other materials provided with the distribution.
099: * 3. The name of the author may not be used to endorse or promote products
100: * derived from this software without specific prior written permission.
101: *
102: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
103: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
104: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
105: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
106: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
107: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
108: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
109: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
110: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
111: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
112: */
|