1 6 7 package com.hp.hpl.jena.graph.test; 8 9 import java.lang.reflect.*; 10 11 import junit.framework.*; 12 13 import com.hp.hpl.jena.graph.*; 14 import com.hp.hpl.jena.mem.GraphMem; 15 import com.hp.hpl.jena.shared.*; 16 17 22 public class MetaTestGraph extends AbstractTestGraph 23 { 24 protected final Class graphClass; 25 protected final ReificationStyle style; 26 27 public MetaTestGraph( Class graphClass, String name, ReificationStyle style ) 28 { 29 super( name ); 30 this.graphClass = graphClass; 31 this.style = style; 32 } 33 34 public MetaTestGraph( String name ) 35 { super( name ); graphClass = null; style = null; } 36 37 public static TestSuite suite() 38 { return suite( MetaTestGraph.class, GraphMem.class, ReificationStyle.Minimal ); } 39 40 public static TestSuite suite( Class testClass, Class graphClass ) 41 { 42 TestSuite result = new TestSuite(); 43 result.addTest( suite( testClass, graphClass, ReificationStyle.Minimal ) ); 44 result.addTest( suite( testClass, graphClass, ReificationStyle.Standard ) ); 45 result.addTest( suite( testClass, graphClass, ReificationStyle.Convenient ) ); 46 return result; 47 } 48 49 public static TestSuite suite( Class testClass, Class graphClass, ReificationStyle style ) 50 { 51 TestSuite result = new TestSuite(); 52 for (Class c = testClass; Test.class.isAssignableFrom( c ); c = c.getSuperclass()) 53 { 54 Method [] methods = c.getDeclaredMethods(); 55 addTestMethods( result, testClass, methods, graphClass, style ); 56 } 57 return result; 58 } 59 60 public static void addTestMethods 61 ( TestSuite result, Class testClass, Method [] methods, Class graphClass, ReificationStyle style ) 62 { 63 for (int i = 0; i < methods.length; i += 1) 64 if (isPublicTestMethod( methods[i] )) 65 result.addTest( makeTest( testClass, graphClass, methods[i].getName(), style ) ); 66 } 67 68 public static TestCase makeTest( Class testClass, Class graphClass, String name, ReificationStyle style ) 69 { 70 Constructor cons = getConstructor( testClass, new Class [] {Class .class, String .class, ReificationStyle.class} ); 71 if (cons == null) throw new JenaException( "cannot find MetaTestGraph constructor" ); 72 try { return (TestCase) cons.newInstance( new Object [] {graphClass, name, style} ); } 73 catch (Exception e) { throw new JenaException( e ); } 74 } 75 76 public Graph getGraph() 77 { return getGraph( this, graphClass, style ); } 78 79 } 80 81 | Popular Tags |