1 5 6 package com.hp.hpl.jena.n3.test ; 7 8 import java.io.* ; 9 import junit.framework.* ; 10 11 import com.hp.hpl.jena.n3.* ; 12 import com.hp.hpl.jena.rdf.model.*; 13 14 18 public class N3JenaWriterTests extends N3ExternalTestsCom 19 { 20 21 static public TestSuite suite() { 22 return new N3JenaWriterTests() ; 23 } 24 25 static final String uriBase = "http://host/base/" ; 26 27 public N3JenaWriterTests() 28 { 29 this("n3-writer-tests") ; 30 } 31 32 public N3JenaWriterTests(String filename) 33 { 34 super("N3 Jena Writer tests", filename) ; 35 } 36 37 38 protected void makeTest(String inputFile, String resultsFile) 39 { 40 String testName = inputFile ; 41 42 if ( basedir != null ) 43 inputFile = basedir+"/"+inputFile ; 44 45 if ( basedir != null && resultsFile != null && !resultsFile.equals("") ) 46 resultsFile = basedir + "/" + resultsFile ; 47 48 addTest(new Test(testName, inputFile, resultsFile, 50 N3JenaWriter.n3WriterPrettyPrinter)) ; 51 addTest(new Test(testName, inputFile, resultsFile, 52 N3JenaWriter.n3WriterPlain)) ; 53 addTest(new Test(testName, inputFile, resultsFile, 54 N3JenaWriter.n3WriterTriples)) ; 55 } 56 57 58 static class Test extends TestCase 59 { 60 String writerName = null ; 61 String testName = null ; 62 String basename = null ; 63 String inputFile = null ; 64 String resultsFile = null ; 65 Reader data = null ; 66 67 68 Test(String _testName, String _inputFile, String _resultsFile, String wName) 69 { 70 super("N3 Jena Writer test: "+_testName+"-"+wName) ; 71 testName = _testName ; 72 inputFile = _inputFile ; 73 resultsFile = _resultsFile ; 74 writerName = wName ; 75 } 76 77 protected void runTest() throws Throwable 78 { 79 try { 80 data = makeReader(new FileInputStream(inputFile)) ; 81 } catch (IOException ioEx) 82 { 83 fail("File does not exist: "+inputFile) ; 84 return ; 85 } 86 87 89 Model model_1 = ModelFactory.createDefaultModel() ; 90 model_1.read(data, uriBase, "N3") ; 91 92 StringWriter w = new StringWriter() ; 93 model_1.write(w, writerName, uriBase) ; 94 w.close() ; 97 98 StringReader r = new StringReader(w.toString()) ; 99 Model model_2 = ModelFactory.createDefaultModel() ; 100 model_2.read(r, uriBase, "N3") ; 101 102 if ( ! model_1.isIsomorphicWith(model_2) ) 103 { 104 System.out.println("#### ---- "+testName+" ------------------------------") ; 105 System.out.println("#### Model 1 ---- "+testName+" ------------------------------") ; 106 model_1.write(System.out, "N3") ; 107 System.out.println("#### Model 2 --- "+testName+" ------------------------------") ; 108 model_2.write(System.out, "N3") ; 109 assertTrue("Models don't match: "+testName, false) ; 110 } 111 } 112 } 113 } 114 115 116 142 | Popular Tags |