001: /*
002: * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: * 1. Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * 3. The name of the author may not be used to endorse or promote products
014: * derived from this software without specific prior written permission.
015:
016: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026: *
027: * $Id: testReaderInterface.java,v 1.18 2008/01/02 12:07:04 andy_seaborne Exp $
028: */
029:
030: package com.hp.hpl.jena.regression;
031:
032: import com.hp.hpl.jena.rdf.model.*;
033: import com.hp.hpl.jena.rdf.model.impl.*;
034:
035: import java.net.*;
036: import java.io.*;
037:
038: import com.hp.hpl.jena.shared.*;
039:
040: import org.apache.commons.logging.Log;
041: import org.apache.commons.logging.LogFactory;
042:
043: /**
044: *
045: * @author bwm
046: * @version $Revision: 1.18 $
047: */
048: public class testReaderInterface extends Object {
049:
050: protected static void doTest(Model m1) {
051: (new testReaderInterface()).test(m1);
052: }
053:
054: protected static Log logger = LogFactory
055: .getLog(testReaderInterface.class);
056:
057: void test(Model m1) {
058:
059: String test = "testReaderInterface";
060: String filebase = "testing/regression/" + test + "/";
061: // System.out.println("Beginning " + test);
062: int n = 0;
063: try {
064: n++;
065: RDFReader reader = m1.getReader();
066:
067: /*
068: if (! (reader instanceof com.hp.hpl.jena.rdf.arp.JenaReader ))
069: error(test, n);
070:
071: n++; reader = m1.getReader("RDF/XML");
072: if (! (reader instanceof com.hp.hpl.jena.rdf.arp.JenaReader ))
073: error(test, n);
074: */
075:
076: n++;
077: reader = m1.getReader("N-TRIPLE");
078: if (!(reader instanceof NTripleReader))
079: error(test, n);
080:
081: n++;
082: try {
083: m1.setReaderClassName("foobar", "");
084: reader = m1.getReader("foobar");
085: error(test, n);
086: } catch (NoReaderForLangException jx) {
087: // that's what we expect
088: }
089:
090: n++;
091: m1.setReaderClassName("foobar",
092: com.hp.hpl.jena.rdf.arp.JenaReader.class.getName());
093: reader = m1.getReader("foobar");
094: if (!(reader instanceof com.hp.hpl.jena.rdf.arp.JenaReader))
095: error(test, n);
096:
097: try {
098:
099: n++;
100: m1
101: .read("http://www.w3.org/2000/10/rdf-tests/rdfcore/"
102: + "rdf-containers-syntax-vs-schema/test001.rdf");
103:
104: n++;
105: m1.read("http://www.w3.org/2000/10/rdf-tests/rdfcore/"
106: + "rdf-containers-syntax-vs-schema/test001.nt",
107: "N-TRIPLE");
108: } catch (JenaException jx) {
109: if (jx.getCause() instanceof NoRouteToHostException
110: || jx.getCause() instanceof UnknownHostException
111: || jx.getCause() instanceof ConnectException
112: || jx.getCause() instanceof IOException) {
113: logger
114: .warn("Cannot access public internet - part of test not executed");
115: } else
116: throw jx;
117: }
118:
119: n++;
120: m1.read(ResourceReader.getInputStream(filebase + "1.rdf"),
121: "http://example.org/");
122:
123: n++;
124: m1.read(ResourceReader.getInputStream(filebase + "2.nt"),
125: "", "N-TRIPLE");
126:
127: } catch (Exception e) {
128: inError = true;
129: logger.error(" test " + test + "[" + n + "]", e);
130: }
131: // System.out.println("End of " + test);
132: }
133:
134: private boolean inError = false;
135:
136: protected void error(String test, int n) {
137: System.out.println(test + ": failed test "
138: + Integer.toString(n));
139: inError = true;
140: }
141:
142: public boolean getErrors() {
143: return inError;
144: }
145:
146: }
|