You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/05/08 09:33:43 UTC

[5/7] git commit: Fixed some tests in ldpath parsing.

Fixed some tests in ldpath parsing.

Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/6c82a02a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/6c82a02a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/6c82a02a

Branch: refs/heads/develop
Commit: 6c82a02a82d5a52a6a3e06d7e1e426ba93d77f82
Parents: fd5642b
Author: Jakob Frank <ja...@apache.org>
Authored: Tue May 7 16:35:08 2013 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Tue May 7 16:35:08 2013 +0200

----------------------------------------------------------------------
 .../marmotta/ldpath/model/tests/IsATest.java       |   57 +++++++++++++++
 .../ldpath/model/tests/LiteralTypeTest.java        |    2 +-
 .../ldpath/model/tests/PathEqualityTest.java       |    4 +-
 .../javacc/at/newmedialab/ldpath/parser/rdfpath.jj |    2 +-
 .../marmotta/ldpath/parser/SelectorsTest.java      |    2 +-
 .../apache/marmotta/ldpath/parser/TestsTest.java   |    4 +-
 6 files changed, 64 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/6c82a02a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/IsATest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/IsATest.java b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/IsATest.java
new file mode 100644
index 0000000..7f84457
--- /dev/null
+++ b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/IsATest.java
@@ -0,0 +1,57 @@
+/**
+ * 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.marmotta.ldpath.model.tests;
+
+import org.apache.marmotta.ldpath.api.backend.NodeBackend;
+import org.apache.marmotta.ldpath.model.selectors.PropertySelector;
+
+/**
+ * Shortcut for {@link PathEqualityTest} with the property {@literal http://www.w3.org/1999/02/22-rdf-syntax-ns#type}
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ * @param <Node>
+ */
+public class IsATest<Node> extends PathEqualityTest<Node> {
+
+    public IsATest(Node rdfType, Node node) {
+        super(new PropertySelector<Node>(rdfType), node);
+    }
+    
+    @Override
+    public String getPathExpression(NodeBackend<Node> rdfBackend) {
+        if (rdfBackend.isURI(node)) {
+            return String.format("is-a <%s>", rdfBackend.stringValue(node));
+        } else if (rdfBackend.isLiteral(node)) {
+            return String.format("is-a \"%s\"", rdfBackend.stringValue(node));
+        } else {
+            // TODO Can this happen?
+            return String.format("is-a %s", rdfBackend.stringValue(node));
+        }
+    }
+    
+    @Override
+    public String getSignature() {
+        return "is-a Node :: NodeList -> Boolean";
+    }
+    
+    @Override
+    public String getDescription() {
+        return "tests if a node has a certain type";
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/6c82a02a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/LiteralTypeTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/LiteralTypeTest.java b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/LiteralTypeTest.java
index 58bbad0..0ed55d5 100644
--- a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/LiteralTypeTest.java
+++ b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/LiteralTypeTest.java
@@ -73,7 +73,7 @@ public class LiteralTypeTest<Node> extends NodeTest<Node> {
      */
     @Override
     public String getPathExpression(NodeBackend<Node> rdfBackend) {
-        return "^^" + typeUri;
+        return String.format("^^<%s>", typeUri);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/6c82a02a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/PathEqualityTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/PathEqualityTest.java b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/PathEqualityTest.java
index 29d09df..82bb714 100644
--- a/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/PathEqualityTest.java
+++ b/libraries/ldpath/ldpath-core/src/main/java/org/apache/marmotta/ldpath/model/tests/PathEqualityTest.java
@@ -36,8 +36,8 @@ import org.apache.marmotta.ldpath.api.tests.NodeTest;
  */
 public class PathEqualityTest<Node> extends NodeTest<Node> {
 
-    private NodeSelector<Node> path;
-    private Node node;
+    private final NodeSelector<Node> path;
+    protected final Node node;
 
 
     public PathEqualityTest(NodeSelector<Node> path, Node node) {

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/6c82a02a/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj b/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj
index 2b05cb6..66223f5 100644
--- a/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj
+++ b/libraries/ldpath/ldpath-core/src/main/javacc/at/newmedialab/ldpath/parser/rdfpath.jj
@@ -970,7 +970,7 @@ PathEqualityTest TypeTest() :
 }
 {
     <IS_A> node = Node() {
-        return new PathEqualityTest(new PropertySelector(resolveResource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")), node);
+        return new IsATest(resolveResource("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), node);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/6c82a02a/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java b/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java
index 3f1ec3a..321705b 100644
--- a/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java
+++ b/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/SelectorsTest.java
@@ -21,7 +21,7 @@ import org.junit.runners.Parameterized.Parameters;
 @RunWith(Parameterized.class)
 public class SelectorsTest {
 
-    @Parameters(name = "{1}Selector")
+    @Parameters(name = "{index}: {1}Selector")
     public static List<String[]> testCases() {
         return Arrays.asList(new String[][] {
                 {"*", "Wildcard"},

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/6c82a02a/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/TestsTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/TestsTest.java b/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/TestsTest.java
index 845f138..df5410a 100644
--- a/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/TestsTest.java
+++ b/libraries/ldpath/ldpath-core/src/test/java/org/apache/marmotta/ldpath/parser/TestsTest.java
@@ -21,7 +21,7 @@ import org.junit.runners.Parameterized.Parameters;
 @RunWith(Parameterized.class)
 public class TestsTest {
 
-    @Parameters(name = "{1}Test")
+    @Parameters(name = "{index}: {1}Test")
     public static List<String[]> testCases() {
         return Arrays.asList(new String[][] {
                 {"<http://foo.bar> & <http://bar.foo>", "And"},
@@ -31,7 +31,7 @@ public class TestsTest {
                 {"!@en", "Not"},
                 {"<http://foo.bar> | <http://bar.foo>", "Or"},
                 {"<http://www.example.com/> is <http://foo.bar>", "PathEquality"},
-                {"is-a <http://foo.bar>", "PathEquality"},
+                {"is-a <http://foo.bar>", "IsA"},
                 {"<http://www.example.com/>", "Path"},
                 });
     }