KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > test > MetaTestGraph


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: MetaTestGraph.java,v 1.6 2005/02/21 11:52:37 andy_seaborne Exp $
5 */

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 /**
18     MetaTestGraph
19
20     @author kers
21 */

22 public class MetaTestGraph extends AbstractTestGraph
23     {
24     protected final Class JavaDoc graphClass;
25     protected final ReificationStyle style;
26     
27     public MetaTestGraph( Class JavaDoc graphClass, String JavaDoc name, ReificationStyle style )
28         {
29         super( name );
30         this.graphClass = graphClass;
31         this.style = style;
32         }
33         
34     public MetaTestGraph( String JavaDoc 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 JavaDoc testClass, Class JavaDoc 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 JavaDoc testClass, Class JavaDoc graphClass, ReificationStyle style )
50         {
51         TestSuite result = new TestSuite();
52         for (Class JavaDoc 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 JavaDoc testClass, Method [] methods, Class JavaDoc 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 JavaDoc testClass, Class JavaDoc graphClass, String JavaDoc name, ReificationStyle style )
69         {
70         Constructor cons = getConstructor( testClass, new Class JavaDoc[] {Class JavaDoc.class, String JavaDoc.class, ReificationStyle.class} );
71         if (cons == null) throw new JenaException( "cannot find MetaTestGraph constructor" );
72         try { return (TestCase) cons.newInstance( new Object JavaDoc [] {graphClass, name, style} ); }
73         catch (Exception JavaDoc e) { throw new JenaException( e ); }
74         }
75
76     public Graph getGraph()
77         { return getGraph( this, graphClass, style ); }
78         
79     }
80
81 /*
82     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
83     All rights reserved.
84
85     Redistribution and use in source and binary forms, with or without
86     modification, are permitted provided that the following conditions
87     are met:
88
89     1. Redistributions of source code must retain the above copyright
90        notice, this list of conditions and the following disclaimer.
91
92     2. Redistributions in binary form must reproduce the above copyright
93        notice, this list of conditions and the following disclaimer in the
94        documentation and/or other materials provided with the distribution.
95
96     3. The name of the author may not be used to endorse or promote products
97        derived from this software without specific prior written permission.
98
99     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
100     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
101     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
102     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
103     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
104     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
105     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
106     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
107     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
108     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109 */
Popular Tags