jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject [1/2] jena git commit: add failing unit test for JENA-1093
Date Wed, 16 Dec 2015 09:53:56 GMT
Repository: jena
Updated Branches:
  refs/heads/master b6192a9e1 -> 67f9905de


add failing unit test for JENA-1093


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/4bf7319c
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/4bf7319c
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/4bf7319c

Branch: refs/heads/master
Commit: 4bf7319c31cb3c65c0ab18e67477d4d24ad5c8ed
Parents: b6192a9
Author: Osma Suominen <osma@apache.org>
Authored: Tue Dec 15 16:52:08 2015 +0200
Committer: Osma Suominen <osma@apache.org>
Committed: Tue Dec 15 16:52:08 2015 +0200

----------------------------------------------------------------------
 .../TestDatasetWithLuceneStoredLiterals.java    | 58 ++++++++++++++++++++
 1 file changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/4bf7319c/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneStoredLiterals.java
----------------------------------------------------------------------
diff --git a/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneStoredLiterals.java
b/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneStoredLiterals.java
index b55bbd7..659a0dd 100644
--- a/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneStoredLiterals.java
+++ b/jena-text/src/test/java/org/apache/jena/query/text/TestDatasetWithLuceneStoredLiterals.java
@@ -27,12 +27,15 @@ import java.io.StringReader ;
 import java.util.Arrays ;
 import java.util.HashMap ;
 import java.util.HashSet ;
+import java.util.LinkedList ;
+import java.util.List ;
 import java.util.Map ;
 import java.util.Set ;
 
 import org.apache.jena.assembler.Assembler ;
 import org.apache.jena.atlas.lib.StrUtils ;
 import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.NodeFactory ;
 import org.apache.jena.query.Dataset ;
 import org.apache.jena.query.Query ;
@@ -147,6 +150,35 @@ public class TestDatasetWithLuceneStoredLiterals extends AbstractTestDatasetWith
         return literals;
     }
 
+    protected List<Node> doTestSearchWithLiteralsMultiple(String turtle, String queryString,
String expectedEntityURI) {
+        List<Node> literals = new LinkedList<>();
+        Model model = dataset.getDefaultModel();
+        Reader reader = new StringReader(turtle);
+        dataset.begin(ReadWrite.WRITE);
+        model.read(reader, "", "TURTLE");
+        dataset.commit();
+
+        Query query = QueryFactory.create(queryString) ;
+        dataset.begin(ReadWrite.READ);
+        try(QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
+            ResultSet results = qexec.execSelect() ;
+            int count;
+            for (count=0; results.hasNext(); count++) {
+                QuerySolution soln = results.nextSolution();
+                String entityURI = soln.getResource("s").getURI();
+                assertEquals(expectedEntityURI, entityURI);
+                Literal literal = soln.getLiteral("literal");
+                assertNotNull(literal);
+                literals.add(literal.asNode());
+            }
+        }
+        finally {
+            dataset.end() ;
+        }
+        return literals;
+    }
+
+
     @Test
     public void testLiteralValue() {
         // test basic capturing of the literal value in a variable
@@ -245,4 +277,30 @@ public class TestDatasetWithLuceneStoredLiterals extends AbstractTestDatasetWith
         assertEquals(NodeFactory.createLiteral("true", XSDDatatype.XSDboolean), value.asNode());
     }
 
+    @Test
+    public void testLiteralValueMultiple() {
+        // test capturing of multiple matching literal values in a variable
+        final String testName = "testLiteralValueMultiple";
+        final String turtle = StrUtils.strjoinNL(
+                TURTLE_PROLOG,
+                "<" + RESOURCE_BASE + testName + ">",
+                "  rdfs:comment 'a nontext comment', 'another nontext comment'",
+                "."
+                );
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s ?literal",
+                "WHERE {",
+                "    (?s ?score ?literal) text:query (rdfs:comment 'nontext') .",
+                "}"
+                );
+
+        String expectedURI = RESOURCE_BASE + testName;
+        List<Node> literals = doTestSearchWithLiteralsMultiple(turtle, queryString,
expectedURI);
+
+        assertEquals(2, literals.size());
+        assertTrue(literals.contains(NodeFactory.createLiteral("a nontext comment")));
+        assertTrue(literals.contains(NodeFactory.createLiteral("another nontext comment")));
+    }
+
 }


Mime
View raw message