Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9F8E6200B92 for ; Wed, 28 Sep 2016 15:05:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9E564160AB4; Wed, 28 Sep 2016 13:05:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 453F3160AD4 for ; Wed, 28 Sep 2016 15:05:41 +0200 (CEST) Received: (qmail 71989 invoked by uid 500); 28 Sep 2016 13:05:40 -0000 Mailing-List: contact commits-help@commonsrdf.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commonsrdf.incubator.apache.org Delivered-To: mailing list commits@commonsrdf.incubator.apache.org Received: (qmail 71980 invoked by uid 99); 28 Sep 2016 13:05:40 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Sep 2016 13:05:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 030811A5FC9 for ; Wed, 28 Sep 2016 13:05:40 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id L1I3pz2cTudQ for ; Wed, 28 Sep 2016 13:05:37 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 7798E5FDEE for ; Wed, 28 Sep 2016 13:05:35 +0000 (UTC) Received: (qmail 71422 invoked by uid 99); 28 Sep 2016 13:05:34 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Sep 2016 13:05:34 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9FFF6E0991; Wed, 28 Sep 2016 13:05:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stain@apache.org To: commits@commonsrdf.incubator.apache.org Date: Wed, 28 Sep 2016 13:05:47 -0000 Message-Id: <1899307c1b4c494b86113e46b1147a9b@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [14/16] incubator-commonsrdf git commit: AbstractRDFParserTest moved to ...experimental archived-at: Wed, 28 Sep 2016 13:05:42 -0000 AbstractRDFParserTest moved to ...experimental Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/74196bdd Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/74196bdd Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/74196bdd Branch: refs/heads/jena-jsonld-rdf4j-integration Commit: 74196bdd363983648860e98e59888ce552e95933 Parents: c3c1719 Author: Stian Soiland-Reyes Authored: Tue Sep 27 18:46:25 2016 +0100 Committer: Stian Soiland-Reyes Committed: Tue Sep 27 18:46:25 2016 +0100 ---------------------------------------------------------------------- .../simple/AbstractRDFParserBuilderTest.java | 254 ------------------ .../experimental/AbstractRDFParserTest.java | 256 +++++++++++++++++++ 2 files changed, 256 insertions(+), 254 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/74196bdd/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java deleted file mode 100644 index f115e94..0000000 --- a/simple/src/test/java/org/apache/commons/rdf/simple/AbstractRDFParserBuilderTest.java +++ /dev/null @@ -1,254 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.rdf.simple; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.rdf.api.Graph; -import org.apache.commons.rdf.api.IRI; -import org.apache.commons.rdf.api.Literal; -import org.apache.commons.rdf.api.RDFSyntax; -import org.apache.commons.rdf.api.RDFTerm; -import org.apache.commons.rdf.api.RDFTermFactory; -import org.apache.commons.rdf.api.Triple; -import org.apache.commons.rdf.experimental.RDFParser; -import org.apache.commons.rdf.simple.experimental.AbstractRDFParser; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class AbstractRDFParserBuilderTest { - - private RDFTermFactory factory = new SimpleRDFTermFactory(); - - private DummyRDFParserBuilder dummyParser = new DummyRDFParserBuilder(); - private Path testNt; - private Path testTtl; - private Path testXml; - - @Before - public void createTempFile() throws IOException { - testNt = Files.createTempFile("test", ".nt"); - testTtl = Files.createTempFile("test", ".ttl"); - testXml = Files.createTempFile("test", ".xml"); - - // No need to populate the files as the dummy parser - // doesn't actually read anything - } - - @After - public void deleteTempFiles() throws IOException { - Files.deleteIfExists(testNt); - Files.deleteIfExists(testTtl); - Files.deleteIfExists(testXml); - } - - @Test - public void guessRDFSyntax() throws Exception { - assertEquals(RDFSyntax.NTRIPLES, AbstractRDFParser.guessRDFSyntax(testNt).get()); - assertEquals(RDFSyntax.TURTLE, AbstractRDFParser.guessRDFSyntax(testTtl).get()); - assertFalse(AbstractRDFParser.guessRDFSyntax(testXml).isPresent()); - } - - private void checkGraph(Graph g) throws Exception { - assertTrue(g.size() > 0); - IRI greeting = factory.createIRI("http://example.com/greeting"); - // Should only have parsed once! - assertEquals(1, g.getTriples(null, greeting, null).count()); - Triple triple = g.getTriples(null, greeting, null).findAny().get(); - assertTrue(triple.getSubject() instanceof IRI); - IRI parsing = (IRI) triple.getSubject(); - assertTrue(parsing.getIRIString().startsWith("urn:uuid:")); - - assertEquals("http://example.com/greeting", triple.getPredicate().getIRIString()); - - assertTrue(triple.getObject() instanceof Literal); - Literal literal = (Literal) triple.getObject(); - assertEquals("Hello world", literal.getLexicalForm()); - assertFalse(literal.getLanguageTag().isPresent()); - assertEquals(Types.XSD_STRING, literal.getDatatype()); - - // Check uniqueness of properties that are always present - assertEquals(1, - g.getTriples(null, factory.createIRI("http://example.com/source"), null).count()); - - // Check optional properties that are unique - assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/base"), null).count()); - assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/contentType"), null).count()); - assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/contentTypeSyntax"), null).count()); - } - - @Test - public void parseFile() throws Exception { - Graph g = factory.createGraph(); - RDFParser parser = dummyParser.source(testNt).target(g); - parser.parse().get(5, TimeUnit.SECONDS); - checkGraph(g); - // FIXME: this could potentially break if the equivalent of /tmp includes - // international characters - assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source")); - // Should be set to the file path - assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base")); - - // Should NOT have guessed the content type - assertNull(firstPredicate(g, "contentType")); - assertNull(firstPredicate(g, "contentTypeSyntax")); - } - - - @Test - public void parseNoSource() throws Exception { - thrown.expect(IllegalStateException.class); - dummyParser.parse(); - } - - @Test - public void parseBaseAndContentTypeNoSource() throws Exception { - // Can set the other options, even without source() - IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf"); - RDFParser parser = dummyParser.base(base).contentType(RDFSyntax.RDFXML); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("No source has been set"); - // but .parse() should fail - parser.parse(); - } - - @Test - public void parseFileMissing() throws Exception { - Files.delete(testNt); - // This should not fail yet - RDFParser parser = dummyParser.source(testNt); - // but here: - thrown.expect(IOException.class); - parser.parse(); - } - - - @Test - public void parseFileContentType() throws Exception { - Graph g = factory.createGraph(); - RDFParser parser = dummyParser - .source(testNt) - .contentType(RDFSyntax.NTRIPLES) - .target(g); - parser.parse().get(5, TimeUnit.SECONDS); - checkGraph(g); - // FIXME: this could potentially break if the equivalent of /tmp includes - // international characters - assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source")); - assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base")); - assertEquals("\"NTRIPLES\"", firstPredicate(g, "contentTypeSyntax")); - assertEquals("\"application/n-triples\"", firstPredicate(g, "contentType")); - } - - private String firstPredicate(Graph g, String pred) { - return g.getTriples(null, factory.createIRI("http://example.com/" + pred), null) - .map(Triple::getObject).map(RDFTerm::ntriplesString).findAny().orElse(null); - } - - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void parseInputStreamFailsIfBaseMissing() throws Exception { - InputStream inputStream = new ByteArrayInputStream(new byte[0]); - // Should not fail at this point - RDFParser parser = dummyParser.source(inputStream); - // but here: - thrown.expect(IllegalStateException.class); - thrown.expectMessage("base iri required for inputstream source"); - parser.parse(); - } - - @Test - public void parseInputStreamWithBase() throws Exception { - InputStream inputStream = new ByteArrayInputStream(new byte[0]); - IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf"); - Graph g = factory.createGraph(); - RDFParser parser = dummyParser.source(inputStream).base(base).target(g); - parser.parse().get(5, TimeUnit.SECONDS); - checkGraph(g); - assertEquals("", firstPredicate(g, "base")); - // in our particular debug output, - // bnode source indicates InputStream - assertTrue(firstPredicate(g, "source").startsWith("_:")); - assertNull(firstPredicate(g, "contentType")); - assertNull(firstPredicate(g, "contentTypeSyntax")); - } - - @Test - public void parseInputStreamWithNQuads() throws Exception { - InputStream inputStream = new ByteArrayInputStream(new byte[0]); - Graph g = factory.createGraph(); - RDFParser parser = dummyParser.source(inputStream).contentType(RDFSyntax.NQUADS).target(g); - parser.parse().get(5, TimeUnit.SECONDS); - checkGraph(g); - assertNull(firstPredicate(g, "base")); - // in our particular debug output, - // bnode source indicates InputStream - assertTrue(firstPredicate(g, "source").startsWith("_:")); - assertEquals("\"application/n-quads\"", firstPredicate(g, "contentType")); - assertEquals("\"NQUADS\"", firstPredicate(g, "contentTypeSyntax")); - } - - @Test - public void parseIRI() throws Exception { - IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl"); - Graph g = factory.createGraph(); - RDFParser parser = dummyParser.source(iri).target(g); - parser.parse().get(5, TimeUnit.SECONDS); - checkGraph(g); - assertEquals("", firstPredicate(g, "source")); - // No base - assuming the above IRI is always - // the base would break server-supplied base from - // any HTTP Location redirects and Content-Location header - assertNull(firstPredicate(g, "base")); - // ".ttl" in IRI string does not imply any content type - assertNull(firstPredicate(g, "contentType")); - assertNull(firstPredicate(g, "contentTypeSyntax")); - - } - - @Test - public void parseIRIBaseContentType() throws Exception { - IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl"); - Graph g = factory.createGraph(); - RDFParser parser = dummyParser.source(iri).base(iri).contentType(RDFSyntax.TURTLE).target(g); - parser.parse().get(5, TimeUnit.SECONDS); - checkGraph(g); - assertEquals("", firstPredicate(g, "source")); - assertEquals("", firstPredicate(g, "base")); - assertEquals("\"TURTLE\"", firstPredicate(g, "contentTypeSyntax")); - assertEquals("\"text/turtle\"", firstPredicate(g, "contentType")); - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/74196bdd/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java ---------------------------------------------------------------------- diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java new file mode 100644 index 0000000..f263029 --- /dev/null +++ b/simple/src/test/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParserTest.java @@ -0,0 +1,256 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.rdf.simple.experimental; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.rdf.api.Graph; +import org.apache.commons.rdf.api.IRI; +import org.apache.commons.rdf.api.Literal; +import org.apache.commons.rdf.api.RDFSyntax; +import org.apache.commons.rdf.api.RDFTerm; +import org.apache.commons.rdf.api.RDFTermFactory; +import org.apache.commons.rdf.api.Triple; +import org.apache.commons.rdf.experimental.RDFParser; +import org.apache.commons.rdf.simple.DummyRDFParserBuilder; +import org.apache.commons.rdf.simple.SimpleRDFTermFactory; +import org.apache.commons.rdf.simple.Types; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class AbstractRDFParserTest { + + private RDFTermFactory factory = new SimpleRDFTermFactory(); + + private DummyRDFParserBuilder dummyParser = new DummyRDFParserBuilder(); + private Path testNt; + private Path testTtl; + private Path testXml; + + @Before + public void createTempFile() throws IOException { + testNt = Files.createTempFile("test", ".nt"); + testTtl = Files.createTempFile("test", ".ttl"); + testXml = Files.createTempFile("test", ".xml"); + + // No need to populate the files as the dummy parser + // doesn't actually read anything + } + + @After + public void deleteTempFiles() throws IOException { + Files.deleteIfExists(testNt); + Files.deleteIfExists(testTtl); + Files.deleteIfExists(testXml); + } + + @Test + public void guessRDFSyntax() throws Exception { + assertEquals(RDFSyntax.NTRIPLES, AbstractRDFParser.guessRDFSyntax(testNt).get()); + assertEquals(RDFSyntax.TURTLE, AbstractRDFParser.guessRDFSyntax(testTtl).get()); + assertFalse(AbstractRDFParser.guessRDFSyntax(testXml).isPresent()); + } + + private void checkGraph(Graph g) throws Exception { + assertTrue(g.size() > 0); + IRI greeting = factory.createIRI("http://example.com/greeting"); + // Should only have parsed once! + assertEquals(1, g.getTriples(null, greeting, null).count()); + Triple triple = g.getTriples(null, greeting, null).findAny().get(); + assertTrue(triple.getSubject() instanceof IRI); + IRI parsing = (IRI) triple.getSubject(); + assertTrue(parsing.getIRIString().startsWith("urn:uuid:")); + + assertEquals("http://example.com/greeting", triple.getPredicate().getIRIString()); + + assertTrue(triple.getObject() instanceof Literal); + Literal literal = (Literal) triple.getObject(); + assertEquals("Hello world", literal.getLexicalForm()); + assertFalse(literal.getLanguageTag().isPresent()); + assertEquals(Types.XSD_STRING, literal.getDatatype()); + + // Check uniqueness of properties that are always present + assertEquals(1, + g.getTriples(null, factory.createIRI("http://example.com/source"), null).count()); + + // Check optional properties that are unique + assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/base"), null).count()); + assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/contentType"), null).count()); + assertTrue(2 > g.getTriples(null, factory.createIRI("http://example.com/contentTypeSyntax"), null).count()); + } + + @Test + public void parseFile() throws Exception { + Graph g = factory.createGraph(); + RDFParser parser = dummyParser.source(testNt).target(g); + parser.parse().get(5, TimeUnit.SECONDS); + checkGraph(g); + // FIXME: this could potentially break if the equivalent of /tmp includes + // international characters + assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source")); + // Should be set to the file path + assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base")); + + // Should NOT have guessed the content type + assertNull(firstPredicate(g, "contentType")); + assertNull(firstPredicate(g, "contentTypeSyntax")); + } + + + @Test + public void parseNoSource() throws Exception { + thrown.expect(IllegalStateException.class); + dummyParser.parse(); + } + + @Test + public void parseBaseAndContentTypeNoSource() throws Exception { + // Can set the other options, even without source() + IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf"); + RDFParser parser = dummyParser.base(base).contentType(RDFSyntax.RDFXML); + thrown.expect(IllegalStateException.class); + thrown.expectMessage("No source has been set"); + // but .parse() should fail + parser.parse(); + } + + @Test + public void parseFileMissing() throws Exception { + Files.delete(testNt); + // This should not fail yet + RDFParser parser = dummyParser.source(testNt); + // but here: + thrown.expect(IOException.class); + parser.parse(); + } + + + @Test + public void parseFileContentType() throws Exception { + Graph g = factory.createGraph(); + RDFParser parser = dummyParser + .source(testNt) + .contentType(RDFSyntax.NTRIPLES) + .target(g); + parser.parse().get(5, TimeUnit.SECONDS); + checkGraph(g); + // FIXME: this could potentially break if the equivalent of /tmp includes + // international characters + assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source")); + assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "base")); + assertEquals("\"NTRIPLES\"", firstPredicate(g, "contentTypeSyntax")); + assertEquals("\"application/n-triples\"", firstPredicate(g, "contentType")); + } + + private String firstPredicate(Graph g, String pred) { + return g.getTriples(null, factory.createIRI("http://example.com/" + pred), null) + .map(Triple::getObject).map(RDFTerm::ntriplesString).findAny().orElse(null); + } + + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void parseInputStreamFailsIfBaseMissing() throws Exception { + InputStream inputStream = new ByteArrayInputStream(new byte[0]); + // Should not fail at this point + RDFParser parser = dummyParser.source(inputStream); + // but here: + thrown.expect(IllegalStateException.class); + thrown.expectMessage("base iri required for inputstream source"); + parser.parse(); + } + + @Test + public void parseInputStreamWithBase() throws Exception { + InputStream inputStream = new ByteArrayInputStream(new byte[0]); + IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf"); + Graph g = factory.createGraph(); + RDFParser parser = dummyParser.source(inputStream).base(base).target(g); + parser.parse().get(5, TimeUnit.SECONDS); + checkGraph(g); + assertEquals("", firstPredicate(g, "base")); + // in our particular debug output, + // bnode source indicates InputStream + assertTrue(firstPredicate(g, "source").startsWith("_:")); + assertNull(firstPredicate(g, "contentType")); + assertNull(firstPredicate(g, "contentTypeSyntax")); + } + + @Test + public void parseInputStreamWithNQuads() throws Exception { + InputStream inputStream = new ByteArrayInputStream(new byte[0]); + Graph g = factory.createGraph(); + RDFParser parser = dummyParser.source(inputStream).contentType(RDFSyntax.NQUADS).target(g); + parser.parse().get(5, TimeUnit.SECONDS); + checkGraph(g); + assertNull(firstPredicate(g, "base")); + // in our particular debug output, + // bnode source indicates InputStream + assertTrue(firstPredicate(g, "source").startsWith("_:")); + assertEquals("\"application/n-quads\"", firstPredicate(g, "contentType")); + assertEquals("\"NQUADS\"", firstPredicate(g, "contentTypeSyntax")); + } + + @Test + public void parseIRI() throws Exception { + IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl"); + Graph g = factory.createGraph(); + RDFParser parser = dummyParser.source(iri).target(g); + parser.parse().get(5, TimeUnit.SECONDS); + checkGraph(g); + assertEquals("", firstPredicate(g, "source")); + // No base - assuming the above IRI is always + // the base would break server-supplied base from + // any HTTP Location redirects and Content-Location header + assertNull(firstPredicate(g, "base")); + // ".ttl" in IRI string does not imply any content type + assertNull(firstPredicate(g, "contentType")); + assertNull(firstPredicate(g, "contentTypeSyntax")); + + } + + @Test + public void parseIRIBaseContentType() throws Exception { + IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl"); + Graph g = factory.createGraph(); + RDFParser parser = dummyParser.source(iri).base(iri).contentType(RDFSyntax.TURTLE).target(g); + parser.parse().get(5, TimeUnit.SECONDS); + checkGraph(g); + assertEquals("", firstPredicate(g, "source")); + assertEquals("", firstPredicate(g, "base")); + assertEquals("\"TURTLE\"", firstPredicate(g, "contentTypeSyntax")); + assertEquals("\"text/turtle\"", firstPredicate(g, "contentType")); + } + + +}