MARMOTTA-617: added test
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/732f4565 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/732f4565 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/732f4565 Branch: refs/heads/MARMOTTA-584 Commit: 732f45650a02f193f75398284b86045da06a3c68 Parents: dd013be Author: Sergio Fernández <[email protected]> Authored: Fri Oct 9 14:48:47 2015 +0200 Committer: Sergio Fernández <[email protected]> Committed: Fri Oct 9 14:48:47 2015 +0200 ---------------------------------------------------------------------- .../kiwi/sparql/test/KiWiSparqlTest.java | 36 +++++++++++++++-- .../kiwi/sparql/test/MARMOTTA-617.sparql | 28 +++++++++++++ .../marmotta/kiwi/sparql/test/MARMOTTA-617.ttl | 41 ++++++++++++++++++++ 3 files changed, 101 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/732f4565/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlTest.java ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlTest.java b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlTest.java index e346ce5..6f34750 100644 --- a/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlTest.java +++ b/libraries/kiwi/kiwi-sparql/src/test/java/org/apache/marmotta/kiwi/sparql/test/KiWiSparqlTest.java @@ -36,9 +36,7 @@ import org.junit.*; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.junit.runner.RunWith; -import org.openrdf.model.BNode; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; +import org.openrdf.model.*; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.*; import org.openrdf.query.impl.DatasetImpl; @@ -137,7 +135,7 @@ public class KiWiSparqlTest { * @throws Exception */ @Test - public void testQuery37() throws Exception { + public void testMarmotta578() throws Exception { testQuery("MARMOTTA-578.sparql"); } @@ -252,4 +250,34 @@ public class KiWiSparqlTest { } + @Test + public void testMarmotta617() throws Exception { + RepositoryConnection conn = repository.getConnection(); + try { + conn.begin(); + + // 1) load demo data + conn.add(this.getClass().getResourceAsStream("MARMOTTA-617.ttl"), "http://localhost/test/MARMOTTA-617", RDFFormat.TURTLE); + conn.commit(); + + // 2) test the query behavior + String queryString = IOUtils.toString(this.getClass().getResourceAsStream("MARMOTTA-617.sparql"), "UTF-8"); + TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); + TupleQueryResult results = query.evaluate(); + try { + while (results.hasNext()) { + BindingSet bindingSet = results.next(); + Assert.assertTrue(bindingSet.getValue("children") instanceof Literal); + Literal children = (Literal) bindingSet.getValue("children"); + Assert.assertEquals("http://www.w3.org/2001/XMLSchema#boolean", children.getDatatype().stringValue()); + Assert.assertTrue(Lists.newArrayList("true", "false").contains(children.stringValue())); + } + } finally { + results.close(); + } + } finally { + conn.close(); + } + } + } http://git-wip-us.apache.org/repos/asf/marmotta/blob/732f4565/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/MARMOTTA-617.sparql ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/MARMOTTA-617.sparql b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/MARMOTTA-617.sparql new file mode 100644 index 0000000..b0f847a --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/MARMOTTA-617.sparql @@ -0,0 +1,28 @@ +# +# 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. +# + +SELECT DISTINCT ?uri ?title ?children { + GRAPH <http://localhost/test/MARMOTTA-617> { + ?uri a <http://www.w3.org/2004/02/skos/core#ConceptScheme> . + OPTIONAL { + ?uri <http://www.w3.org/2000/01/rdf-schema#label> ?title . + FILTER (lang(?title) = 'en') + } + BIND ( EXISTS { ?uri <http://www.w3.org/2004/02/skos/core#hasTopConcept> ?_top } AS ?children ) + } +} http://git-wip-us.apache.org/repos/asf/marmotta/blob/732f4565/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/MARMOTTA-617.ttl ---------------------------------------------------------------------- diff --git a/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/MARMOTTA-617.ttl b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/MARMOTTA-617.ttl new file mode 100644 index 0000000..91d0e6c --- /dev/null +++ b/libraries/kiwi/kiwi-sparql/src/test/resources/org/apache/marmotta/kiwi/sparql/test/MARMOTTA-617.ttl @@ -0,0 +1,41 @@ +# +# 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. +# + +@prefix skos: <http://www.w3.org/2004/02/skos/core#> . +@prefix : <http://example.org/vocabulary/> . + +:Vocabulary a skos:ConceptScheme; + skos:hasTopConcept :TopLevelConceptA; + skos:hasTopConcept :TopLevelConceptB; + rdfs:label "A simple Vocabulary"@en. + +:TopLevelConceptA a skos:Concept; + skos:inScheme :Vocabulary; + skos:topConceptOf :Vocabulary; + skos:prefLabel "Label Concept a"@en. + +:TopLevelConceptB a skos:Concept; + skos:inScheme :Vocabulary; + skos:topConceptOf :Vocabulary; + skos:narrower :NarrowerConceptB; + skos:prefLabel "Label Concept b"@en. + +:NarrowerConceptB a skos:Concept; + skos:inScheme :Vocabulary; + skos:broader :TopLevelConceptB; + skos:prefLabel "Label Concept b"@en.
