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 com.hp.hpl.jena.n3.*;
010: import junit.framework.*;
011:
012: import com.hp.hpl.jena.rdf.model.*;
013: import com.hp.hpl.jena.util.FileManager;
014:
015: /**
016: * @author Andy Seaborne
017: * @version $Id: N3JenaReaderTests.java,v 1.12 2008/01/02 12:06:53 andy_seaborne Exp $
018: */
019: public class N3JenaReaderTests extends N3ExternalTestsCom {
020: static public boolean VERBOSE = false;
021:
022: public N3JenaReaderTests() {
023: this ("n3-reader-tests");
024: }
025:
026: public N3JenaReaderTests(String filename) {
027: super ("N3 Jena Reader tests", filename);
028: }
029:
030: protected void makeTest(String n3File, String resultsFile) {
031: String testName = n3File;
032:
033: if (basedir != null)
034: n3File = basedir + "/" + n3File;
035:
036: if (basedir != null && resultsFile != null
037: && !resultsFile.equals(""))
038: resultsFile = basedir + "/" + resultsFile;
039:
040: addTest(new Test(testName, n3File, resultsFile));
041: }
042:
043: static class Test extends TestCase {
044: RDFReader reader = null;
045: String basename = null;
046: String n3File = null;
047: String resultsFile = null;
048: Model dModel = null;
049: Model rModel = null;
050: Reader rData = null;
051:
052: Test(String testName, String _n3File, String _resultsFile) {
053: super ("N3 Jena Reader test: " + testName);
054: n3File = _n3File;
055: resultsFile = _resultsFile;
056: try {
057:
058: rData = makeReader(new FileInputStream(n3File));
059:
060: // Check the files exist
061: dModel = ModelFactory.createDefaultModel();
062:
063: if (resultsFile != null && !resultsFile.equals("")) {
064: rModel = FileManager.get().loadModel(resultsFile,
065: null);
066: if (rModel == null)
067: System.err
068: .println("Failed to find results file "
069: + resultsFile);
070: }
071:
072: // Manually create a jena reader while not fully integrated into Jena
073: reader = new N3JenaReader();
074: int ind = n3File.lastIndexOf(File.pathSeparatorChar);
075: if (ind == -1)
076: // Not found: maybe UNIX syntax on windows.
077: ind = n3File.lastIndexOf('/');
078: String x = n3File.substring(ind + 1);
079: // Use a fake basename to make this more portable.
080: // The tests results data knows this basename.
081: basename = "file:///base/" + x;
082: //basename = basename.replace('\\', '/') ;
083: } catch (IOException ioEx) {
084: System.err.println("IO Exception: " + ioEx);
085: }
086: }
087:
088: protected void runTest() throws Throwable {
089: reader.read(dModel, rData, basename);
090: if (VERBOSE) {
091: PrintWriter w = makeWriter(System.out);
092: BufferedReader r = makeReader(new FileInputStream(
093: n3File));
094: w.println("+++++++ " + this .getName());
095: for (String s = r.readLine(); s != null; s = r
096: .readLine())
097: w.println(s);
098: w.println("+++++++");
099: dModel.write(w, "N-TRIPLE");
100: w.println("+++++++");
101: w.flush();
102: }
103: if (rModel != null) {
104: if (!dModel.isIsomorphicWith(rModel)) {
105:
106: PrintWriter w = makeWriter(System.out);
107: w.println("+++++++ " + super .getName());
108: w.println("---- Created");
109: dModel.write(w, "N-TRIPLE");
110: w.println("---- Expected ");
111: rModel.write(w, "N-TRIPLE");
112: w.println("+++++++" + super .getName());
113: w.flush();
114: assertTrue("Model compare failed: "
115: + super .getName(), false);
116: }
117: }
118:
119: }
120: }
121:
122: }
123:
124: /*
125: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
126: * All rights reserved.
127: *
128: * Redistribution and use in source and binary forms, with or without
129: * modification, are permitted provided that the following conditions
130: * are met:
131: * 1. Redistributions of source code must retain the above copyright
132: * notice, this list of conditions and the following disclaimer.
133: * 2. Redistributions in binary form must reproduce the above copyright
134: * notice, this list of conditions and the following disclaimer in the
135: * documentation and/or other materials provided with the distribution.
136: * 3. The name of the author may not be used to endorse or promote products
137: * derived from this software without specific prior written permission.
138: *
139: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
140: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
141: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
142: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
143: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
144: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
145: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
146: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
147: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
148: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
149: */
|