KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > n3 > test > N3ExternalTestsCom


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.n3.test;
7
8 import java.io.* ;
9 import java.util.* ;
10 import junit.framework.* ;
11
12 import com.hp.hpl.jena.shared.*;
13 import com.hp.hpl.jena.util.tuple.* ;
14 import com.hp.hpl.jena.util.FileUtils;
15
16
17 /**
18  * @author Andy Seaborne
19  * @version $Id: N3ExternalTestsCom.java,v 1.11 2005/02/21 12:04:08 andy_seaborne Exp $
20  */

21 public abstract class N3ExternalTestsCom extends TestSuite
22 {
23     // List of places
24
static protected final String JavaDoc dirbases[] = {".", "testN3",
25                                                 // Jena2: correct location
26
"testing/N3",
27                                                 // Jena1: correct location
28
"modules/rdf/regression/testN3"} ;
29     
30     // Record where we find the file in the constructor
31
protected String JavaDoc basedir = null ;
32     protected String JavaDoc testFile ;
33     
34     public N3ExternalTestsCom(String JavaDoc testName, String JavaDoc filename)
35     {
36         super(testName) ;
37         testFile = findFile(filename) ;
38         if ( testFile == null )
39             throw new JenaException("No such file: "+filename) ;
40         TupleSet tests = null ;
41         try {
42             Reader r = new BufferedReader(new FileReader(testFile)) ;
43             tests = new TupleSet(r) ;
44         } catch (IOException ioEx)
45         {
46             System.err.println("IO exception: "+ioEx) ;
47             return ;
48         }
49         
50         for ( ; tests.hasNext() ; )
51         {
52             List l = (List)tests.next() ;
53             if ( l.size() != 2 )
54             {
55                 System.err.println("Error in N3 test configuration file: "+filename+": length of an entry is "+l.size()) ;
56                 return ;
57             }
58             String JavaDoc n3File = ((TupleItem)l.get(0)).get() ;
59             String JavaDoc resultsFile = ((TupleItem)l.get(1)).get() ;
60
61             makeTest(n3File, resultsFile) ;
62         }
63     }
64
65     abstract protected void makeTest(String JavaDoc n3File, String JavaDoc resultsFile) ;
66     
67     protected String JavaDoc findFile(String JavaDoc fname)
68     {
69         for ( int i = 0 ; i < dirbases.length ; i++ )
70         {
71             String JavaDoc maybeFile = dirbases[i]+"/"+fname ;
72             File f = new File(maybeFile) ;
73             if ( f.exists() )
74             {
75                 basedir = dirbases[i] ;
76                 return f.getAbsolutePath() ;
77             }
78         }
79         return null ;
80     }
81
82     // Utilities.
83

84     static protected PrintWriter makeWriter(OutputStream out)
85     {
86         return FileUtils.asPrintWriterUTF8(out) ;
87     }
88
89     static protected BufferedReader makeReader(InputStream in)
90     {
91         return new BufferedReader(FileUtils.asUTF8(in)) ;
92     }
93 }
94
95
96 /*
97  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
98  * All rights reserved.
99  *
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  * 1. Redistributions of source code must retain the above copyright
104  * notice, this list of conditions and the following disclaimer.
105  * 2. Redistributions in binary form must reproduce the above copyright
106  * notice, this list of conditions and the following disclaimer in the
107  * documentation and/or other materials provided with the distribution.
108  * 3. The name of the author may not be used to endorse or promote products
109  * derived from this software without specific prior written permission.
110  *
111  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
112  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
113  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
114  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
115  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
116  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
117  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
118  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
119  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
120  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
121  */

122
Popular Tags