001: /*
002: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * [See end of file]
004: */
005:
006: package com.hp.hpl.jena.n3.test;
007:
008: import java.io.*;
009: import java.util.*;
010: import junit.framework.*;
011:
012: import com.hp.hpl.jena.shared.*;
013: import com.hp.hpl.jena.util.tuple.*;
014: import com.hp.hpl.jena.util.FileUtils;
015:
016: /**
017: * @author Andy Seaborne
018: * @version $Id: N3ExternalTestsCom.java,v 1.15 2008/01/02 12:06:52 andy_seaborne Exp $
019: */
020: public abstract class N3ExternalTestsCom extends TestSuite {
021: // List of places
022: static protected final String dirbases[] = { ".", "testN3",
023: // Jena2: correct location
024: "testing/N3", };
025:
026: // Record where we find the file in the constructor
027: protected String basedir = null;
028: protected String testFile;
029:
030: public N3ExternalTestsCom(String testName, String filename) {
031: super (testName);
032: testFile = findFile(filename);
033: if (testFile == null)
034: throw new JenaException("No such file: " + filename);
035: TupleSet tests = null;
036: try {
037: Reader r = new BufferedReader(new FileReader(testFile));
038: tests = new TupleSet(r);
039: } catch (IOException ioEx) {
040: System.err.println("IO exception: " + ioEx);
041: return;
042: }
043:
044: for (; tests.hasNext();) {
045: List l = (List) tests.next();
046: if (l.size() != 2) {
047: System.err
048: .println("Error in N3 test configuration file: "
049: + filename
050: + ": length of an entry is "
051: + l.size());
052: return;
053: }
054: String n3File = ((TupleItem) l.get(0)).get();
055: String resultsFile = ((TupleItem) l.get(1)).get();
056:
057: makeTest(n3File, resultsFile);
058: }
059: }
060:
061: abstract protected void makeTest(String n3File, String resultsFile);
062:
063: protected String findFile(String fname) {
064: for (int i = 0; i < dirbases.length; i++) {
065: String maybeFile = dirbases[i] + "/" + fname;
066: File f = new File(maybeFile);
067: if (f.exists()) {
068: basedir = dirbases[i];
069: return f.getAbsolutePath();
070: }
071: }
072: return null;
073: }
074:
075: // Utilities.
076:
077: static protected PrintWriter makeWriter(OutputStream out) {
078: return FileUtils.asPrintWriterUTF8(out);
079: }
080:
081: static protected BufferedReader makeReader(InputStream in) {
082: return new BufferedReader(FileUtils.asUTF8(in));
083: }
084: }
085:
086: /*
087: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
088: * All rights reserved.
089: *
090: * Redistribution and use in source and binary forms, with or without
091: * modification, are permitted provided that the following conditions
092: * are met:
093: * 1. Redistributions of source code must retain the above copyright
094: * notice, this list of conditions and the following disclaimer.
095: * 2. Redistributions in binary form must reproduce the above copyright
096: * notice, this list of conditions and the following disclaimer in the
097: * documentation and/or other materials provided with the distribution.
098: * 3. The name of the author may not be used to endorse or promote products
099: * derived from this software without specific prior written permission.
100: *
101: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
102: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
103: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
104: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
105: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
106: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
107: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
108: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
109: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
110: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
111: */
|