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