jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/5] jena git commit: JENA-1468: Tests
Date Tue, 30 Jan 2018 11:18:40 GMT
JENA-1468: Tests


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

Branch: refs/heads/master
Commit: 2586abf09751fd962ca7afe25d4ab3d9431ce716
Parents: 30eb931
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Jan 26 13:53:17 2018 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Sat Jan 27 13:49:43 2018 +0000

----------------------------------------------------------------------
 .../apache/jena/sparql/algebra/TS_Algebra.java  |  3 +-
 .../jena/sparql/algebra/TestOpAsQuery.java      | 26 +++++++-
 .../apache/jena/sparql/algebra/TestTable.java   | 68 ++++++++++++++++++++
 .../algebra/optimize/TestTransformFilters.java  |  2 +-
 4 files changed, 94 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/2586abf0/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TS_Algebra.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TS_Algebra.java b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TS_Algebra.java
index eaa9fe4..0e34dba 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TS_Algebra.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TS_Algebra.java
@@ -24,7 +24,8 @@ import org.junit.runners.Suite ;
 @RunWith(Suite.class)
 @Suite.SuiteClasses( {
     // This package
-    TestAlgebraTranslate.class
+    TestTable.class
+    , TestAlgebraTranslate.class
     , TestClassify.class
     , TestOpAsQuery.class
     , TestOpVars.class

http://git-wip-us.apache.org/repos/asf/jena/blob/2586abf0/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java
index 24169d5..2033ba8 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestOpAsQuery.java
@@ -390,6 +390,25 @@ public class TestOpAsQuery {
     }
     
     @Test
+    public void testTable1() {
+        String query = "SELECT * WHERE { ?x ?p ?z . VALUES ?y { } }" ;
+        roundTripQuery(query);
+    }
+    
+    @Test
+    public void testTable2() {
+        // JENA-1468 : op to string and back.
+        String qs = "SELECT * WHERE { ?x ?p ?z . VALUES ?y { } }" ;
+        Query query = QueryFactory.create(qs); 
+        Op op = Algebra.compile(query);
+        String x = op.toString();
+        Op op1 = SSE.parseOp(x);
+        Query query2 = OpAsQuery.asQuery(op1);
+        assertEquals(query, query2);
+    }
+    
+
+    @Test
     public void testValues1() {
         String query = "SELECT  * { VALUES ?x {1 2} ?s ?p ?x }" ;
         test_roundTripQuery(query) ;
@@ -443,6 +462,7 @@ public class TestOpAsQuery {
     
     // Test for queries that do query->algebra->OpAsQuery->query
     // to produce an output that is .equals the input.
+    /** query->algebra->OpAsQuery->query */
     public static Query[] test_roundTripQuery(String query) {
         Query[] r = roundTripQuery(query) ;
         stripNamespacesAndBase(r[0]) ; 
@@ -471,7 +491,7 @@ public class TestOpAsQuery {
         Assert.assertEquals(a1, a2);
     }
     
-    // algebra->OpAsQuery->query
+    /** algebra->OpAsQuery->query */
     public static void test_AlgebraToQuery(String input, String expected) {
         Op op = SSE.parseOp(input) ;
         Query orig = QueryFactory.create(expected, Syntax.syntaxSPARQL_11);
@@ -480,7 +500,7 @@ public class TestOpAsQuery {
         Assert.assertEquals(orig, got) ;
     }
 
-    // query->algebra->OpAsQuery->query
+    /** query->algebra->OpAsQuery->query **/
     private static Query[] roundTripQuery(String query) {
         Query orig = QueryFactory.create(query, Syntax.syntaxSPARQL_11);
         Op toReconstruct = Algebra.compile(orig);
@@ -489,7 +509,7 @@ public class TestOpAsQuery {
         return r;
     }
     
-    // query->algebra/quads->OpAsQuery->query
+    /** query->algebra/quads->OpAsQuery->query */
     private static Query[] roundTripQueryQuad(String query) {
         Query orig = QueryFactory.create(query, Syntax.syntaxSPARQL_11);
         Op toReconstruct = Algebra.compile(orig);

http://git-wip-us.apache.org/repos/asf/jena/blob/2586abf0/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestTable.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestTable.java b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestTable.java
new file mode 100644
index 0000000..5f647ce
--- /dev/null
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/TestTable.java
@@ -0,0 +1,68 @@
+/*
+ * 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.jena.sparql.algebra;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer;
+import org.apache.jena.sparql.algebra.op.OpTable;
+import org.apache.jena.sparql.core.Var;
+import org.apache.jena.sparql.engine.binding.Binding;
+import org.apache.jena.sparql.engine.binding.BindingFactory;
+import org.apache.jena.sparql.serializer.SerializationContext;
+import org.apache.jena.sparql.sse.writers.WriterOp;
+import org.junit.Test ;
+
+public class TestTable {
+    @Test public void table_01() {
+        Table table = TableFactory.createEmpty();
+        Op opTable = OpTable.create(table);
+        String x = str(opTable);
+        assertEquals("(table empty)",  x);
+    }
+
+    // JENA-1468: Table, no rows , with declared variables.
+    @Test public void table_02() {
+        Table table = TableFactory.create();
+        table.getVars().add(Var.alloc("a"));
+        Op opTable = OpTable.create(table);
+        String x = str(opTable);
+        assertEquals("(table (vars ?a))",  x);
+    }
+    
+    @Test public void table_03() {
+        Table table = TableFactory.create();
+        Binding b = BindingFactory.binding();
+        table.addBinding(b);
+        Op opTable = OpTable.create(table);
+        String x = str(opTable);
+        assertEquals("(table (vars) (row) )",  x);
+    }
+    
+    // String, no adornment
+    private static String str(Op op) {
+        SerializationContext sCxt = new SerializationContext();
+        IndentedLineBuffer out = new IndentedLineBuffer();
+        out.setFlatMode(true);
+        WriterOp.output(out, op, sCxt);
+        String x = out.asString();
+        return x.trim();
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/2586abf0/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestTransformFilters.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestTransformFilters.java
b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestTransformFilters.java
index a970f8e..41de9ee 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestTransformFilters.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/algebra/optimize/TestTransformFilters.java
@@ -907,7 +907,7 @@ public class TestTransformFilters extends AbstractTestTransform
         // Tests use of multiple != conditions on same variable
         testOp("(filter ((!= ?x <x>) (!= ?x <y>)) (bgp ( ?s ?p ?x)) )",
                t_inequality,
-               "(minus (bgp (?s ?p ?x)) (table (vars ?p ?x) (row [?x <y>]) (row [?x
<x>])))") ;
+               "(minus (bgp (?s ?p ?x)) (table (vars ?x) (row [?x <y>]) (row [?x <x>])))")
;
     }
 
     @Test public void inequality09() {


Mime
View raw message