~ more comments
authorEric Prud'hommeaux <eric@w3.org>
Fri, 08 Jan 2010 08:27:15 -0500
changeset 133 e3d5b1289b8c
parent 132 3f3e829247c9
child 134 f661bcdbb2e1
~ more comments
src/test/scala/RDB2RDFTest.scala
--- a/src/test/scala/RDB2RDFTest.scala	Fri Jan 08 01:18:52 2010 -0500
+++ b/src/test/scala/RDB2RDFTest.scala	Fri Jan 08 08:27:15 2010 -0500
@@ -1,28 +1,64 @@
 /* RDB2RDFTest: transform SPARQL to SQL and compare against a reference query.
- *
- * These work with a database:
+ * $Id$
+ */
 
-Employee+----------+------------+---------+
-| empid | lastName | birthday   | manager |
-+-------+----------+------------+---------+
-|    18 | Johnson  | 1969-11-08 |    NULL |    TaskAssignments--------+
-|   253 | Smith    | 1979-01-18 |      18 |    | id | task | employee |
-|   255 | Jones    | 1981-03-24 |     253 |    +----+------+----------+
-|    19 | Xu       | 1966-11-08 |    NULL |    |  1 |    1 |       18 |
-|   254 | Ishita   | 1971-10-31 |     253 |    |  2 |    2 |      253 |
-+-------+----------+------------+---------+    |  3 |    3 |       19 |
-					       |  4 |    4 |      253 |
-Tasks----+--------+------+		       |  5 |    1 |      253 |
-| taskid | name   | lead |		       |  6 |    2 |      255 |
-+--------+--------+------+		       |  7 |    3 |      255 |
-|      1 | widget |   18 |		       |  8 |    4 |      254 |
-|      2 | dingus |  253 |		       +----+------+----------+
-|      3 | thingy |   18 |
-|      4 | toy    |  253 |
-+--------+--------+------+
+package w3c.sw
 
- * with has an RDF representation:
+import org.scalatest.FunSuite
+import java.net.URI
+import w3c.sw.sql.{Sql,DatabaseDesc,Relation,RelationDesc,Attribute,Value,Datatype,ForeignKey,Name}
+import w3c.sw.sparql.Sparql
+import w3c.sw.rdb2rdf.{RDB2RDF,StemURI}
 
