001: /*
002: (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: TestReifier.java,v 1.27 2008/01/02 12:05:34 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.test;
008:
009: import java.lang.reflect.Constructor;
010:
011: import com.hp.hpl.jena.graph.*;
012: import com.hp.hpl.jena.graph.impl.GraphBase;
013: import com.hp.hpl.jena.graph.impl.ReifierFragmentsMap;
014: import com.hp.hpl.jena.graph.impl.ReifierTripleMap;
015: import com.hp.hpl.jena.graph.impl.SimpleReifier;
016: import com.hp.hpl.jena.graph.impl.SimpleReifierFragmentsMap;
017: import com.hp.hpl.jena.graph.impl.SimpleReifierTripleMap;
018: import com.hp.hpl.jena.mem.*;
019: import com.hp.hpl.jena.mem.faster.GraphMemFaster;
020: import com.hp.hpl.jena.shared.*;
021: import com.hp.hpl.jena.util.iterator.ExtendedIterator;
022:
023: import junit.framework.*;
024:
025: /**
026: This class tests the reifiers of ordinary GraphMem graphs.
027: @author kers
028: */
029:
030: public class TestReifier extends AbstractTestReifier {
031: public TestReifier(String name) {
032: super (name);
033: graphClass = null;
034: style = null;
035: }
036:
037: protected final Class graphClass;
038: protected final ReificationStyle style;
039:
040: public TestReifier(Class graphClass, String name,
041: ReificationStyle style) {
042: super (name);
043: this .graphClass = graphClass;
044: this .style = style;
045: }
046:
047: public static TestSuite suite() {
048: TestSuite result = new TestSuite();
049: result.addTest(MetaTestGraph.suite(TestReifier.class,
050: GraphMem.class));
051: result.addTest(MetaTestGraph.suite(TestReifier.class,
052: GraphMemFaster.class));
053: return result;
054: }
055:
056: public Graph getGraph() {
057: return getGraph(style);
058: }
059:
060: public Graph getGraph(ReificationStyle style) {
061: try {
062: Constructor cons = getConstructor(graphClass,
063: new Class[] { ReificationStyle.class });
064: if (cons != null)
065: return (Graph) cons.newInstance(new Object[] { style });
066: Constructor cons2 = getConstructor(graphClass, new Class[] {
067: this .getClass(), ReificationStyle.class });
068: if (cons2 != null)
069: return (Graph) cons2.newInstance(new Object[] { this ,
070: style });
071: throw new JenaException(
072: "no suitable graph constructor found for "
073: + graphClass);
074: } catch (RuntimeException e) {
075: throw e;
076: } catch (Exception e) {
077: throw new JenaException(e);
078: }
079: }
080:
081: public void testExtendedConstructorExists() {
082: GraphBase parent = new GraphBase() {
083:
084: public ExtendedIterator graphBaseFind(TripleMatch m) {
085: // TODO Auto-generated method stub
086: return null;
087: }
088: };
089: ReifierTripleMap tm = new SimpleReifierTripleMap();
090: ReifierFragmentsMap fm = new SimpleReifierFragmentsMap();
091: SimpleReifier sr = new SimpleReifier(parent, tm, fm,
092: ReificationStyle.Minimal);
093: }
094: }
095:
096: /*
097: (c) Copyright 2002, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
098: All rights reserved.
099:
100: Redistribution and use in source and binary forms, with or without
101: modification, are permitted provided that the following conditions
102: are met:
103:
104: 1. Redistributions of source code must retain the above copyright
105: notice, this list of conditions and the following disclaimer.
106:
107: 2. Redistributions in binary form must reproduce the above copyright
108: notice, this list of conditions and the following disclaimer in the
109: documentation and/or other materials provided with the distribution.
110:
111: 3. The name of the author may not be used to endorse or promote products
112: derived from this software without specific prior written permission.
113:
114: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
115: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
116: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
117: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
118: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
119: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
120: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
121: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
122: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
123: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
124: */
|