1 5 6 package com.hp.hpl.jena.n3.test; 7 8 import java.io.* ; 9 import com.hp.hpl.jena.n3.* ; 10 import junit.framework.* ; 11 12 import com.hp.hpl.jena.rdf.model.* ; 13 import com.hp.hpl.jena.util.FileManager; 14 18 public class N3JenaReaderTests extends N3ExternalTestsCom 19 { 20 static public boolean VERBOSE = false ; 21 22 public N3JenaReaderTests() 23 { 24 this("n3-reader-tests") ; 25 } 26 27 public N3JenaReaderTests(String filename) 28 { 29 super("N3 Jena Reader tests", filename) ; 30 } 31 32 protected void makeTest(String n3File, String resultsFile) 33 { 34 String testName = n3File ; 35 36 if ( basedir != null ) 37 n3File = basedir+"/"+n3File ; 38 39 if ( basedir != null && resultsFile != null && !resultsFile.equals("") ) 40 resultsFile = basedir + "/" + resultsFile ; 41 42 addTest(new Test(testName, n3File, resultsFile)) ; 43 } 44 45 static class Test extends TestCase 46 { 47 RDFReader reader = null ; 48 String basename = null ; 49 String n3File = null ; 50 String resultsFile = null ; 51 Model dModel = null ; 52 Model rModel = null ; 53 Reader rData = null ; 54 55 Test(String testName, String _n3File, String _resultsFile) 56 { 57 super("N3 Jena Reader test: "+testName) ; 58 n3File = _n3File ; 59 resultsFile = _resultsFile ; 60 try { 61 62 rData = makeReader(new FileInputStream(n3File)) ; 63 64 dModel = ModelFactory.createDefaultModel() ; 66 67 if ( resultsFile != null && !resultsFile.equals("") ) 68 { 69 rModel = FileManager.get().loadModel(resultsFile, null) ; 70 if ( rModel == null ) 71 System.err.println("Failed to find results file "+resultsFile) ; 72 } 73 74 reader = new N3JenaReader() ; 76 int ind = n3File.lastIndexOf(File.pathSeparatorChar) ; 77 if ( ind == -1 ) 78 ind = n3File.lastIndexOf('/') ; 80 String x = n3File.substring(ind+1) ; 81 basename = "file:///base/"+x ; 84 } catch (IOException ioEx) 86 { 87 System.err.println("IO Exception: "+ioEx) ; 88 } 89 } 90 91 92 protected void runTest() throws Throwable 93 { 94 reader.read(dModel, rData, basename) ; 95 if ( VERBOSE ) 96 { 97 PrintWriter w = makeWriter(System.out) ; 98 BufferedReader r = makeReader(new FileInputStream(n3File)) ; 99 w.println("+++++++ "+this.getName()) ; 100 for ( String s = r.readLine(); s != null ; s = r.readLine()) 101 w.println(s) ; 102 w.println("+++++++") ; 103 dModel.write(w, "N-TRIPLE") ; 104 w.println("+++++++") ; 105 w.flush() ; 106 } 107 if ( rModel != null ) 108 { 109 if ( ! dModel.isIsomorphicWith(rModel) ) 110 { 111 112 PrintWriter w = makeWriter(System.out) ; 113 w.println("+++++++ "+super.getName()) ; 114 w.println("---- Created") ; 115 dModel.write(w, "N-TRIPLE") ; 116 w.println("---- Expected ") ; 117 rModel.write(w, "N-TRIPLE") ; 118 w.println("+++++++"+super.getName()) ; 119 w.flush() ; 120 assertTrue("Model compare failed: "+super.getName(), false) ; 121 } 122 } 123 124 } 125 } 126 127 } 128 129 155 | Popular Tags |