KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > arp > test > ARPTests


1 /*
2  * (c) Copyright 2001, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27 *
28  * ARPTests.java
29  *
30  * Created on September 18, 2001, 7:50 PM
31  */

32
33 package com.hp.hpl.jena.rdf.arp.test;
34 import junit.framework.TestSuite;
35 import junit.framework.Test;
36 import java.io.*;
37 import java.util.*;
38
39 import com.hp.hpl.jena.shared.wg.*;
40 /**
41  * The JUnit test suite for ARP.
42  *
43  * @author jjc
44
45  */

46 public class ARPTests extends java.lang.Object JavaDoc {
47     /**
48      * Setting this field to true uses the tests found
49      * on the W3C web site.
50      * The default value false uses a cached corrected
51      * copy of the tests.
52      */

53     static public boolean internet = false;
54     static URI wgTestDir =
55         URI.create("http://www.w3.org/2000/10/rdf-tests/rdfcore/");
56     static URI arpTestDir =
57         URI.create("http://jcarroll.hpl.hp.com/arp-tests/");
58     /** Creates new ARPTests */
59     static public Test suite() {
60         TestSuite s = new TestSuite("ARP");
61         if (internet) {
62             s.addTest(NTripleTestSuite.suite(wgTestDir, wgTestDir, "WG Parser Tests"));
63         } else {
64             s.addTest(WGTestSuite.suite(wgTestDir, "wg",
65             // URI.create(
66
// "file://src/com/hp/hpl/jena/rdf/arp/test/data/wg/"),
67
"WG Parser Tests"));
68             s.addTest(WGTestSuite.suite(arpTestDir, "arp",
69             // URI.create(
70
// "file://src/com/hp/hpl/jena/rdf/arp/test/data/arp-bugs/"),
71
"ARP Tests"));
72             s.addTest(NTripleTestSuite.suite(wgTestDir, "wg",
73             // URI.create(
74
// "file://src/com/hp/hpl/jena/rdf/arp/test/data/wg/"),
75
"NTriple WG Tests"));
76         }
77         return s;
78     }
79     static int cnt = 0;
80     static String JavaDoc toJava(Test s,PrintWriter pw, String JavaDoc wgparent) {
81         String JavaDoc name = "test"+cnt++;
82         if ( s instanceof TestSuite ) {
83             TestSuite ts = (TestSuite)s;
84             if ( s instanceof WGTestSuite ) {
85             pw.println("WGTestSuite "+name + " = " + ((WGTestSuite)s).createMe+";");
86              wgparent = name;
87             } else {
88             pw.println("TestSuite "+name + " = new TestSuite(\""+ts.getName()+"\");");
89             }
90             Enumeration ee = ts.tests();
91             while ( ee.hasMoreElements() ) {
92                 Test tt = (Test)ee.nextElement();
93                 if ( tt == null )
94                    continue;
95                 String JavaDoc sub = toJava(tt,pw ,wgparent);
96                 pw.println(name+".addTest("+sub+");");
97             }
98         }
99         else if ( s instanceof WGTestSuite.Test ) {
100             String JavaDoc className = s.getClass().getName();
101             String JavaDoc localPart = className.substring(className.lastIndexOf('$')+1);
102             pw.println("Test "+ name + " = " + wgparent +".create" + localPart +"("
103 + ((WGTestSuite.Test)s).createMe() + ");");
104         }
105         else {
106             pw.println(name + " is of class " + s.getClass().getName());
107         }
108             
109            
110         return name;
111     }
112     static public void main(String JavaDoc args[]) throws IOException {
113         Test ts = suite();
114         PrintWriter pw = new PrintWriter(new FileWriter("src/com/hp/hpl/jena/rdf/arp/test/TestPackage.java"));
115         pw.println("/*");
116         pw.println(" * (c) Copyright 2002-2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP") ;
117         pw.println(" * All rights reserved.");
118         pw.println(" *");
119         pw.println(" * Redistribution and use in source and binary forms, with or without");
120         pw.println(" * modification, are permitted provided that the following conditions");
121         pw.println(" * are met:");
122         pw.println(" * 1. Redistributions of source code must retain the above copyright");
123         pw.println(" * notice, this list of conditions and the following disclaimer.");
124         pw.println(" * 2. Redistributions in binary form must reproduce the above copyright");
125         pw.println(" * notice, this list of conditions and the following disclaimer in the");
126         pw.println(" * documentation and/or other materials provided with the distribution.");
127         pw.println(" * 3. The name of the author may not be used to endorse or promote products");
128         pw.println(" * derived from this software without specific prior written permission.");
129         pw.println("");
130         pw.println(" * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR");
131         pw.println(" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES");
132         pw.println(" * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.");
133         pw.println(" * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,");
134         pw.println(" * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT");
135         pw.println(" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,");
136         pw.println(" * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY");
137         pw.println(" * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT");
138         pw.println(" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF");
139         pw.println(" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.");
140         pw.println(" *");
141         pw.println(" */");
142         
143         pw.println("package com.hp.hpl.jena.rdf.arp.test;");
144         pw.println("import junit.framework.TestSuite;");
145         pw.println("import junit.framework.Test;");
146             pw.println("import com.hp.hpl.jena.shared.wg.*;");
147         pw.println("public class TestPackage{");
148         pw.println("static public Test suite() {");
149         String JavaDoc tsname = toJava(ts, pw, "xx");
150         pw.println("return " + tsname+ ";");
151         pw.println("} }");
152         pw.println("");
153         pw.flush();
154     }
155
156 }
Popular Tags