+ test cases
authorEric Prud'hommeaux <eric@w3.org>
Wed, 02 Feb 2011 21:58:42 -0500
changeset 318 7144a09e48ac
parent 317 f5050941adff
child 319 47634947e6d7
+ test cases
directmapping-webapp/src/main/scala/Servlet.scala
--- a/directmapping-webapp/src/main/scala/Servlet.scala	Wed Feb 02 19:08:01 2011 -0500
+++ b/directmapping-webapp/src/main/scala/Servlet.scala	Wed Feb 02 21:58:42 2011 -0500
@@ -54,23 +54,160 @@
                                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"),
                              Nil)
 
+  val Style = """
+    #sql { background-color: #e7e7ff; float:left; border: thin solid #888888; padding: 1em; }
+    #result { background-color: #eee; float:left; border: thin solid #888888; padding: 1em; }
+    .clear { clear:both; }
+    input { margin-bottom: -1em; }
+"""
+
+  val Script = """
+var emp_addr = 'CREATE TABLE Addresses (ID INT PRIMARY KEY, city STRING, state STRING);\n\
+INSERT INTO Addresses (ID, city, state) VALUES (18, "Cambridge", "MA");\n\
+CREATE TABLE People (ID INT PRIMARY KEY, fname STRING, addr INT, FOREIGN KEY (addr) REFERENCES Addresses(ID));\n\
+INSERT INTO People (ID, fname, addr) VALUES (7, "Bob", 18);\n\
+INSERT INTO People (ID, fname, addr) VALUES (8, "Sue", NULL);';
+
+var hier_tabl_proto = 'CREATE TABLE Addresses (ID INT PRIMARY KEY, city STRING, state STRING);\n\
+INSERT INTO Addresses (ID, city, state) VALUES (18, "Cambridge", "MA");\n\
+CREATE TABLE People (ID INT PRIMARY KEY, fname STRING, addr INT,\n\
+                     FOREIGN KEY (addr) REFERENCES Addresses(ID));\n\
+INSERT INTO People (ID, fname, addr) VALUES (7, "Bob", 18);\n\
+CREATE TABLE Offices (ID INT PRIMARY KEY,\n\
+                      building INT, ofcNumber STRING,\n\
+                      FOREIGN KEY (ID) REFERENCES Addresses(ID));\n\
+INSERT INTO Offices (ID, building, ofcNumber) VALUES (18, 32, "G528");';
+
+var hier_table = 'CREATE TABLE Addresses (ID INT PRIMARY KEY, city STRING, state STRING);\n\
+INSERT INTO Addresses (ID, city, state) VALUES (18, "Cambridge", "MA");\n\
+CREATE TABLE People (ID INT PRIMARY KEY, fname STRING, addr INT,\n\
+                     FOREIGN KEY (addr) REFERENCES Addresses(ID));\n\
+INSERT INTO People (ID, fname, addr) VALUES (7, "Bob", 18);\n\
+CREATE TABLE Offices (ID INT PRIMARY KEY,\n\
+                      building INT, ofcNumber STRING,\n\
+                      FOREIGN KEY (ID) REFERENCES Addresses(ID));\n\
+INSERT INTO Offices (ID, building, ofcNumber) VALUES (18, 32, "G528");\n\
+CREATE TABLE ExecutiveOffices (ID INT PRIMARY KEY,\n\
+                               desk STRING,\n\
+                               FOREIGN KEY (ID) REFERENCES Offices(ID));\n\
+INSERT INTO ExecutiveOffices (ID, desk) VALUES (18, "oak");';
+
+var multi_key = 'CREATE TABLE Addresses (ID INT PRIMARY KEY, city STRING, state STRING);\n\
+INSERT INTO Addresses (ID, city, state) VALUES (18, "Cambridge", "MA");\n\
+CREATE TABLE Department (ID INT PRIMARY KEY, name STRING, city STRING,\n\
+                         manager INT, FOREIGN KEY (manager) REFERENCES People(ID), UNIQUE (name, city));\n\
+INSERT INTO Department (ID, name, city, manager) VALUES (23, "accounting", "Cambridge", 8);\n\
+CREATE TABLE People (ID INT PRIMARY KEY, fname STRING,\n\
+                     addr INT, FOREIGN KEY (addr) REFERENCES Addresses(ID),\n\
+                     deptName STRING, deptCity STRING, FOREIGN KEY (deptName, deptCity) REFERENCES Department(name, city));\n\
+INSERT INTO People (ID, fname, addr, deptName, deptCity) VALUES (7, "Bob", 18, "accounting", "Cambridge");\n\
+INSERT INTO People (ID, fname, addr, deptName, deptCity) VALUES (8, "Sue", NULL, NULL, NULL);';
+
+var ref_no_pk = 'CREATE TABLE Addresses (ID INT PRIMARY KEY, city STRING, state STRING);\n\
+INSERT INTO Addresses (ID, city, state) VALUES (18, "Cambridge", "MA");\n\
+CREATE TABLE Department (ID INT PRIMARY KEY, name STRING, city STRING, manager INT,\n\
+                         FOREIGN KEY (manager) REFERENCES People(ID),\n\
+                         UNIQUE (name, city));\n\
+INSERT INTO Department (ID, name, city, manager) VALUES (23, "accounting", "Cambridge", 8);\n\
+CREATE TABLE People (ID INT PRIMARY KEY, fname STRING, addr INT,\n\
+                     FOREIGN KEY (addr) REFERENCES Addresses(ID),\n\
+                     deptName STRING, deptCity STRING,\n\
+                     FOREIGN KEY (deptName, deptCity) REFERENCES Department(name, city));\n\
+INSERT INTO People (ID, fname, addr, deptName, deptCity) VALUES (7, "Bob", 18, "accounting", "Cambridge");\n\
+INSERT INTO People (ID, fname, addr, deptName, deptCity) VALUES (8, "Sue", NULL, NULL, NULL);\n\
+CREATE TABLE Projects (lead INT,\n\
+                       FOREIGN KEY (lead) REFERENCES People(ID),\n\
+                       name STRING, UNIQUE (lead, name), \n\
+                       deptName STRING, deptCity STRING,\n\
+                       UNIQUE (name, deptName, deptCity),\n\
+                       FOREIGN KEY (deptName, deptCity) REFERENCES Department(name, city));\n\
+INSERT INTO Projects (lead, name, deptName, deptCity) VALUES (8, "pencil survey", "accounting", "Cambridge");\n\
+INSERT INTO Projects (lead, name, deptName, deptCity) VALUES (8, "eraser survey", "accounting", "Cambridge");\n\
+CREATE TABLE TaskAssignments (worker INT,\n\
+                              FOREIGN KEY (worker) REFERENCES People(ID),\n\
+                              project STRING, PRIMARY KEY (worker, project), \n\
+                              deptName STRING, deptCity STRING,\n\
+                              FOREIGN KEY (worker) REFERENCES People(ID),\n\
+                              FOREIGN KEY (project, deptName, deptCity) REFERENCES Projects(name, deptName, deptCity),\n\
+                              FOREIGN KEY (deptName, deptCity) REFERENCES Department(name, city));\n\
+INSERT INTO TaskAssignments (worker, project, deptName, deptCity) VALUES (7, "pencil survey", "accounting", "Cambridge");';
+
+var _1table0rows = 'CREATE TABLE Student (\n\
+  Name VARCHAR(50)\n\
+);';
+
+var _1table1row = 'CREATE TABLE Student (\n\
+  Name VARCHAR(50)\n\
+);\n\
+INSERT INTO Student (Name) VALUES ("Venus");'
+
+var _1table2columns1row = 'CREATE TABLE Student (\n\
+  ID INT,\n\
+  Name VARCHAR(50)\n\
+);\n\
+INSERT INTO Student (ID, Name) VALUES(10,"Venus");';
+
+var _1table3columns1row = 'CREATE TABLE Student (\n\
+  ID INT,\n\
+  FirstName VARCHAR(50),\n\
+  LastName VARCHAR(50)\n\
+);\n\
+INSERT INTO Student (ID, FirstName, LastName) VALUES (10,"Venus", "Williams");';
+
+var _2duplicates0nulls = 'CREATE TABLE IOUs (\n\
+  fname CHAR(20),\n\
+  lname CHAR(20),\n\
+  amount FLOAT);\n\
+INSERT INTO IOUs (fname, lname, amount) VALUES ("Bob", "Smith", 30);\n\
+INSERT INTO IOUs (fname, lname, amount) VALUES ("Sue", "Jones", 20);\n\
+INSERT INTO IOUs (fname, lname, amount) VALUES ("Bob", "Smith", 30);';
+
+var varchar_varchar_1row = 'CREATE TABLE Student_Sport(\n\
+  Student VARCHAR(50),\n\
+  Sport VARCHAR(50)\n\
+);\n\
+INSERT INTO Student_Sport (Student,Sport) VALUES ("Venus", "Tennis");';
+
+"""
+
   def render(sql:String, result:Option[String]) =
     <html xmlns="http://www.w3.org/1999/xhtml">
       <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title>Direct Mapping</title>
