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/07/16 15:27:51 UTC

git commit: Implemented String-Test-Functions for LDPath (MARMOTTA-273)

Updated Branches:
  refs/heads/develop 3160eac3f -> b918d64ee


Implemented String-Test-Functions for LDPath (MARMOTTA-273)


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

Branch: refs/heads/develop
Commit: b918d64ee4570b8fa3bf12fc21ecbd45afbafcfd
Parents: 3160eac
Author: Jakob Frank <ja...@apache.org>
Authored: Tue Jul 16 15:26:36 2013 +0200
Committer: Jakob Frank <ja...@apache.org>
Committed: Tue Jul 16 15:26:36 2013 +0200

----------------------------------------------------------------------
 .../text/AbstractBinaryStringTest.java          |  59 ++++++
 .../functions/text/AbstractStringTest.java      | 101 +++++++++++
 .../functions/text/StringContainsTest.java      |  42 +++++
 .../functions/text/StringEndsWithTest.java      |  44 +++++
 .../tests/functions/text/StringEqualsIC.java    |  42 +++++
 .../tests/functions/text/StringEqualsTest.java  |  42 +++++
 .../tests/functions/text/StringIsEmptyTest.java |  61 +++++++
 .../functions/text/StringStartsWithTest.java    |  44 +++++
 ...e.marmotta.ldpath.api.functions.TestFunction |   6 +
 .../tests/functions/text/StringTestTest.java    | 181 +++++++++++++++++++
 10 files changed, 622 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/AbstractBinaryStringTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/AbstractBinaryStringTest.java b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/AbstractBinaryStringTest.java
