Author: andy
Date: Tue Jul 22 11:19:30 2014
New Revision: 1612546
URL: http://svn.apache.org/r1612546
Log:
Inaccessible public internet should not cause test failures.
Modified:
jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestReaders.java
Modified:
jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestReaders.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestReaders.java?rev=1612546&r1=1612545&r2=1612546&view=diff
==============================================================================
---
jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestReaders.java
(original)
+++
jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestReaders.java
Tue Jul 22 11:19:30 2014
@@ -24,6 +24,7 @@ import java.net.NoRouteToHostException ;
import java.net.UnknownHostException ;
import org.junit.Assert ;
+import org.slf4j.LoggerFactory ;
import com.hp.hpl.jena.rdf.model.RDFReader ;
import com.hp.hpl.jena.rdf.model.StmtIterator ;
@@ -33,117 +34,84 @@ import com.hp.hpl.jena.shared.NoReaderFo
public class TestReaders extends AbstractModelTestBase
{
- public TestReaders( final TestingModelFactory modelFactory,
- final String name )
- {
- super(modelFactory, name);
- }
+ public TestReaders(final TestingModelFactory modelFactory, final String
name) {
+ super(modelFactory, name) ;
+ }
- public TestReaders()
- {
- this( new TestPackage.PlainModelFactory(), "TestReaders");
- }
-
- /**
- * Test to ensure that the reader is set.
- */
- public void testGetNTripleReader()
- {
- final RDFReader reader = model.getReader("N-TRIPLE");
- Assert.assertNotNull(reader);
- }
+ public TestReaders() {
+ this(new TestPackage.PlainModelFactory(), "TestReaders") ;
+ }
+
+ /**
+ * Test to ensure that the reader is set.
+ */
+ public void testGetNTripleReader() {
+ final RDFReader reader = model.getReader("N-TRIPLE") ;
+ Assert.assertNotNull(reader) ;
+ }
- public void testMissingReader()
- {
- model.setReaderClassName("foobar", "");
- try
- {
- model.getReader("foobar");
- Assert.fail("Should have thrown
NoReaderForLangException");
- }
- catch (final NoReaderForLangException expected)
- {
- // that's what we expect
- }
-
- try
- {
- model.setReaderClassName("foobar",
-
com.hp.hpl.jena.rdf.arp.JenaReader.class.getName());
- final RDFReader reader = model.getReader("foobar");
- Assert.assertTrue("Wrong reader type",
- reader instanceof
com.hp.hpl.jena.rdf.arp.JenaReader);
- }
- finally
- {
- // unset the reader
- model.setReaderClassName("foobar", "");
- }
-
- }
-
- public void testReadLocalNTriple()
- {
- model.read(getInputStream("TestReaders.nt"), "", "N-TRIPLE");
- Assert.assertEquals("Wrong size model", 5, model.size());
- final StmtIterator iter = model.listStatements(null, null,
- "foo\"\\\n\r\tbar");
- Assert.assertTrue("No next statement found", iter.hasNext());
-
- }
-
- public void testReadLocalRDF()
- {
- model.read(getInputStream("TestReaders.rdf"),
"http://example.org/");
- }
-
- public void testReadRemoteNTriple()
- {
- try
- {
-
model.read("http://www.w3.org/2000/10/rdf-tests/rdfcore/"
- +
"rdf-containers-syntax-vs-schema/test001.nt", "N-TRIPLE");
- }
- catch (final JenaException jx)
- {
- if ((jx.getCause() instanceof NoRouteToHostException)
- || (jx.getCause() instanceof
UnknownHostException)
- || (jx.getCause() instanceof
ConnectException)
- || (jx.getCause() instanceof
IOException))
- {
- Assert.fail("Cannot access public internet -
part of test not executed");
- }
- else
- {
- throw jx;
- }
- }
- }
-
- public void testReadRemoteRDF()
- {
-
- try
- {
-
-
model.read("http://www.w3.org/2000/10/rdf-tests/rdfcore/"
- +
"rdf-containers-syntax-vs-schema/test001.rdf");
-
- }
- catch (final JenaException jx)
- {
- if ((jx.getCause() instanceof NoRouteToHostException)
- || (jx.getCause() instanceof
UnknownHostException)
- || (jx.getCause() instanceof
ConnectException)
- || (jx.getCause() instanceof
IOException))
- {
- Assert.fail("Cannot access public internet -
part of test not executed");
- }
- else
- {
- throw jx;
- }
- }
+ public void testMissingReader() {
+ model.setReaderClassName("foobar", "") ;
+ try {
+ model.getReader("foobar") ;
+ Assert.fail("Should have thrown NoReaderForLangException") ;
+ }
+ catch (final NoReaderForLangException expected) {
+ // that's what we expect
+ }
+
+ try {
+ model.setReaderClassName("foobar",
com.hp.hpl.jena.rdf.arp.JenaReader.class.getName()) ;
+ final RDFReader reader = model.getReader("foobar") ;
+ Assert.assertTrue("Wrong reader type", reader instanceof
com.hp.hpl.jena.rdf.arp.JenaReader) ;
+ }
+ finally {
+ // unset the reader
+ model.setReaderClassName("foobar", "") ;
+ }
+ }
+
+ public void testReadLocalNTriple() {
+ model.read(getInputStream("TestReaders.nt"), "", "N-TRIPLE") ;
+ Assert.assertEquals("Wrong size model", 5, model.size()) ;
+ final StmtIterator iter = model.listStatements(null, null,
"foo\"\\\n\r\tbar") ;
+ Assert.assertTrue("No next statement found", iter.hasNext()) ;
+ }
+
+ public void testReadLocalRDF() {
+ model.read(getInputStream("TestReaders.rdf"), "http://example.org/") ;
+ }
+
+ public void testReadRemoteNTriple() {
+ try {
+ model.read("http://www.w3.org/2000/10/rdf-tests/rdfcore/" +
"rdf-containers-syntax-vs-schema/test001.nt",
+ "N-TRIPLE") ;
+ }
+ catch (final JenaException jx) {
+ if ( (jx.getCause() instanceof NoRouteToHostException) ||
(jx.getCause() instanceof UnknownHostException)
+ || (jx.getCause() instanceof ConnectException) ||
(jx.getCause() instanceof IOException) ) {
+ noPublicInternet() ;
+ } else {
+ throw jx ;
+ }
+ }
+ }
+
+ public void testReadRemoteRDF() {
+ try {
+ model.read("http://www.w3.org/2000/10/rdf-tests/rdfcore/" +
"rdf-containers-syntax-vs-schema/test001.rdf") ;
+ }
+ catch (final JenaException jx) {
+ if ( (jx.getCause() instanceof NoRouteToHostException) ||
(jx.getCause() instanceof UnknownHostException)
+ || (jx.getCause() instanceof ConnectException) ||
(jx.getCause() instanceof IOException) ) {
+ noPublicInternet() ;
+ } else {
+ throw jx ;
+ }
+ }
+ }
+ private void noPublicInternet() {
+ LoggerFactory.getLogger(this.getClass()).warn("Cannot access public
internet - part of test not executed");
}
}