[Mulgara-svn] r791 - branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter

pag at mulgara.org pag at mulgara.org
Tue Apr 15 21:10:17 UTC 2008


Author: pag
Date: 2008-04-15 14:10:17 -0700 (Tue, 15 Apr 2008)
New Revision: 791

Added:
   branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractIsIriFnUnitTest.java
   branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BoundFnUnitTest.java
   branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsBlankFnUnitTest.java
   branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsIRIFnUnitTest.java
   branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsLiteralFnUnitTest.java
   branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsURIFnUnitTest.java
Log:
Tests for all the "SPARQL Tests"

Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractIsIriFnUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractIsIriFnUnitTest.java	                        (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractIsIriFnUnitTest.java	2008-04-15 21:10:17 UTC (rev 791)
@@ -0,0 +1,88 @@
+package org.mulgara.query.filter;
+
+import static org.mulgara.query.filter.value.TypedLiteral.XSD_NS;
+
+import java.net.URI;
+
+import org.jrdf.graph.Literal;
+import org.jrdf.graph.Node;
+import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.value.Bool;
+import org.mulgara.query.filter.value.IRI;
+import org.mulgara.query.filter.value.Var;
+import org.mulgara.query.rdf.LiteralImpl;
+import org.mulgara.query.rdf.URIReferenceImpl;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the isURI and isIRI functions.
+ *
+ * @created Apr 15, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public abstract class AbstractIsIriFnUnitTest extends TestCase {
+
+  protected URI xsdInt = URI.create(XSD_NS + "int");
+  Bool t = Bool.TRUE;
+  Bool f = Bool.FALSE;
+
+  public AbstractIsIriFnUnitTest(String name) {
+    super(name);
+  }
+
+  abstract public AbstractFilterValue createFn(RDFTerm arg);
+  
+  public void testLiteral() throws Exception {
+    AbstractFilterValue fn = createFn(t);
+    assertTrue(f.equals(fn));
+    assertTrue(fn.equals(f));
+  
+    fn = createFn(new IRI(URI.create("foo:bar")));
+    assertTrue(t.equals(fn));
+    assertTrue(fn.equals(t));
+  
+    fn = createFn(t.getType());
+    assertTrue(t.equals(fn));
+    assertTrue(fn.equals(t));
+  }
+
+  public void testVar() throws Exception {
+    Var x = new Var("x");
+    AbstractFilterValue fn = createFn(x);
+  
+    Literal seven = new LiteralImpl("7", xsdInt);
+    Node[][] rows = {
+      new Node[] {seven},
+      new Node[] {null},
+      new Node[] {new URIReferenceImpl(xsdInt)}
+    };
+    TestContext c = new TestContext(new String[] {"x"}, rows);
+    c.beforeFirst();
+    fn.setContextOwner(new TestContextOwner(c));
+  
+    // check the context setting
+    fn.setCurrentContext(c);
+  
+    assertTrue(c.next());
+    assertTrue(f.equals(fn));
+    assertTrue(fn.equals(f));
+  
+    assertTrue(c.next());
+    try {
+      assertTrue(f.equals(fn));
+      fail("No exception when testing an unbound value");
+    } catch (QueryException qe) {
+      assertTrue(qe.getMessage().startsWith("Unbound column"));
+    }
+  
+    assertTrue(c.next());
+    assertTrue(t.equals(fn));
+    assertTrue(fn.equals(t));
+  
+    assertFalse(c.next());
+  }
+
+}
\ No newline at end of file

Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BoundFnUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BoundFnUnitTest.java	                        (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BoundFnUnitTest.java	2008-04-15 21:10:17 UTC (rev 791)
@@ -0,0 +1,133 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.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.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+import java.net.URI;
+
+import org.jrdf.graph.Literal;
+import org.jrdf.graph.Node;
+import org.mulgara.query.filter.TestContext;
+import org.mulgara.query.filter.TestContextOwner;
+import org.mulgara.query.rdf.BlankNodeImpl;
+import org.mulgara.query.rdf.LiteralImpl;
+
+import org.mulgara.query.filter.value.Bool;
+import org.mulgara.query.filter.value.Var;
+
+import static org.mulgara.query.filter.value.TypedLiteral.XSD_NS;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Tests the BOUND function.
+ *
+ * @created Apr 15, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class BoundFnUnitTest extends TestCase {
+
+  protected URI xsdInt = URI.create(XSD_NS + "int");
+  Bool t = Bool.TRUE;
+  Bool f = Bool.FALSE;
+
+  /**
+   * Build the unit test.
+   * @param name The name of the test
+   */
+  public BoundFnUnitTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Hook for test runner to obtain a test suite from.
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new BoundFnUnitTest("testVar"));
+    suite.addTest(new BoundFnUnitTest("testGuard"));
+    return suite;
+  }
+
+  public void testVar() throws Exception {
+    Var x = new Var("x");
+    BoundFn fn = new BoundFn(x);
+
+    Literal seven = new LiteralImpl("7", xsdInt);
+    Node[][] rows = {
+      new Node[] {seven},
+      new Node[] {null},
+      new Node[] {seven},
+      new Node[] {null},
+    };
+    TestContext c = new TestContext(new String[] {"x"}, rows);
+    c.beforeFirst();
+    fn.setContextOwner(new TestContextOwner(c));
+
+    // check the context setting
+    fn.setCurrentContext(c);
+
+    assertTrue(c.next());
+    assertTrue(t.equals(fn));
+    assertTrue(fn.equals(t));
+
+    assertTrue(c.next());
+    assertTrue(f.equals(fn));
+    assertTrue(fn.equals(f));
+
+    assertTrue(c.next());
+    assertTrue(t.equals(fn));
+
+    assertTrue(c.next());
+    assertTrue(f.equals(fn));
+
+    assertFalse(c.next());
+  }
+  
+  public void testGuard() throws Exception {
+    Var x = new Var("x");
+    AbstractFilterValue fn = new And(new BoundFn(x), new IsBlankFn(x));
+
+    Literal seven = new LiteralImpl("7", xsdInt);
+    Node[][] rows = {
+      new Node[] {seven},
+      new Node[] {null},
+      new Node[] {new BlankNodeImpl(101)},
+    };
+    TestContext c = new TestContext(new String[] {"x"}, rows);
+    c.beforeFirst();
+    fn.setContextOwner(new TestContextOwner(c));
+
+    // check the context setting
+    fn.setCurrentContext(c);
+
+    assertTrue(c.next());
+    assertTrue(f.equals(fn));
+    assertTrue(fn.equals(f));
+
+    assertTrue(c.next());
+    assertTrue(f.equals(fn));
+    assertTrue(fn.equals(f));
+
+    assertTrue(c.next());
+    assertTrue(t.equals(fn));
+    assertTrue(fn.equals(t));
+
+    assertFalse(c.next());
+  }
+  
+}

Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsBlankFnUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsBlankFnUnitTest.java	                        (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsBlankFnUnitTest.java	2008-04-15 21:10:17 UTC (rev 791)
@@ -0,0 +1,114 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.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.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+import java.net.URI;
+
+import org.jrdf.graph.Literal;
+import org.jrdf.graph.Node;
+import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.TestContext;
+import org.mulgara.query.filter.TestContextOwner;
+import org.mulgara.query.rdf.BlankNodeImpl;
+import org.mulgara.query.rdf.LiteralImpl;
+
+import org.mulgara.query.filter.value.BlankNodeValue;
+import org.mulgara.query.filter.value.Bool;
+import org.mulgara.query.filter.value.Var;
+
+import static org.mulgara.query.filter.value.TypedLiteral.XSD_NS;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Tests the isBlank function.
+ *
+ * @created Apr 15, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class IsBlankFnUnitTest extends TestCase {
+
+  protected URI xsdInt = URI.create(XSD_NS + "int");
+  Bool t = Bool.TRUE;
+  Bool f = Bool.FALSE;
+
+  /**
+   * Build the unit test.
+   * @param name The name of the test
+   */
+  public IsBlankFnUnitTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Hook for test runner to obtain a test suite from.
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new NotUnitTest("testLiteral"));
+    suite.addTest(new IsBlankFnUnitTest("testVar"));
+    return suite;
+  }
+
+  public void testLiteral() throws Exception {
+    IsBlankFn fn = new IsBlankFn(t);
+    assertTrue(f.equals(fn));
+    assertTrue(fn.equals(f));
+
+    fn = new IsBlankFn(new BlankNodeValue(new BlankNodeImpl(101)));
+    assertTrue(t.equals(fn));
+    assertTrue(fn.equals(t));
+  }
+
+  public void testVar() throws Exception {
+    Var x = new Var("x");
+    IsBlankFn fn = new IsBlankFn(x);
+
+    Literal seven = new LiteralImpl("7", xsdInt);
+    Node[][] rows = {
+      new Node[] {seven},
+      new Node[] {null},
+      new Node[] {new BlankNodeImpl(101)}
+    };
+    TestContext c = new TestContext(new String[] {"x"}, rows);
+    c.beforeFirst();
+    fn.setContextOwner(new TestContextOwner(c));
+
+    // check the context setting
+    fn.setCurrentContext(c);
+
+    assertTrue(c.next());
+    assertTrue(f.equals(fn));
+    assertTrue(fn.equals(f));
+
+    assertTrue(c.next());
+    try {
+      assertTrue(f.equals(fn));
+      fail("No exception when testing an unbound value");
+    } catch (QueryException qe) {
+      assertTrue(qe.getMessage().startsWith("Unbound column"));
+    }
+
+    assertTrue(c.next());
+    assertTrue(t.equals(fn));
+    assertTrue(fn.equals(t));
+
+    assertFalse(c.next());
+  }
+  
+}

Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsIRIFnUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsIRIFnUnitTest.java	                        (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsIRIFnUnitTest.java	2008-04-15 21:10:17 UTC (rev 791)
@@ -0,0 +1,51 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.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.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Tests the isIRI function.
+ *
+ * @created Apr 15, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class IsIRIFnUnitTest extends AbstractIsIriFnUnitTest {
+
+  /**
+   * Build the unit test.
+   * @param name The name of the test
+   */
+  public IsIRIFnUnitTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Hook for test runner to obtain a test suite from.
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new NotUnitTest("testLiteral"));
+    suite.addTest(new IsIRIFnUnitTest("testVar"));
+    return suite;
+  }
+
+  public AbstractFilterValue createFn(RDFTerm arg) {
+    return new IsIriFn(arg);
+  }
+
+}

Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsLiteralFnUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsLiteralFnUnitTest.java	                        (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsLiteralFnUnitTest.java	2008-04-15 21:10:17 UTC (rev 791)
@@ -0,0 +1,116 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.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.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+import java.net.URI;
+
+import org.jrdf.graph.Literal;
+import org.jrdf.graph.Node;
+import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.TestContext;
+import org.mulgara.query.filter.TestContextOwner;
+import org.mulgara.query.rdf.BlankNodeImpl;
+import org.mulgara.query.rdf.LiteralImpl;
+import org.mulgara.query.rdf.URIReferenceImpl;
+
+import org.mulgara.query.filter.value.Bool;
+import org.mulgara.query.filter.value.Var;
+
+import static org.mulgara.query.filter.value.TypedLiteral.XSD_NS;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Tests the isLiteral function.
+ *
+ * @created Apr 15, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class IsLiteralFnUnitTest extends TestCase {
+
+  protected URI xsdInt = URI.create(XSD_NS + "int");
+  Bool t = Bool.TRUE;
+  Bool f = Bool.FALSE;
+
+  /**
+   * Build the unit test.
+   * @param name The name of the test
+   */
+  public IsLiteralFnUnitTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Hook for test runner to obtain a test suite from.
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new IsLiteralFnUnitTest("testLiteral"));
+    suite.addTest(new IsLiteralFnUnitTest("testVar"));
+    return suite;
+  }
+
+  public void testLiteral() throws Exception {
+    IsLiteralFn fn = new IsLiteralFn(t);
+    assertTrue(t.equals(fn));
+    assertTrue(fn.equals(t));
+
+    fn = new IsLiteralFn(t.getType());
+    assertTrue(f.equals(fn));
+    assertTrue(fn.equals(f));
+  }
+
+  public void testVar() throws Exception {
+    IsLiteralFn fn = new IsLiteralFn(new Var("x"));
+
+    Literal seven = new LiteralImpl("7", xsdInt);
+    Node[][] rows = {
+      new Node[] {seven},
+      new Node[] {new URIReferenceImpl(xsdInt)},
+      new Node[] {null},
+      new Node[] {new BlankNodeImpl(101)},
+    };
+    TestContext c = new TestContext(new String[] {"x"}, rows);
+    c.beforeFirst();
+    fn.setContextOwner(new TestContextOwner(c));
+    // check the context setting
+    fn.setCurrentContext(c);
+
+    assertTrue(c.next());
+    assertTrue(t.equals(fn));
+    assertTrue(fn.equals(t));
+
+    assertTrue(c.next());
+    assertTrue(f.equals(fn));
+    assertTrue(fn.equals(f));
+
+    assertTrue(c.next());
+    try {
+      assertTrue(f.equals(fn));
+      fail("No exception when testing an unbound value");
+    } catch (QueryException qe) {
+      assertTrue(qe.getMessage().startsWith("Unbound column"));
+    }
+
+    assertTrue(c.next());
+    assertTrue(f.equals(fn));
+
+    assertFalse(c.next());
+  }
+
+}

Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsURIFnUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsURIFnUnitTest.java	                        (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsURIFnUnitTest.java	2008-04-15 21:10:17 UTC (rev 791)
@@ -0,0 +1,55 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.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.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+
+
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Tests the isURI function.
+ *
+ * @created Apr 15, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class IsURIFnUnitTest extends AbstractIsIriFnUnitTest {
+
+  /**
+   * Build the unit test.
+   * @param name The name of the test
+   */
+  public IsURIFnUnitTest(String name) {
+    super(name);
+  }
+
+  /**
+   * Hook for test runner to obtain a test suite from.
+   * @return The test suite
+   */
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTest(new NotUnitTest("testLiteral"));
+    suite.addTest(new IsURIFnUnitTest("testVar"));
+    return suite;
+  }
+
+  public AbstractFilterValue createFn(RDFTerm arg) {
+    return new IsUriFn(arg);
+  }
+
+}




More information about the Mulgara-svn mailing list