[Mulgara-svn] r759 - branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value
pag at mulgara.org
pag at mulgara.org
Thu Apr 10 21:41:09 UTC 2008
Author: pag
Date: 2008-04-10 14:41:08 -0700 (Thu, 10 Apr 2008)
New Revision: 759
Added:
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/LangFnUnitTest.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/StrFnUnitTest.java
Log:
New passing tests
Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/LangFnUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/LangFnUnitTest.java (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/LangFnUnitTest.java 2008-04-10 21:41:08 UTC (rev 759)
@@ -0,0 +1,148 @@
+/**
+ * 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.value;
+
+import static org.mulgara.query.filter.value.TypedLiteral.XSD_NS;
+
+import java.net.URI;
+
+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 junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Tests the language function class.
+ *
+ * @created Apr 10, 2008
+ * @author Paul Gearon
+ * @copyright © 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 LangFnUnitTest extends TestCase {
+
+ /**
+ * Build the unit test.
+ * @param name The name of the test
+ */
+ public LangFnUnitTest(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 LangFnUnitTest("testValues"));
+ suite.addTest(new LangFnUnitTest("testVar"));
+ return suite;
+ }
+
+
+ public void testValues() throws Exception {
+ String str = "test";
+ URI t = URI.create(XSD_NS + "string");
+ ValueLiteral l = TypedLiteral.newLiteral(str, t, null);
+
+ LangFn fn = new LangFn(l);
+
+ assertTrue(fn.equals(SimpleLiteral.EMPTY));
+ assertFalse(fn.isBlank());
+ assertFalse(fn.isIRI());
+ assertTrue(fn.isLiteral());
+ assertFalse(fn.isURI());
+ assertEquals(SimpleLiteral.STRING_TYPE, fn.getType());
+ assertEquals(SimpleLiteral.EMPTY, fn.getLang());
+
+ l = TypedLiteral.newLiteral(str, null, "en");
+ fn = new LangFn(l);
+ SimpleLiteral lang = new SimpleLiteral("en");
+ assertTrue(fn.equals(lang));
+ assertFalse(fn.isBlank());
+ assertFalse(fn.isIRI());
+ assertTrue(fn.isLiteral());
+ assertFalse(fn.isURI());
+
+ l = TypedLiteral.newLiteral(new Integer(42));
+ fn = new LangFn(l);
+ assertTrue(fn.equals(SimpleLiteral.EMPTY));
+ assertFalse(fn.isBlank());
+ assertFalse(fn.isIRI());
+ assertTrue(fn.isLiteral());
+ assertFalse(fn.isURI());
+
+ IRI i = new IRI(URI.create("foo:bar"));
+ fn = new LangFn(i);
+ try {
+ fn.equals(SimpleLiteral.EMPTY);
+ fail("Got a language from a URI");
+ } catch (QueryException qe) { }
+ }
+
+ public void testVar() throws Exception {
+ String vName = "foo";
+ Var v = new Var(vName);
+ LangFn fn = new LangFn(v);
+
+ URI xsdString = URI.create(XSD_NS + "string");
+ URI xsdDouble = URI.create(XSD_NS + "double");
+ URI fooBar = URI.create("foo:bar");
+ Node[][] rows = {
+ new Node[] {new LiteralImpl("foo")},
+ new Node[] {new LiteralImpl("foo", xsdString)},
+ new Node[] {new LiteralImpl("5.0", xsdDouble)},
+ new Node[] {new LiteralImpl("foo", "en")},
+ new Node[] {new LiteralImpl("foo", fooBar)},
+ new Node[] {new URIReferenceImpl(fooBar)},
+ new Node[] {new BlankNodeImpl()},
+ };
+ TestContext c = new TestContext(new String[] {vName}, rows);
+ c.beforeFirst();
+ fn.setContextOwner(new TestContextOwner(c));
+
+ // check the context setting
+ fn.setCurrentContext(c);
+
+ assertTrue(c.next());
+ assertEquals("", fn.getValue());
+ assertTrue(c.next());
+ assertEquals("", fn.getValue());
+ assertTrue(c.next());
+ assertEquals("", fn.getValue());
+ assertTrue(c.next());
+ assertEquals("en", fn.getValue());
+ assertTrue(c.next());
+ assertEquals("", fn.getValue());
+ assertTrue(c.next());
+ try {
+ Object o = fn.getValue();
+ fail("Got the language of a URI reference: " + o);
+ } catch (QueryException qe) { }
+ assertTrue(c.next());
+ try {
+ Object o = fn.getValue();
+ fail("Got the language of a Blank Node: " + o);
+ } catch (QueryException qe) { }
+ assertFalse(c.next());
+ }
+
+}
Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/StrFnUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/StrFnUnitTest.java (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/StrFnUnitTest.java 2008-04-10 21:41:08 UTC (rev 759)
@@ -0,0 +1,142 @@
+/**
+ * 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.value;
+
+import static org.mulgara.query.filter.value.TypedLiteral.XSD_NS;
+
+import java.net.URI;
+
+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 junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+/**
+ * Tests the string function class.
+ *
+ * @created Apr 10, 2008
+ * @author Paul Gearon
+ * @copyright © 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 StrFnUnitTest extends TestCase {
+
+ /**
+ * Build the unit test.
+ * @param name The name of the test
+ */
+ public StrFnUnitTest(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 StrFnUnitTest("testValues"));
+ suite.addTest(new StrFnUnitTest("testVar"));
+ return suite;
+ }
+
+
+ public void testValues() throws Exception {
+ String str = "test";
+ SimpleLiteral strLiteral = new SimpleLiteral(str);
+ URI t = URI.create(XSD_NS + "string");
+ ValueLiteral l = TypedLiteral.newLiteral(str, t, null);
+
+ StrFn fn = new StrFn(l);
+
+ assertTrue(fn.equals(strLiteral));
+ assertFalse(fn.isBlank());
+ assertFalse(fn.isIRI());
+ assertTrue(fn.isLiteral());
+ assertFalse(fn.isURI());
+ assertEquals(SimpleLiteral.STRING_TYPE, fn.getType());
+ assertEquals(SimpleLiteral.EMPTY, fn.getLang());
+
+ l = TypedLiteral.newLiteral(str, null, "en");
+ fn = new StrFn(l);
+ assertTrue(fn.equals(strLiteral));
+ assertFalse(fn.isBlank());
+ assertFalse(fn.isIRI());
+ assertTrue(fn.isLiteral());
+ assertFalse(fn.isURI());
+
+ l = TypedLiteral.newLiteral(new Integer(42));
+ fn = new StrFn(l);
+ assertTrue(fn.equals(new SimpleLiteral("42")));
+ assertFalse(fn.isBlank());
+ assertFalse(fn.isIRI());
+ assertTrue(fn.isLiteral());
+ assertFalse(fn.isURI());
+
+ IRI i = new IRI(URI.create("foo:bar"));
+ fn = new StrFn(i);
+ fn.equals(new SimpleLiteral("foo:bar"));
+ }
+
+ public void testVar() throws Exception {
+ String vName = "foo";
+ Var v = new Var(vName);
+ StrFn fn = new StrFn(v);
+
+ URI xsdString = URI.create(XSD_NS + "string");
+ URI xsdDouble = URI.create(XSD_NS + "double");
+ URI fooBar = URI.create("foo:bar");
+ Node[][] rows = {
+ new Node[] {new LiteralImpl("foo")},
+ new Node[] {new LiteralImpl("foo", xsdString)},
+ new Node[] {new LiteralImpl("5.0", xsdDouble)},
+ new Node[] {new LiteralImpl("foo", "en")},
+ new Node[] {new LiteralImpl("foo", fooBar)},
+ new Node[] {new URIReferenceImpl(fooBar)},
+ new Node[] {new BlankNodeImpl()},
+ };
+ TestContext c = new TestContext(new String[] {vName}, rows);
+ c.beforeFirst();
+ fn.setContextOwner(new TestContextOwner(c));
+
+ // check the context setting
+ fn.setCurrentContext(c);
+
+ assertTrue(c.next());
+ assertEquals("foo", fn.getValue());
+ assertTrue(c.next());
+ assertEquals("foo", fn.getValue());
+ assertTrue(c.next());
+ assertEquals("5.0", fn.getValue());
+ assertTrue(c.next());
+ assertEquals("foo", fn.getValue());
+ assertTrue(c.next());
+ assertEquals("foo", fn.getValue());
+ assertTrue(c.next());
+ assertEquals("foo:bar", fn.getValue());
+ assertTrue(c.next());
+ try {
+ Object o = fn.getValue();
+ fail("Got the string from a Blank Node: " + o);
+ } catch (QueryException qe) { }
+ assertFalse(c.next());
+ }
+
+}
More information about the Mulgara-svn
mailing list