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 1D2A0200C24 for ; Thu, 9 Feb 2017 01:27:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1BDDD160B6A; Thu, 9 Feb 2017 00:27:48 +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 17D50160B67 for ; Thu, 9 Feb 2017 01:27:46 +0100 (CET) Received: (qmail 40716 invoked by uid 500); 9 Feb 2017 00:27:46 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 40619 invoked by uid 99); 9 Feb 2017 00:27:46 -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; Thu, 09 Feb 2017 00:27:46 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D746EDFB0E; Thu, 9 Feb 2017 00:27:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stain@apache.org To: commits@commons.apache.org Date: Thu, 09 Feb 2017 00:27:46 -0000 Message-Id: <92c448a7eb524eb0b78b748f3d9da552@git.apache.org> In-Reply-To: <1612ee627842422b90ce5cddc9e8399e@git.apache.org> References: <1612ee627842422b90ce5cddc9e8399e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] commons-rdf git commit: COMMONSRDF-57: Verify JSON-LD parses with mega-classpath archived-at: Thu, 09 Feb 2017 00:27:48 -0000 COMMONSRDF-57: Verify JSON-LD parses with mega-classpath Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/b1a31157 Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/b1a31157 Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/b1a31157 Branch: refs/heads/master Commit: b1a31157ee683e695501d77ece7d012c8066b1c0 Parents: df6c1a2 Author: Stian Soiland-Reyes Authored: Thu Feb 9 00:21:15 2017 +0000 Committer: Stian Soiland-Reyes Committed: Thu Feb 9 00:27:20 2017 +0000 ---------------------------------------------------------------------- integration-tests/pom.xml | 3 +- .../rdf/integrationtests/JSONLDParsingTest.java | 164 +++++++++++++++++++ .../src/test/resources/alice-cached.jsonld | 9 + .../src/test/resources/alice-embedded.jsonld | 16 ++ .../src/test/resources/contexts/example.jsonld | 11 ++ .../src/test/resources/jarcache.json | 10 ++ 6 files changed, 212 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b1a31157/integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 04496ef..4eeb7ec 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -49,7 +49,8 @@ ${project.version} + See the JSONLDParsingTest. + --> ${project.groupId} commons-rdf-jsonld-java http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b1a31157/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JSONLDParsingTest.java ---------------------------------------------------------------------- diff --git a/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JSONLDParsingTest.java b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JSONLDParsingTest.java new file mode 100644 index 0000000..3bd406a --- /dev/null +++ b/integration-tests/src/test/java/org/apache/commons/rdf/integrationtests/JSONLDParsingTest.java @@ -0,0 +1,164 @@ +/** + * 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.integrationtests; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +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.RDF; +import org.apache.commons.rdf.jena.JenaDataset; +import org.apache.commons.rdf.jena.JenaRDF; +import org.apache.commons.rdf.jsonldjava.JsonLdGraph; +import org.apache.commons.rdf.jsonldjava.JsonLdRDF; +import org.apache.commons.rdf.rdf4j.RDF4J; +import org.apache.commons.rdf.rdf4j.RDF4JGraph; +import org.apache.commons.rdf.simple.SimpleRDF; +import org.apache.jena.riot.RDFDataMgr; +import org.eclipse.rdf4j.model.Model; +import org.eclipse.rdf4j.rio.RDFFormat; +import org.eclipse.rdf4j.rio.Rio; +import org.junit.Before; +import org.junit.Test; + +import com.fasterxml.jackson.core.JsonParseException; +import com.github.jsonldjava.core.JsonLdError; +import com.github.jsonldjava.core.JsonLdOptions; +import com.github.jsonldjava.core.JsonLdProcessor; +import com.github.jsonldjava.core.RDFDataset; +import com.github.jsonldjava.utils.JsonUtils; + +/** + * COMMONSRDF-57 etc: For upgrades, ensure JSONLD-Java parses well in all + * implementations even if they might have slightly incompatible versions of + * their dependencies. + *

+ * The *Embedded tests parse alice-embedded.jsonld + * from the test classpath through Jena, RDF4J and JSONLD-Java and verifies it + * contains the expected triples using {@link #checkGraph(Graph)}. This ensures + * that the versions of JSONLD-Java and Jackson are compatible with Jena and + * RDF4J. + *

+ * The *Cached tests parse alice-cached.jsonld, which + * references an external @context of http://example.com/context - + * but using the jarcache.json + * mechanism of JSONLD-Java, this context will be loaded from + * contexts/example.jsonld on the test classpath instead. This + * ensures that the versions of HTTPClient is compatible with JSONLD-Java + * (however it does not check that it is compatible with Jena and + * RDF4J's external fetching of RDF documents). + * + */ +public class JSONLDParsingTest { + + static RDF rdf = new SimpleRDF(); + static IRI alice = rdf.createIRI("http://example.com/Alice"); + static IRI name = rdf.createIRI("http://schema.org/name"); + static IRI type = rdf.createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); + static IRI person = rdf.createIRI("http://schema.org/Person"); + static Literal aliceWLand = rdf.createLiteral("Alice W. Land"); + + URL aliceCached = getClass().getResource("/alice-cached.jsonld"); + URL aliceEmbedded = getClass().getResource("/alice-embedded.jsonld"); + + /** + * Pre-test that src/test/resources files are on the classpath + * + */ + @Before + public void checkTestResources() throws Exception { + aliceCached.openStream().close(); + aliceEmbedded.openStream().close(); + // Used by JSONLD-Java to avoid external dependencies. See + // https://github.com/jsonld-java/jsonld-java#loading-contexts-from-classpathjar + getClass().getResourceAsStream("/jarcache.json").close(); + getClass().getResourceAsStream("/contexts/example.jsonld").close(); + // (We'll use these to ensure our HTTPClient dependency works) + } + + private void checkGraph(Graph g) { + assertTrue(g.contains(alice, name, aliceWLand)); + assertTrue(g.contains(alice, type, person)); + } + + @Test + public void jenaParseEmbedded() throws Exception { + jenaParse(aliceEmbedded); + } + + @Test + public void jenaParseCached() throws Exception { + // Check if HTTPClient cache is used from + // jarcache.json + jenaParse(aliceCached); + } + + private void jenaParse(URL url) { + JenaDataset dataset = new JenaRDF().createDataset(); + RDFDataMgr.read(dataset.asJenaDatasetGraph(), url.toExternalForm()); + checkGraph(dataset.getGraph()); + } + + @Test + public void rdf4jParseEmbedded() throws Exception { + rdf4jParse(aliceEmbedded); + } + + @Test + public void rdf4jParseCached() throws Exception { + // Check if HTTPClient cache is used from + // jarcache.json + rdf4jParse(aliceCached); + } + + private void rdf4jParse(URL url) throws IOException { + Model model; + try (InputStream in = url.openStream()) { + model = Rio.parse(in, url.toExternalForm(), RDFFormat.JSONLD); + } + RDF4JGraph graph = new RDF4J().asGraph(model); + checkGraph(graph); + } + + @Test + public void jsonldParseEmbedded() throws Exception { + jsonldParse(aliceEmbedded); + } + + @Test + public void jsonldParseCached() throws Exception { + // Check if HTTPClient cache is used from + // jarcache.json + jsonldParse(aliceCached); + } + + private void jsonldParse(URL url) throws JsonParseException, IOException, JsonLdError { + Object aliceJson = JsonUtils.fromURL(url, JsonUtils.getDefaultHttpClient()); + JsonLdOptions options = new JsonLdOptions(); + options.setBase(url.toExternalForm()); + RDFDataset ds = (RDFDataset) JsonLdProcessor.toRDF(aliceJson); + JsonLdGraph graph = new JsonLdRDF().asGraph(ds); + checkGraph(graph); + } +} http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b1a31157/integration-tests/src/test/resources/alice-cached.jsonld ---------------------------------------------------------------------- diff --git a/integration-tests/src/test/resources/alice-cached.jsonld b/integration-tests/src/test/resources/alice-cached.jsonld new file mode 100644 index 0000000..494d20e --- /dev/null +++ b/integration-tests/src/test/resources/alice-cached.jsonld @@ -0,0 +1,9 @@ +{ "http://purl.org/dc/terms/license" : + "Licensed to the Apache Software Foundation (ASF) under one or more\n contributor license agreements. See the NOTICE file distributed with\n this work for additional information regarding copyright ownership.\n The ASF licenses this file to You under the Apache License, Version 2.0\n (the \"License\"); you may not use this file except in compliance with\n the License. You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n", + + "@context": "http://example.com/context", + "@id": "ex:Alice", + "@type": "Person", + "name": "Alice W. Land" +} + http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b1a31157/integration-tests/src/test/resources/alice-embedded.jsonld ---------------------------------------------------------------------- diff --git a/integration-tests/src/test/resources/alice-embedded.jsonld b/integration-tests/src/test/resources/alice-embedded.jsonld new file mode 100644 index 0000000..7c8ca85 --- /dev/null +++ b/integration-tests/src/test/resources/alice-embedded.jsonld @@ -0,0 +1,16 @@ +{ "http://purl.org/dc/terms/license" : + "Licensed to the Apache Software Foundation (ASF) under one or more\n contributor license agreements. See the NOTICE file distributed with\n this work for additional information regarding copyright ownership.\n The ASF licenses this file to You under the Apache License, Version 2.0\n (the \"License\"); you may not use this file except in compliance with\n the License. You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n", + + "@context": { + "xsd": "http://www.w3.org/2001/XMLSchema#", + "schema": "http://schema.org/", + "ex": "http://example.com/", + "name": "schema:name", + "Person": "schema:Person" + }, + + "@id": "ex:Alice", + "@type": "Person", + "name": "Alice W. Land" +} + http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b1a31157/integration-tests/src/test/resources/contexts/example.jsonld ---------------------------------------------------------------------- diff --git a/integration-tests/src/test/resources/contexts/example.jsonld b/integration-tests/src/test/resources/contexts/example.jsonld new file mode 100644 index 0000000..0e58a65 --- /dev/null +++ b/integration-tests/src/test/resources/contexts/example.jsonld @@ -0,0 +1,11 @@ +{ "http://purl.org/dc/terms/license" : + "Licensed to the Apache Software Foundation (ASF) under one or more\n contributor license agreements. See the NOTICE file distributed with\n this work for additional information regarding copyright ownership.\n The ASF licenses this file to You under the Apache License, Version 2.0\n (the \"License\"); you may not use this file except in compliance with\n the License. You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n", + + "@context": { + "xsd": "http://www.w3.org/2001/XMLSchema#", + "schema": "http://schema.org/", + "ex": "http://example.com/", + "name": "schema:name", + "Person": "schema:Person" + } +} http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/b1a31157/integration-tests/src/test/resources/jarcache.json ---------------------------------------------------------------------- diff --git a/integration-tests/src/test/resources/jarcache.json b/integration-tests/src/test/resources/jarcache.json new file mode 100644 index 0000000..05eb13c --- /dev/null +++ b/integration-tests/src/test/resources/jarcache.json @@ -0,0 +1,10 @@ +[ + { + "X-License": + "Licensed to the Apache Software Foundation (ASF) under one or more\n contributor license agreements. See the NOTICE file distributed with\n this work for additional information regarding copyright ownership.\n The ASF licenses this file to You under the Apache License, Version 2.0\n (the \"License\"); you may not use this file except in compliance with\n the License. You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n", + + "Content-Location": "http://example.com/context", + "X-Classpath": "contexts/example.jsonld", + "Content-Type": "application/ld+json" + } +] \ No newline at end of file