001: /*
002: (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestGraph.java,v 1.30 2008/01/02 12:05:34 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.test;
008:
009: /**
010: Tests that check GraphMem and WrappedGraph for correctness against the Graph
011: and reifier test suites.
012:
013: @author kers
014: */
015:
016: import com.hp.hpl.jena.mem.*;
017: import com.hp.hpl.jena.shared.ReificationStyle;
018: import com.hp.hpl.jena.util.CollectionFactory;
019: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
020: import com.hp.hpl.jena.graph.*;
021: import com.hp.hpl.jena.graph.impl.*;
022:
023: import java.util.*;
024:
025: import junit.framework.*;
026:
027: public class TestGraph extends GraphTestBase {
028: public TestGraph(String name) {
029: super (name);
030: }
031:
032: /**
033: Answer a test suite that runs the Graph and Reifier tests on GraphMem and on
034: WrappedGraphMem, the latter standing in for testing WrappedGraph.
035: */
036: public static TestSuite suite() {
037: TestSuite result = new TestSuite(TestGraph.class);
038: result.addTest(suite(MetaTestGraph.class, GraphMem.class));
039: result.addTest(suite(TestReifier.class, GraphMem.class));
040: result.addTest(suite(MetaTestGraph.class, SmallGraphMem.class));
041: result.addTest(suite(TestReifier.class, SmallGraphMem.class));
042: result
043: .addTest(suite(MetaTestGraph.class,
044: WrappedGraphMem.class));
045: result.addTest(suite(TestReifier.class, WrappedGraphMem.class));
046: return result;
047: }
048:
049: public static TestSuite suite(Class classWithTests, Class graphClass) {
050: return MetaTestGraph.suite(classWithTests, graphClass);
051: }
052:
053: /**
054: Trivial [incomplete] test that a Wrapped graph pokes through to the underlying
055: graph. Really want something using mock classes. Will think about it.
056: */
057: public void testWrappedSame() {
058: Graph m = Factory.createGraphMem();
059: Graph w = new WrappedGraph(m);
060: graphAdd(m, "a trumps b; c eats d");
061: assertIsomorphic(m, w);
062: graphAdd(w, "i write this; you read that");
063: assertIsomorphic(w, m);
064: }
065:
066: /**
067: Class to provide a constructor that produces a wrapper round a GraphMem.
068: @author kers
069: */
070: public static class WrappedGraphMem extends WrappedGraph {
071: public WrappedGraphMem(ReificationStyle style) {
072: super (Factory.createGraphMem(style));
073: }
074: }
075:
076: public void testListSubjectsDoesntUseFind() {
077: final boolean[] called = { false };
078:
079: Graph g = Factory.createGraphMem();
080:
081: ExtendedIterator subjects = g.queryHandler().subjectsFor(null,
082: null);
083: Set s = CollectionFactory.createHashedSet();
084: while (subjects.hasNext())
085: s.add(subjects.next());
086: assertFalse("find should not have been called", called[0]);
087: }
088:
089: public void testListPredicatesDoesntUseFind() {
090: final boolean[] called = { false };
091:
092: Graph g = Factory.createGraphMem();
093:
094: ExtendedIterator predicates = g.queryHandler().predicatesFor(
095: null, null);
096: Set s = CollectionFactory.createHashedSet();
097: while (predicates.hasNext())
098: s.add(predicates.next());
099: assertFalse("find should not have been called", called[0]);
100: }
101:
102: public void testListObjectsDoesntUseFind() {
103: final boolean[] called = { false };
104:
105: Graph g = Factory.createGraphMem();
106:
107: ExtendedIterator subjects = g.queryHandler().objectsFor(null,
108: null);
109: Set s = CollectionFactory.createHashedSet();
110: while (subjects.hasNext())
111: s.add(subjects.next());
112: assertFalse("find should not have been called", called[0]);
113: }
114: }
115:
116: /*
117: (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
118: All rights reserved.
119:
120: Redistribution and use in source and binary forms, with or without
121: modification, are permitted provided that the following conditions
122: are met:
123:
124: 1. Redistributions of source code must retain the above copyright
125: notice, this list of conditions and the following disclaimer.
126:
127: 2. Redistributions in binary form must reproduce the above copyright
128: notice, this list of conditions and the following disclaimer in the
129: documentation and/or other materials provided with the distribution.
130:
131: 3. The name of the author may not be used to endorse or promote products
132: derived from this software without specific prior written permission.
133:
134: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
135: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
136: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
137: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
138: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
139: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
140: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
141: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
142: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
143: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
144: */
|