new file mode 100644
index 0000000..a873c0d
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/AbstractBinaryStringTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.functions.text;
+
+import java.util.Collection;
+
+import com.google.common.collect.Collections2;
+
+/**
+ * Abstract base class for binary string tests.
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+public abstract class AbstractBinaryStringTest<Node> extends AbstractStringTest<Node> {
+
+    @Override
+    protected boolean test(AbstractStringTest<Node>.ToStringFunction toStringFunction, Collection<Node>... args) {
+        final Collection<Node> l = args[0], r = args[1];
+        
+        try {
+            for (String first: Collections2.transform(l, toStringFunction)) {
+                for (String second: Collections2.transform(r, toStringFunction)) {
+                    if (!test(first, second)) return false;
+                }
+            }
+            return true;
+        } catch (IllegalArgumentException e) {
+            return false;
+        }
+    }
+
+    /**
+     * Do the test.
+     * @param first the first (left) argument
+     * @param second the second (right) argument
+     */
+    protected abstract boolean test(String first, String second);
+    
+    @Override
+    protected final int getArgCount() {
+        return 2;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/AbstractStringTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/AbstractStringTest.java b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/AbstractStringTest.java
new file mode 100644
index 0000000..306e78f
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/AbstractStringTest.java
@@ -0,0 +1,101 @@
+/**
+ * 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.functions.text;
+
+import java.util.Collection;
+
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+import org.apache.marmotta.ldpath.api.functions.TestFunction;
+import org.apache.marmotta.ldpath.model.transformers.StringTransformer;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+
+/**
+ * Abstract base class for LDPath Test functions that work on the string representation of nodes.
+ * @author Jakob Frank <ja...@apache.org>
+ * @see TestFunction
+ */
+public abstract class AbstractStringTest<Node> extends TestFunction<Node> {
+
+    protected final StringTransformer<Node> transformer = new StringTransformer<Node>();
+
+    @Override
+    public Boolean apply(RDFBackend<Node> backend, Node context,
+            Collection<Node>... args) throws IllegalArgumentException {
+
+        if (args.length != getArgCount()) { throw new IllegalArgumentException(getLocalName() + " requires exactly " + getArgCount() + " arguments"); }
+
+        return test(new ToStringFunction(backend), args);
+    }
+
+    /**
+     * 
+     * @param toStringFunction
+     * @param args
+     */
+    protected abstract boolean test(ToStringFunction toStringFunction, Collection<Node>... args);
+
+    /**
+     * The signature of this functions (how to use it)
+     */
+    @Override
+    public String getSignature() {
+        return "fn:" + getLocalName() + "(" + getArgSignature() + ") :: Boolean";
+    }
+
+    private String getArgSignature() {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < getArgCount(); i++) {
+            if (i > 0)
+                sb.append(", ");
+            sb.append("Node ").append('a' + i);
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Number of (required) arguments this function accepts.
+     * @return
+     */
+    protected abstract int getArgCount();
+
+    /**
+     * A function for the guava-library to convert a node into a string based on
+     * the backend provided in the constructor.
+     * 
+     * @author Jakob Frank <ja...@apache.org>
+     * @see Collections2
+     * @see Function
+     */
+    protected class ToStringFunction implements Function<Node, String> {
+        private final RDFBackend<Node> backend;
+
+        /**
+         * @param backend the RDFBackend to use for transformation
+         */
+        public ToStringFunction(RDFBackend<Node> backend) {
+            this.backend = backend;
+        }
+
+        @Override
+        public String apply(Node n) {
+            return transformer.transform(backend, n, null);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringContainsTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringContainsTest.java b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringContainsTest.java
new file mode 100644
index 0000000..0714c3a
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringContainsTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.functions.text;
+
+/**
+ * Check if one string is contained within an other.
+ * @author Jakob Frank <ja...@apache.org>
+ * @see String#contains(CharSequence)
+ */
+public class StringContainsTest<Node> extends AbstractBinaryStringTest<Node> {
+
+    @Override
+    public String getDescription() {
+        return "Checks if the first string contains the second";
+    }
+
+    @Override
+    protected boolean test(String first, String second) {
+        return first != null && second != null && first.contains(second);
+    }
+
+    @Override
+    public String getLocalName() {
+        return "contains";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEndsWithTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEndsWithTest.java b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEndsWithTest.java
new file mode 100644
index 0000000..a7e64c8
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEndsWithTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.functions.text;
+
+import org.apache.marmotta.ldpath.model.tests.functions.text.AbstractBinaryStringTest;
+
+/**
+ * Check if one string ends with the other.
+ * @author Jakob Frank <ja...@apache.org>
+ * @see String#endsWith(String)
+ */
+public class StringEndsWithTest<Node> extends AbstractBinaryStringTest<Node> {
+
+    @Override
+    public String getDescription() {
+        return "Checks if the first string ends the second";
+    }
+
+    @Override
+    protected boolean test(String first, String second) {
+        return first != null && second != null && first.endsWith(second);
+    }
+
+    @Override
+    public String getLocalName() {
+        return "endsWith";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEqualsIC.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEqualsIC.java b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEqualsIC.java
new file mode 100644
index 0000000..bd2e385
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEqualsIC.java
@@ -0,0 +1,42 @@
+/**
+ * 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.functions.text;
+
+/**
+ * Check two strings for equality, ignoring case considerations.
+ * @author Jakob Frank <ja...@apache.org>
+ * @see String#equalsIgnoreCase(String)
+ */
+public class StringEqualsIC<Node> extends AbstractBinaryStringTest<Node> {
+
+    @Override
+    public String getDescription() {
+        return "Checks the provided arguments for equality (string representation, ignoring case considerations)";
+    }
+
+    @Override
+    protected boolean test(String first, String second) {
+        return first==null?second==null:first.equalsIgnoreCase(second);
+    }
+
+    @Override
+    public String getLocalName() {
+        return "equalsIgnoreCase";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEqualsTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEqualsTest.java b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEqualsTest.java
new file mode 100644
index 0000000..816704a
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringEqualsTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.functions.text;
+
+/**
+ * Check two strings for equality.
+ * @author Jakob Frank <ja...@apache.org>
+ * @see String#equals(Object)
+ */
+public class StringEqualsTest<Node> extends AbstractBinaryStringTest<Node> {
+
+    @Override
+    public String getDescription() {
+        return "Checks the provided arguments for equality (string representation)";
+    }
+
+    @Override
+    protected boolean test(String first, String second) {
+        return first==null?second==null:first.equals(second);
+    }
+
+    @Override
+    public String getLocalName() {
+        return "equals";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringIsEmptyTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringIsEmptyTest.java b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringIsEmptyTest.java
new file mode 100644
index 0000000..aa2c421
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringIsEmptyTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.functions.text;
+
+import java.util.Collection;
+
+import com.google.common.collect.Collections2;
+
+/**
+ * LDPath test function to check if the string representation of an node is empty.
+ * 
+ * @author Jakob Frank <ja...@apache.org>
+ *
+ */
+public class StringIsEmptyTest<Node> extends AbstractStringTest<Node> {
+
+    @Override
+    public String getDescription() {
+        return "Check if the string representation of the node is empty";
+    }
+
+    @Override
+    protected boolean test(AbstractStringTest<Node>.ToStringFunction toStringFunction, Collection<Node>... args) {
+        try {
+            for (String str: Collections2.transform(args[0], toStringFunction)) {
+                if (!str.isEmpty()) return false;
+            }
+            
+            return true;
+        } catch (IllegalArgumentException e) {
+            return false;
+        }
+        
+    }
+
+    @Override
+    protected final int getArgCount() {
+        return 1;
+    }
+
+    @Override
+    public String getLocalName() {
+        return "isEmpty";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringStartsWithTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringStartsWithTest.java b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringStartsWithTest.java
new file mode 100644
index 0000000..a7f2ab8
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/main/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringStartsWithTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.functions.text;
+
+import org.apache.marmotta.ldpath.model.tests.functions.text.AbstractBinaryStringTest;
+
+/**
+ * Check if one string starts with the other.
+ * @author Jakob Frank <ja...@apache.org>
+ * @see String#startsWith(String)
+ */
+public class StringStartsWithTest<Node> extends AbstractBinaryStringTest<Node> {
+
+    @Override
+    public String getDescription() {
+        return "Checks if the first string starts the second";
+    }
+
+    @Override
+    protected boolean test(String first, String second) {
+        return first != null && second != null && first.startsWith(second);
+    }
+
+    @Override
+    public String getLocalName() {
+        return "startsWith";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.TestFunction
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.TestFunction b/libraries/ldpath/ldpath-functions-text/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.TestFunction
new file mode 100644
index 0000000..444c898
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/main/resources/META-INF/services/org.apache.marmotta.ldpath.api.functions.TestFunction
@@ -0,0 +1,6 @@
+org.apache.marmotta.ldpath.model.tests.functions.text.StringIsEmptyTest
+org.apache.marmotta.ldpath.model.tests.functions.text.StringEqualsTest
+org.apache.marmotta.ldpath.model.tests.functions.text.StringEqualsIC
+org.apache.marmotta.ldpath.model.tests.functions.text.StringContainsTest
+org.apache.marmotta.ldpath.model.tests.functions.text.StringStartsWithTest
+org.apache.marmotta.ldpath.model.tests.functions.text.StringEndsWithTest
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/b918d64e/libraries/ldpath/ldpath-functions-text/src/test/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringTestTest.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-functions-text/src/test/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringTestTest.java b/libraries/ldpath/ldpath-functions-text/src/test/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringTestTest.java
new file mode 100644
index 0000000..713508f
--- /dev/null
+++ b/libraries/ldpath/ldpath-functions-text/src/test/java/org/apache/marmotta/ldpath/model/tests/functions/text/StringTestTest.java
@@ -0,0 +1,181 @@
+/**
+ * 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.functions.text;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+
+import org.apache.marmotta.ldpath.api.tests.NodeTest;
+import org.apache.marmotta.ldpath.parser.ParseException;
+import org.apache.marmotta.ldpath.parser.RdfPathParser;
+import org.apache.marmotta.ldpath.test.AbstractTestBase;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.repository.sail.SailRepositoryConnection;
+
+@RunWith(Parameterized.class)
+public class StringTestTest extends AbstractTestBase {
+    
+    @Parameters(name = "Case-{index}")
+    public static List<String[]> data() {
+        return Arrays.asList(
+                new String[] { "Welcome to The Apache Software Foundation!" },
+                new String[] { "Apache Marmotta (incubator) is an Open Platform for Linked Data" }
+                );
+    }
+    private static Random rnd;
+    
+    @Parameter
+    public String text;
+    
+    private int textLen;
+    
+    private int testWindow;
+    
+    private String errSalt;
+    
+    private URI subject, predicate;
+
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        rnd = new Random();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() throws Exception {
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        textLen = text.length();
+        Assert.assertTrue(textLen > 4);
+        testWindow = 1+rnd.nextInt((textLen / 4));
+        
+        errSalt = UUID.randomUUID().toString();
+        
+        subject = repository.getValueFactory().createURI(ns("foo", UUID.randomUUID().toString()));
+        predicate = repository.getValueFactory().createURI(ns("foo", UUID.randomUUID().toString()));
+
+        final SailRepositoryConnection con = repository.getConnection();
+        try {
+            final ValueFactory vf = con.getValueFactory();
+
+            con.add(vf.createStatement(subject, predicate, vf.createLiteral(text)));
+
+            con.commit();
+        } finally {
+            con.close();
+        }
+    }
+
+    @After
+    public void tearDown() throws Exception {
+    }
+    
+    private boolean checkTest(String ldPathTest, URI context) throws ParseException {
+        final RdfPathParser<Value> parser = createParserFromString(ldPathTest);
+        final NodeTest<Value> test = parser.parseTest(NSS);
+        return test.accept(backend, context, context);
+    }
+
+    @Test
+    public void testEquals() throws ParseException {
+        final String ldPath_T = String.format("fn:equals(<%s>, \"%s\")", predicate.stringValue(), text);
+        final String ldPath_F = String.format("fn:equals(<%s>, \"%s\")", predicate.stringValue(), errSalt);
+
+        Assert.assertTrue(checkTest(ldPath_T, subject));
+        Assert.assertFalse(checkTest(ldPath_F, subject));
+    }
+
+    @Test
+    public void testEqualsIgnoreCase() throws ParseException {
+        final String ldPath_T = String.format("fn:equalsIgnoreCase(<%s>, \"%s\")", predicate.stringValue(), text);
+        final String ldPath_T_LC = String.format("fn:equalsIgnoreCase(<%s>, \"%s\")", predicate.stringValue(), text.toLowerCase());
+        final String ldPath_T_UC = String.format("fn:equalsIgnoreCase(<%s>, \"%s\")", predicate.stringValue(), text.toUpperCase());
+
+        final String ldPath_F = String.format("fn:equalsIgnoreCase(<%s>, \"%s\")", predicate.stringValue(), errSalt);
+        final String ldPath_F_LC = String.format("fn:equalsIgnoreCase(<%s>, \"%s\")", predicate.stringValue(), errSalt.toLowerCase());
+        final String ldPath_F_UC = String.format("fn:equalsIgnoreCase(<%s>, \"%s\")", predicate.stringValue(), errSalt.toUpperCase());
+
+        Assert.assertTrue(checkTest(ldPath_T, subject));
+        Assert.assertTrue(checkTest(ldPath_T_LC, subject));
+        Assert.assertTrue(checkTest(ldPath_T_UC, subject));
+        
+        Assert.assertFalse(checkTest(ldPath_F, subject));
+        Assert.assertFalse(checkTest(ldPath_F_LC, subject));
+        Assert.assertFalse(checkTest(ldPath_F_UC, subject));
+    }
+
+    @Test
+    public void testContains() throws ParseException {
+        final String ldPath_T1 = String.format("fn:contains(<%s>, \"%s\")", predicate.stringValue(), text.substring(textLen/2-testWindow, textLen/2+testWindow));
+        final String ldPath_T2 = String.format("fn:contains(<%s>, \"%s\")", predicate.stringValue(), text.substring(textLen-testWindow));
+        final String ldPath_T3 = String.format("fn:contains(<%s>, \"%s\")", predicate.stringValue(), text.substring(0,testWindow));
+        final String ldPath_F = String.format("fn:contains(<%s>, \"%s\")", predicate.stringValue(), UUID.randomUUID().toString());
+
+        Assert.assertTrue(checkTest(ldPath_T1, subject));
+        Assert.assertTrue(checkTest(ldPath_T2, subject));
+        Assert.assertTrue(checkTest(ldPath_T3, subject));
+        Assert.assertFalse(checkTest(ldPath_F, subject));
+    }
+
+    @Test
+    public void testEndsWith() throws ParseException {
+        final String ldPath_S = String.format("fn:endsWith(<%s>, \"%s\")", predicate.stringValue(), text.substring(0,testWindow));
+        final String ldPath_M = String.format("fn:endsWith(<%s>, \"%s\")", predicate.stringValue(), text.substring(textLen/2-testWindow, textLen/2+testWindow));
+        final String ldPath_E = String.format("fn:endsWith(<%s>, \"%s\")", predicate.stringValue(), text.substring(textLen-testWindow));
+
+        Assert.assertFalse(checkTest(ldPath_S, subject));
+        Assert.assertFalse(checkTest(ldPath_M, subject));
+        Assert.assertTrue(checkTest(ldPath_E, subject));
+    }
+
+    @Test
+    public void testStartsWith() throws ParseException {
+        final String ldPath_S = String.format("fn:startsWith(<%s>, \"%s\")", predicate.stringValue(), text.substring(0,testWindow));
+        final String ldPath_M = String.format("fn:startsWith(<%s>, \"%s\")", predicate.stringValue(), text.substring(textLen/2-testWindow, textLen/2+testWindow));
+        final String ldPath_E = String.format("fn:startsWith(<%s>, \"%s\")", predicate.stringValue(), text.substring(textLen-testWindow));
+
+        Assert.assertTrue(checkTest(ldPath_S, subject));
+        Assert.assertFalse(checkTest(ldPath_M, subject));
+        Assert.assertFalse(checkTest(ldPath_E, subject));
+    }
+
+    @Test
+    public void testIsEmpty() throws ParseException {
+        final String ldPath_T = "fn:isEmpty(\"\")";
+        final String ldPath_F = String.format("fn:isEmpty(<%s>)", predicate.stringValue());
+        
+        Assert.assertTrue(checkTest(ldPath_T, subject));
+        Assert.assertFalse(checkTest(ldPath_F, subject));
+    }
+
+}