001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: TestModelRead.java,v 1.13 2008/01/02 12:04:42 andy_seaborne Exp $
005: */
006: package com.hp.hpl.jena.rdf.model.test;
007:
008: import java.io.IOException;
009: import java.net.ConnectException;
010: import java.net.NoRouteToHostException;
011: import java.net.UnknownHostException;
012:
013: import org.apache.commons.logging.Log;
014: import org.apache.commons.logging.LogFactory;
015:
016: import com.hp.hpl.jena.n3.IRIResolver;
017: import com.hp.hpl.jena.rdf.model.*;
018: import com.hp.hpl.jena.shared.ConfigException;
019: import com.hp.hpl.jena.shared.JenaException;
020:
021: import junit.framework.TestSuite;
022:
023: /**
024: TestModelRead - test that the new model.read operation(s) exist.
025: @author kers
026: */
027: public class TestModelRead extends ModelTestBase {
028: protected static Log logger = LogFactory
029: .getLog(TestModelRead.class);
030:
031: public TestModelRead(String name) {
032: super (name);
033: }
034:
035: public static TestSuite suite() {
036: return new TestSuite(TestModelRead.class);
037: }
038:
039: public void testReturnsSelf() {
040: Model m = ModelFactory.createDefaultModel();
041: assertSame(m, m.read("file:testing/modelReading/empty.n3",
042: "base", "N3"));
043: assertTrue(m.isEmpty());
044: }
045:
046: public void testGRDDLConfigMessage() {
047: Model m = ModelFactory.createDefaultModel();
048: try {
049: m.read("http://www.w3.org/", "GRDDL");
050: // ok.
051: } catch (ConfigException e) {
052: // expected.
053: }
054: }
055:
056: public void testLoadsSimpleModel() {
057: Model expected = ModelFactory.createDefaultModel();
058: Model m = ModelFactory.createDefaultModel();
059: expected.read("file:testing/modelReading/simple.n3", "N3");
060: assertSame(m, m.read("file:testing/modelReading/simple.n3",
061: "base", "N3"));
062: assertIsoModels(expected, m);
063: }
064:
065: /*
066: Suppressed, since the other Model::read(String url) operations apparently
067: don't retry failing URLs as filenames. But the code text remains, so that
068: when-and-if, we have a basis.
069: */
070: // public void testLoadsSimpleModelWithoutProtocol()
071: // {
072: // Model expected = ModelFactory.createDefaultModel();
073: // Model m = ModelFactory.createDefaultModel();
074: // expected.read( "testing/modelReading/simple.n3", "RDF/XML" );
075: // assertSame( m, m.read( "testing/modelReading/simple.n3", "base", "N3" ) );
076: // assertIsoModels( expected, m );
077: // }
078: public void testSimpleLoadImplictBase() {
079: Model mBasedImplicit = ModelFactory.createDefaultModel();
080: String fn = IRIResolver
081: .resolveFileURL("file:testing/modelReading/based.n3");
082: Model wanted = ModelFactory.createDefaultModel().add(
083: resource(fn), property("jms:predicate"),
084: resource("jms:object"));
085: mBasedImplicit.read(fn, "N3");
086: assertIsoModels(wanted, mBasedImplicit);
087: }
088:
089: public void testSimpleLoadExplicitBase() {
090: Model mBasedExplicit = ModelFactory.createDefaultModel();
091: mBasedExplicit.read("file:testing/modelReading/based.n3",
092: "http://example/", "N3");
093: assertIsoModels(
094: modelWithStatements("http://example/ jms:predicate jms:object"),
095: mBasedExplicit);
096: }
097:
098: public void testDefaultLangXML() {
099: Model m = ModelFactory.createDefaultModel();
100: m.read("file:testing/modelReading/plain.rdf", null, null);
101: }
102:
103: public void testContentNegotiation() {
104: Model m = ModelFactory.createDefaultModel();
105: // Model m2 = ModelFactory.createDefaultModel();
106:
107: try {
108: m.read("http://jena.sourceforge.net/test/mime/test1");
109: assertEquals(m.size(), 1);
110: // m2.read("http://xmlns.com/foaf/0.1/");
111: } catch (JenaException jx) {
112: if (jx.getCause() instanceof NoRouteToHostException
113: || jx.getCause() instanceof UnknownHostException
114: || jx.getCause() instanceof ConnectException
115: || jx.getCause() instanceof IOException) {
116: logger
117: .warn("Cannot access public internet - content negotiation test not executed");
118: } else
119: throw jx;
120: }
121: }
122:
123: }
124:
125: /*
126: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All
127: * rights reserved.
128: *
129: * Redistribution and use in source and binary forms, with or without
130: * modification, are permitted provided that the following conditions are met:
131: *
132: * 1. Redistributions of source code must retain the above copyright notice,
133: * this list of conditions and the following disclaimer.
134: *
135: * 2. Redistributions in binary form must reproduce the above copyright notice,
136: * this list of conditions and the following disclaimer in the documentation
137: * and/or other materials provided with the distribution.
138: *
139: * 3. The name of the author may not be used to endorse or promote products
140: * derived from this software without specific prior written permission.
141: *
142: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
143: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
144: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
145: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
146: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
147: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
148: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
149: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
150: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
151: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
152: */
|