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 junit.framework.*;
010:
011: import com.hp.hpl.jena.n3.*;
012: import com.hp.hpl.jena.rdf.model.*;
013:
014: /**
015: * @author Andy Seaborne
016: * @version $Id: N3JenaWriterTests.java,v 1.15 2008/01/02 12:06:53 andy_seaborne Exp $
017: */
018: public class N3JenaWriterTests extends N3ExternalTestsCom {
019: /* JUnit swingUI needed this */
020: static public TestSuite suite() {
021: return new N3JenaWriterTests();
022: }
023:
024: static final String uriBase = "http://host/base/";
025:
026: public N3JenaWriterTests() {
027: this ("n3-writer-tests");
028: }
029:
030: public N3JenaWriterTests(String filename) {
031: super ("N3 Jena Writer tests", filename);
032: }
033:
034: protected void makeTest(String inputFile, String resultsFile) {
035: String testName = inputFile;
036:
037: if (basedir != null)
038: inputFile = basedir + "/" + inputFile;
039:
040: if (basedir != null && resultsFile != null
041: && !resultsFile.equals(""))
042: resultsFile = basedir + "/" + resultsFile;
043:
044: // Run on each of the writers
045: addTest(new Test(testName, inputFile, resultsFile,
046: N3JenaWriter.n3WriterPrettyPrinter));
047: addTest(new Test(testName, inputFile, resultsFile,
048: N3JenaWriter.n3WriterPlain));
049: addTest(new Test(testName, inputFile, resultsFile,
050: N3JenaWriter.n3WriterTriples));
051: }
052:
053: static class Test extends TestCase {
054: String writerName = null;
055: String testName = null;
056: String basename = null;
057: String inputFile = null;
058: String resultsFile = null;
059: Reader data = null;
060:
061: Test(String _testName, String _inputFile, String _resultsFile,
062: String wName) {
063: super ("N3 Jena Writer test: " + _testName + "-" + wName);
064: testName = _testName;
065: inputFile = _inputFile;
066: resultsFile = _resultsFile;
067: writerName = wName;
068: }
069:
070: protected void runTest() throws Throwable {
071: try {
072: data = makeReader(new FileInputStream(inputFile));
073: } catch (IOException ioEx) {
074: fail("File does not exist: " + inputFile);
075: return;
076: }
077:
078: // Test: write model to a string, read it again and see if same/isomorphic
079:
080: Model model_1 = ModelFactory.createDefaultModel();
081: model_1.read(data, uriBase, "N3");
082:
083: StringWriter w = new StringWriter();
084: model_1.write(w, writerName, uriBase);
085: // Check we really are writing different things!
086: //model_1.write(System.out, writerName, uriBase) ;
087: w.close();
088:
089: StringReader r = new StringReader(w.toString());
090: Model model_2 = ModelFactory.createDefaultModel();
091: model_2.read(r, uriBase, "N3");
092:
093: if (!model_1.isIsomorphicWith(model_2)) {
094: System.out.println("#### ---- " + testName
095: + " ------------------------------");
096: System.out.println("#### Model 1 ---- " + testName
097: + " ------------------------------");
098: model_1.write(System.out, "N3");
099: System.out.println("#### Model 2 --- " + testName
100: + " ------------------------------");
101: model_2.write(System.out, "N3");
102: assertTrue("Models don't match: " + testName, false);
103: }
104: }
105: }
106: }
107:
108: /*
109: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
110: * All rights reserved.
111: *
112: * Redistribution and use in source and binary forms, with or without
113: * modification, are permitted provided that the following conditions
114: * are met:
115: * 1. Redistributions of source code must retain the above copyright
116: * notice, this list of conditions and the following disclaimer.
117: * 2. Redistributions in binary form must reproduce the above copyright
118: * notice, this list of conditions and the following disclaimer in the
119: * documentation and/or other materials provided with the distribution.
120: * 3. The name of the author may not be used to endorse or promote products
121: * derived from this software without specific prior written permission.
122: *
123: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
124: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
125: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
126: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
127: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
128: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
129: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
130: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
131: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
132: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
133: */
|