+/* The RDB2RDFTest class transforms SPARQL queries to a relational data
+ * structure and compares them to a structure parsed from SQL.
+ */
+class RDB2RDFTest extends FunSuite {
+
+  /* These tests use a schema and queries designed to work with this
+   * example database:
+       Employee+----------+------------+---------+
+       | empid | lastName | birthday   | manager |
+       +-------+----------+------------+---------+
+       |    18 | Johnson  | 1969-11-08 |    NULL |    TaskAssignments--------+
+       |   253 | Smith    | 1979-01-18 |      18 |    | id | task | employee |
+       |   255 | Jones    | 1981-03-24 |     253 |    +----+------+----------+
+       |    19 | Xu       | 1966-11-08 |    NULL |    |  1 |    1 |       18 |
+       |   254 | Ishita   | 1971-10-31 |     253 |    |  2 |    2 |      253 |
+       +-------+----------+------------+---------+    |  3 |    3 |       19 |
+       					              |  4 |    4 |      253 |
+       Tasks----+--------+------+		      |  5 |    1 |      253 |
+       | taskid | name   | lead |		      |  6 |    2 |      255 |
+       +--------+--------+------+		      |  7 |    3 |      255 |
+       |      1 | widget |   18 |		      |  8 |    4 |      254 |
+       |      2 | dingus |  253 |		      +----+------+----------+
+       |      3 | thingy |   18 |
+       |      4 | toy    |  253 |
+       +--------+--------+------+
+ */
+
+  val db:DatabaseDesc = DatabaseDesc(
+    Map(Relation("Employee") -> 
+	RelationDesc(Option(Attribute("empid")), 
+		     Map(Attribute("empid") -> Value(Datatype.INTEGER),
+			 Attribute("lastName") -> Value(Datatype.STRING),
+			 Attribute("birthday") -> Value(Datatype.DATE),
+			 Attribute("manager") -> ForeignKey(Relation("Employee"), Attribute("empid")))),
+	Relation("Tasks") -> 
+	RelationDesc(Option(Attribute("taskid")),
+		     Map(Attribute("taskid") -> Value(Datatype.INTEGER),
+			 Attribute("name") -> Value(Datatype.STRING),
+			 Attribute("lead") -> ForeignKey(Relation("Employee"), Attribute("empid")))),
+	Relation("TaskAssignments") -> 
+	RelationDesc(Option(Attribute("id")),
+		     Map(Attribute("task") -> ForeignKey(Relation("Tasks"), Attribute("taskid")), 
+			 Attribute("employee") -> ForeignKey(Relation("Employee"),  Attribute("empid"))))
+      ))
+
+/* The reference RDF representation (queriable with the SPARQL in the tests) is:
+ */
+
+  val dbAsTurtle = """
 PREFIX empP : <http://hr.example/DB/Employee#>
 PREFIX task : <http://hr.example/DB/Tasks#>
 PREFIX tass : <http://hr.example/DB/TaskAssignments#>
@@ -79,40 +115,16 @@
 <http://hr.example/DB/TaskAssignment/id.8#record>
    tass:task <http://hr.example/DB/Tasks/taskid.4#record>
    tass:employee <http://hr.example/DB/Employee/empid.254#record> .
-
- * The obvious test s that the results from the SPARQL query and the relational
- * query match.
- */
-
-package w3c.sw
-
-import org.scalatest.FunSuite
-import java.net.URI
-import w3c.sw.sql.{Sql,DatabaseDesc,Relation,RelationDesc,Attribute,Value,Datatype,ForeignKey,Name}
-import w3c.sw.sparql.Sparql
-import w3c.sw.rdb2rdf.{RDB2RDF,StemURI}
-
-class RDB2RDFTest extends FunSuite {
+"""
+  /* The obvious test is that the results from the SPARQL query and the
+   * relational query match.
+   *
+   * Data can be converted to turtle strings, or left as native formats for
+   * mapping the the querier. The first examples constrast queries relying
+   * on a post-query transformation against those returing turtle atoms.
+   */
 
-  val db:DatabaseDesc = DatabaseDesc(
-    Map(Relation("Employee") -> 
-	RelationDesc(Option(Attribute("empid")), 
-		     Map(Attribute("empid") -> Value(Datatype.INTEGER),
-			 Attribute("lastName") -> Value(Datatype.STRING),
-			 Attribute("birthday") -> Value(Datatype.DATE),
-			 Attribute("manager") -> ForeignKey(Relation("Employee"), Attribute("empid")))),
-	Relation("Tasks") -> 
-	RelationDesc(Option(Attribute("taskid")),
-		     Map(Attribute("taskid") -> Value(Datatype.INTEGER),
-			 Attribute("name") -> Value(Datatype.STRING),
-			 Attribute("lead") -> ForeignKey(Relation("Employee"), Attribute("empid")))),
-	Relation("TaskAssignments") -> 
-	RelationDesc(Option(Attribute("id")),
-		     Map(Attribute("task") -> ForeignKey(Relation("Tasks"), Attribute("taskid")), 
-			 Attribute("employee") -> ForeignKey(Relation("Employee"),  Attribute("empid"))))
-      ))
-
-
+  /* Disable turtle string-izing (RDB2RDF parm 5) and return native format: */
   test("?s <p> <x>") {
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
@@ -139,10 +151,7 @@
 """
   }
 
-  /* Data can be converted to turtle strings, or left as native formats for
-   * mapping the the querier. Here are a couple turtle string generators:
-   */
-
+  /* Enable turtle string-izing and test URI generation: */
   test("SELECT <x> { ?sf <p> <x>} (in-SQL Nodizer)") {
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """
@@ -169,6 +178,7 @@
 """
   }
 
+  /* Enable turtle string-izing and test RDFLiteral generation: */
   test("SELECT <x> { ?sf <p> \"asdf\"} (in-SQL Nodizer)") {
     val sparqlParser = Sparql()
     val sparqlSelect = sparqlParser.parseAll(sparqlParser.select, """