+      <style type="text/css" media="print, screen and (min-width: 481px)">{ Style }
+      </style>
+      <script type="text/javascript">{ Script }
+      </script>
       </head>
       <body>
         <h1>Try the <a href="http://www.w3.org/2001/sw/rdb2rdf/directMapping/">Direct Mapping</a> application!</h1>
-        { if (result isDefined) <pre name="result" id="result">{ result.get }</pre> }
         <form method="post" action="/">
-          <p>
-            <textarea rows="15" cols="80" name="sql" id="sql">{ sql }</textarea><br />
-            <input name="hierarchy" checked="checked" type="checkbox" />Detects hierarchy relation
-            <input type="submit" value="submit SQL" />
-          </p>
+          <p><textarea rows="15" cols="80" name="sql" id="sql">{ sql }</textarea></p>
+	  <div style="float:right;">
+	  <div style="float:left;">
+	    <p><input value="emp_addr" type="button" onclick="document.getElementById('sql').value = emp_addr;" /></p>
+	    <p><input value="hier_tabl_proto" type="button" onclick="document.getElementById('sql').value = hier_tabl_proto;" /></p>
+	    <p><input value="hier_table" type="button" onclick="document.getElementById('sql').value = hier_table;" /></p>
+	    <p><input value="multi_key" type="button" onclick="document.getElementById('sql').value = multi_key;" /></p>
+	    <p><input value="ref_no_pk" type="button" onclick="document.getElementById('sql').value = ref_no_pk;" /></p>
+	  </div>
+	  <div style="float:left;">
+	    <p><input value="1table0rows" type="button" onclick="document.getElementById('sql').value = _1table0rows;" /></p>
+	    <p><input value="1table1row" type="button" onclick="document.getElementById('sql').value = _1table1row;" /></p>
+	    <p><input value="1table2columns1row" type="button" onclick="document.getElementById('sql').value = _1table2columns1row;" /></p>
+	    <p><input value="1table3columns1row" type="button" onclick="document.getElementById('sql').value = _1table3columns1row;" /></p>
+	    <p><input value="2duplicates0nulls" type="button" onclick="document.getElementById('sql').value = _2duplicates0nulls;" /></p>
+	    <p><input value="varchar_varchar_1row" type="button" onclick="document.getElementById('sql').value = varchar_varchar_1row;" /></p>
+	  </div>
+	  </div>
+	  <p><input name="hierarchy" checked="checked" type="checkbox" />Detects hierarchy relation</p>
+	  <p><input value="clear" type="button" onclick="document.getElementById('sql').value = '';" /></p>
+	  <p><input id="submit" value="submit SQL" type="submit" /></p>
         </form>
-        <hr />
+	<div class="clear"/>
+        { if (result isDefined) <pre name="result" id="result">{ result.get }</pre> }
+        <hr class="clear" />
         <address>
           <a href="http://www.w3.org/People/Eric/">Eric Prud'hommeaux</a>, <a href="http://www.w3.org/People/Bertails/">Alexandre Bertails</a>, Feb 2011
         </address>