~ finished refactoring
authorAlexandre Bertails <alexandre@bertails.org>
Fri, 26 Nov 2010 11:26:26 -0500
changeset 272 2cd7671b1c3c
parent 271 18e140f8fd6f
child 273 75e3560805d7
~ finished refactoring
directmapping/src/test/scala/DirectMappingTest.scala
--- a/directmapping/src/test/scala/DirectMappingTest.scala	Fri Nov 26 11:08:41 2010 -0500
+++ b/directmapping/src/test/scala/DirectMappingTest.scala	Fri Nov 26 11:26:26 2010 -0500
@@ -45,6 +45,27 @@
 INSERT INTO People (ID, fname, addr, deptName, deptCity) VALUES (8, "Sue", NULL, NULL, NULL);
 """).get
 
+  val directgraph_multi_key:Graph =
+    Set(
+      Triple(IRI("People/ID.7#_"),IRI("People#deptName"),TypedLiteral("accounting",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#deptCity"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#deptName_deptCity"),IRI("Department/ID.23#_")),
+
+      Triple(IRI("Department/ID.23#_"),IRI("Department#ID"),TypedLiteral("23",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Department/ID.23#_"),IRI("Department#name"),TypedLiteral("accounting",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("Department/ID.23#_"),IRI("Department#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("Department/ID.23#_"),IRI("Department#manager"),IRI("People/ID.8#_")),
+
+      Triple(IRI("People/ID.7#_"),IRI("People#ID"),TypedLiteral("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#addr"),IRI("Addresses/ID.18#_")),
+      Triple(IRI("People/ID.8#_"),IRI("People#ID"),TypedLiteral("8",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("People/ID.8#_"),IRI("People#fname"),TypedLiteral("Sue",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
+
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string"))))
+
   val db_ref_no_pk = SqlParser.parseAll(SqlParser.ddl, """
 CREATE TABLE Addresses (ID INT PRIMARY KEY, city STRING, state STRING);
 INSERT INTO Addresses (ID, city, state) VALUES (18, "Cambridge", "MA");
