1 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 21 public abstract class N3ExternalTestsCom extends TestSuite 22 { 23 static protected final String dirbases[] = {".", "testN3", 25 "testing/N3", 27 "modules/rdf/regression/testN3"} ; 29 30 protected String basedir = null ; 32 protected String testFile ; 33 34 public N3ExternalTestsCom(String testName, String 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 n3File = ((TupleItem)l.get(0)).get() ; 59 String resultsFile = ((TupleItem)l.get(1)).get() ; 60 61 makeTest(n3File, resultsFile) ; 62 } 63 } 64 65 abstract protected void makeTest(String n3File, String resultsFile) ; 66 67 protected String findFile(String fname) 68 { 69 for ( int i = 0 ; i < dirbases.length ; i++ ) 70 { 71 String 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 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 122 | Popular Tags |