@@ -76,7 +97,48 @@
 INSERT INTO TaskAssignments (worker, project, deptName, deptCity) VALUES (7, "pencil survey", "accounting", "Cambridge");
 """).get
 
-  val db_hier_tabl = SqlParser.parseAll(SqlParser.ddl, """
+  val directmapping_ref_no_pk =
+    Set(
+      Triple(BNode("a"), IRI("Projects#lead"), IRI("People/ID.8#_")),
+      Triple(BNode("a"), IRI("Projects#name"), TypedLiteral("pencil survey", IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(BNode("a"), IRI("Projects#deptName"), TypedLiteral("accounting", IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(BNode("a"), IRI("Projects#deptCity"), TypedLiteral("Cambridge", IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(BNode("a"), IRI("Projects#deptName_deptCity"), IRI("Department/ID.23#_")),
+
+      Triple(BNode("b"), IRI("Projects#lead"), IRI("People/ID.8#_")),
+      Triple(BNode("b"), IRI("Projects#name"), TypedLiteral("eraser survey", IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(BNode("b"), IRI("Projects#deptName"), TypedLiteral("accounting", IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(BNode("b"), IRI("Projects#deptCity"), TypedLiteral("Cambridge", IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(BNode("b"), IRI("Projects#deptName_deptCity"), IRI("Department/ID.23#_")),
+
+      Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#worker"), IRI("People/ID.7#_")),
+      Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#project"), TypedLiteral("pencil survey", IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#deptName"), TypedLiteral("accounting", IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#deptCity"), TypedLiteral("Cambridge", IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#deptName_deptCity"), IRI("Department/ID.23#_")),
+      Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#project_deptName_deptCity"), BNode("a")),
+
+      Triple(IRI("People/ID.7#_"),IRI("People#deptName"),TypedLiteral("accounting",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#deptCity"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#deptName_deptCity"),IRI("Department/ID.23#_")),
+
+      Triple(IRI("Department/ID.23#_"),IRI("Department#ID"),TypedLiteral("23",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Department/ID.23#_"),IRI("Department#name"),TypedLiteral("accounting",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("Department/ID.23#_"),IRI("Department#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("Department/ID.23#_"),IRI("Department#manager"),IRI("People/ID.8#_")),
+
+      Triple(IRI("People/ID.7#_"),IRI("People#ID"),TypedLiteral("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#addr"),IRI("Addresses/ID.18#_")),
+      Triple(IRI("People/ID.8#_"),IRI("People#ID"),TypedLiteral("8",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("People/ID.8#_"),IRI("People#fname"),TypedLiteral("Sue",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
+
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
+    )
+
+  val db_hier_tabl_proto = SqlParser.parseAll(SqlParser.ddl, """
 CREATE TABLE Addresses (ID INT PRIMARY KEY, city STRING, state STRING);
 INSERT INTO Addresses (ID, city, state) VALUES (18, "Cambridge", "MA");
 CREATE TABLE People (ID INT PRIMARY KEY, fname STRING, addr INT,
@@ -88,127 +150,22 @@
 INSERT INTO Offices (ID, building, ofcNumber) VALUES (18, 32, "G528");
 """).get
 
-}
-
-class Test extends FunSuite {
-
-  import SchemasFromDirectMappingSpec._
-
-  implicit def l2db (rs:List[Relation]):Map[RelName, Relation] =
-    rs.map(r => (r.name -> r)).toMap
-  implicit def string2relName (n:String) = RelName(n)
-  implicit def string2attrName (n:String) = AttrName(n)
-
-//  def test_directmapping(testName:String, )
-
-  test("2 People 1 Addresses") {
-
-    val g = directDB(db_emp_adder)
-
-    assert (directgraph_emp_adder === g)
-  }
-
-  test("2 People 1 Addresses 1 Department") {
-
-    val g = directDB(db_multi_key)
-
-    val expected:Graph =
-      Set(
-	Triple(IRI("People/ID.7#_"),IRI("People#deptName"),TypedLiteral("accounting",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#deptCity"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#deptName_deptCity"),IRI("Department/ID.23#_")),
-
-	Triple(IRI("Department/ID.23#_"),IRI("Department#ID"),TypedLiteral("23",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Department/ID.23#_"),IRI("Department#name"),TypedLiteral("accounting",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("Department/ID.23#_"),IRI("Department#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("Department/ID.23#_"),IRI("Department#manager"),IRI("People/ID.8#_")),
-
-	Triple(IRI("People/ID.7#_"),IRI("People#ID"),TypedLiteral("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#addr"),IRI("Addresses/ID.18#_")),
-	Triple(IRI("People/ID.8#_"),IRI("People#ID"),TypedLiteral("8",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("People/ID.8#_"),IRI("People#fname"),TypedLiteral("Sue",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
-
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
-      )
-    assert (expected === g)
-  }
-
-  test("2 People 1 Addresses 1 Department 2 Projects 1 Task") {
-
-    val g = directDB(db_ref_no_pk)
-
-    val expected:Graph =
-      Set(
-	Triple(BNode("a"), IRI("Projects#lead"), IRI("People/ID.8#_")),
-	Triple(BNode("a"), IRI("Projects#name"), TypedLiteral("pencil survey", IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(BNode("a"), IRI("Projects#deptName"), TypedLiteral("accounting", IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(BNode("a"), IRI("Projects#deptCity"), TypedLiteral("Cambridge", IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(BNode("a"), IRI("Projects#deptName_deptCity"), IRI("Department/ID.23#_")),
+  val directmapping_hier_tabl_proto:Graph =
+    Set(
+      Triple(IRI("Addresses/ID.18#_"),IRI("Offices#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Offices#building"),TypedLiteral("32",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Offices#ofcNumber"),TypedLiteral("G528",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
 
-	Triple(BNode("b"), IRI("Projects#lead"), IRI("People/ID.8#_")),
-	Triple(BNode("b"), IRI("Projects#name"), TypedLiteral("eraser survey", IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(BNode("b"), IRI("Projects#deptName"), TypedLiteral("accounting", IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(BNode("b"), IRI("Projects#deptCity"), TypedLiteral("Cambridge", IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(BNode("b"), IRI("Projects#deptName_deptCity"), IRI("Department/ID.23#_")),
-
-	Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#worker"), IRI("People/ID.7#_")),
-	Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#project"), TypedLiteral("pencil survey", IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#deptName"), TypedLiteral("accounting", IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#deptCity"), TypedLiteral("Cambridge", IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#deptName_deptCity"), IRI("Department/ID.23#_")),
-	Triple(IRI("TaskAssignments/worker.7_project.pencil+survey#_"), IRI("TaskAssignments#project_deptName_deptCity"), BNode("a")),
-
-	Triple(IRI("People/ID.7#_"),IRI("People#deptName"),TypedLiteral("accounting",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#deptCity"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#deptName_deptCity"),IRI("Department/ID.23#_")),
-
-	Triple(IRI("Department/ID.23#_"),IRI("Department#ID"),TypedLiteral("23",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Department/ID.23#_"),IRI("Department#name"),TypedLiteral("accounting",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("Department/ID.23#_"),IRI("Department#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("Department/ID.23#_"),IRI("Department#manager"),IRI("People/ID.8#_")),
-
-	Triple(IRI("People/ID.7#_"),IRI("People#ID"),TypedLiteral("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#addr"),IRI("Addresses/ID.18#_")),
-	Triple(IRI("People/ID.8#_"),IRI("People#ID"),TypedLiteral("8",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("People/ID.8#_"),IRI("People#fname"),TypedLiteral("Sue",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
+      Triple(IRI("People/ID.7#_"),IRI("People#ID"),TypedLiteral("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#addr"),IRI("Addresses/ID.18#_")),
 
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
-      )
-    assert (expected === g)
-  }
-
-
-  test("1 People 1 Addresses 1 Offices") {
-
-    val g = directDB(db_hier_tabl)
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
+    )
 
-    val expected:Graph =
-      Set(
-	Triple(IRI("Addresses/ID.18#_"),IRI("Offices#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Offices#building"),TypedLiteral("32",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Offices#ofcNumber"),TypedLiteral("G528",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
-
-	Triple(IRI("People/ID.7#_"),IRI("People#ID"),TypedLiteral("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#addr"),IRI("Addresses/ID.18#_")),
-
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
-      )
-    assert (expected === g)
-  }
-
-
-  test("1 People 1 Addresses 1 Offices 1 ExectutiveOffices") {
-
-    val s = """
+  val db_hier_tabl = SqlParser.parseAll(SqlParser.ddl, """
 CREATE TABLE Addresses (ID INT PRIMARY KEY, city STRING, state STRING);
 INSERT INTO Addresses (ID, city, state) VALUES (18, "Cambridge", "MA");
 CREATE TABLE People (ID INT PRIMARY KEY, fname STRING, addr INT,
@@ -222,31 +179,52 @@
                                desk STRING,
                                FOREIGN KEY (ID) REFERENCES Offices(ID));
 INSERT INTO ExecutiveOffices (ID, desk) VALUES (18, "oak");
-"""
-
-    val db = SqlParser.parseAll(SqlParser.ddl, s).get
-    val g = directDB(db)
-
-    val expected:Graph =
-      Set(
-	Triple(IRI("Addresses/ID.18#_"),IRI("ExecutiveOffices#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("ExecutiveOffices#desk"),TypedLiteral("oak",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
+""").get
+					
+  val directgraph_hier_tabl:Graph =
+    Set(
+      Triple(IRI("Addresses/ID.18#_"),IRI("ExecutiveOffices#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("ExecutiveOffices#desk"),TypedLiteral("oak",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
 
-	Triple(IRI("Addresses/ID.18#_"),IRI("Offices#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Offices#building"),TypedLiteral("32",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Offices#ofcNumber"),TypedLiteral("G528",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
+      Triple(IRI("Addresses/ID.18#_"),IRI("Offices#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Offices#building"),TypedLiteral("32",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Offices#ofcNumber"),TypedLiteral("G528",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
 
-	Triple(IRI("People/ID.7#_"),IRI("People#ID"),TypedLiteral("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("People/ID.7#_"),IRI("People#addr"),IRI("Addresses/ID.18#_")),
+      Triple(IRI("People/ID.7#_"),IRI("People#ID"),TypedLiteral("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("People/ID.7#_"),IRI("People#addr"),IRI("Addresses/ID.18#_")),
 
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
-	Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
-      )
-    assert (expected === g)
-  }
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+      Triple(IRI("Addresses/ID.18#_"),IRI("Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
+    )
 
+}
+
+class Test extends FunSuite {
+
+  import SchemasFromDirectMappingSpec._
+
+  implicit def l2db (rs:List[Relation]):Map[RelName, Relation] =
+    rs.map(r => (r.name -> r)).toMap
+  implicit def string2relName (n:String) = RelName(n)
+  implicit def string2attrName (n:String) = AttrName(n)
+
+  def testDirectMapping(testName:String, db:Database, expectedGraph:Graph) =
+    test(testName) {
+      val computedGraph = directDB(db)
+      assert (expectedGraph === computedGraph)
+    }
+
+  testDirectMapping("2 People 1 Addresses", db_emp_adder, directgraph_emp_adder)
+
+  testDirectMapping("2 People 1 Addresses 1 Department", db_multi_key, directgraph_multi_key)
+
+  testDirectMapping("2 People 1 Addresses 1 Department 2 Projects 1 Task", db_ref_no_pk, directmapping_ref_no_pk)
+
+  testDirectMapping("1 People 1 Addresses 1 Offices", db_hier_tabl_proto, directmapping_hier_tabl_proto)
+
+  testDirectMapping("1 People 1 Addresses 1 Offices 1 ExectutiveOffices", db_hier_tabl, directgraph_hier_tabl)
 
   test("NodeMap") {