db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r619230 - in /db/torque/village/trunk: src/test/com/workingdogs/village/TestMySQL.java xdocs/changes.xml
Date Thu, 07 Feb 2008 00:29:32 GMT
Author: seade
Date: Wed Feb  6 16:29:31 2008
New Revision: 619230

URL: http://svn.apache.org/viewvc?rev=619230&view=rev
Log:
Refactored unit tests to use JUnit.  This has not been configured to run as part of the build
process.
Added test case for TORQUE-8.

Modified:
    db/torque/village/trunk/src/test/com/workingdogs/village/TestMySQL.java
    db/torque/village/trunk/xdocs/changes.xml

Modified: db/torque/village/trunk/src/test/com/workingdogs/village/TestMySQL.java
URL: http://svn.apache.org/viewvc/db/torque/village/trunk/src/test/com/workingdogs/village/TestMySQL.java?rev=619230&r1=619229&r2=619230&view=diff
==============================================================================
--- db/torque/village/trunk/src/test/com/workingdogs/village/TestMySQL.java (original)
+++ db/torque/village/trunk/src/test/com/workingdogs/village/TestMySQL.java Wed Feb  6 16:29:31
2008
@@ -21,26 +21,32 @@
 
 import java.sql.Connection;
 import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import junit.framework.TestCase;
 
 /**
- * This class is used for testing the functionality of this product. While creating this
code, I have closed many potential bugs,
- * but I'm sure that others still exist. Thus, if you find a bug in Village, please add to
this test suite so that the bug will be
- * sure to be fixed in future versions.
+ * This class is used for testing the functionality of this product. While
+ * creating this code, I have closed many potential bugs, but I'm sure that
+ * others still exist. Thus, if you find a bug in Village, please add to this
+ * test suite so that the bug will be sure to be fixed in future versions.
  *
- * <P>
- * In order to do the testing, you will need to be able to connect via JDBC to your database.
Since I use MySQL <A
- * HREF="http://www.mysql.com/">http://www.mysql.com/</A> , this testing suite is
best for that database. I also use the mm MySQL
- * drivers <A HREF="http://www.worldserver.com/mm.mysql/">http://www.worldserver.com/mm.mysql/</A>
because it is the best driver
- * that I have found for MySQL.
+ * <p>
+ * In order to do the testing, you will need to be able to connect via JDBC to
+ * your database. Since I use <a href="http://www.mysql.com/">MySQL</a>, this
+ * testing suite is best for that database. I also use the mm MySQL drivers
+ * <a href="http://mmmysql.sourceforge.net/">mm MySQL drivers</a> because it
+ * is the best driver that I have found for MySQL.
  * </p>
  *
  * <P>
  * Note that Village should work with <strong>any</strong> JDBC compliant driver.
  * </p>
  *
- * <P>
- * Here is the schema that this test expects ( you should be able to copy and paste it into
your MySQL database that you want to
- * use ):
+ * <p>
+ * Here is the schema that this test expects (you should be able to copy and
+ * paste it into your MySQL database that you want to use):
  * <pre>
  *  CREATE TABLE test
  *  (
@@ -72,10 +78,18 @@
  *  </pre>
  * </p>
  *
+ * <p>
+ * Note that presently this class is hardcoded to use a MySQL database named
+ * "village" with a username of "village" and a password of "village".  It is
+ * a modified version of Jon's original Unit test that apparently pre-dated
+ * JUnit!
+ * </p>
+ *
  * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
+ * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
  * @version $Revision: 565 $
  */
-public class TestMySQL
+public class TestMySQL extends TestCase
 {
     /** The database connection */
     static Connection conn;
@@ -90,18 +104,21 @@
     private static String DB_HOST = "localhost";
 
     /**
-     * This is the user to log into the database as. For this test, the user must have insert/update/delete
access to the database.
+     * This is the user to log into the database as. For this test, the user
+     * must have insert/update/delete access to the database.
      */
-    private static String DB_USER = "";
+    private static String DB_USER = "village";
 
     /** the password for the user */
-    private static String DB_PASS = "";
+    private static String DB_PASS = "village";
 
     /** mm MySQL Driver setup */
     private static String DB_DRIVER = "org.gjt.mm.mysql.Driver";
+    //private static String DB_DRIVER = "com.mysql.jdbc.Driver";
 
     /** mm MySQL Driver setup */
-    private static String DB_CONNECTION = "jdbc:mysql://" + DB_HOST + "/" + DB_NAME + "?user="
+ DB_USER + "&password=" + DB_PASS;
+    private static String DB_CONNECTION = "jdbc:mysql://" + DB_HOST + "/"
+            + DB_NAME + "?user=" + DB_USER + "&password=" + DB_PASS;
 
     /** used for debugging */
     private static boolean debugging = true;
@@ -110,9 +127,6 @@
     private static int num = 1;
 
     /** used for debugging */
-    private static int testCount = 1;
-
-    /** used for debugging */
     private static int TDS = 1;
 
     /** used for debugging */
@@ -124,391 +138,415 @@
     /** used for debugging */
     private static int FAILED = 2;
 
+    /** The number of times to hit the schema to try and reach a connection
+     *  limit. */
+    private static int SCHEMA_LOOPS = 2000;
+
     /**
-     * @TODO DOCUMENT ME!
+     * Creates a new instance.
      *
-     * @param argv @TODO DOCUMENT ME!
+     * @param name the name of the test case to run
      */
-    public static void main(String [] argv)
+    public TestMySQL(String name)
     {
-        if ((argv.length > 0) && (argv.length < 5))
-        {
-            System.out.println("Format: TestMySQL <DB_NAME> <DB_TABLE> <DB_HOST>
<DB_USER> <DB_PASS>");
+        super(name);
+    }
+
+//    /**
+//     * @TODO DOCUMENT ME!
+//     *
+//     * @param argv
+//     */
+//    public static void main(String [] argv)
+//    {
+//        if ((argv.length > 0) && (argv.length < 5))
+//        {
+//            System.out.println("Format: TestMySQL <DB_NAME> <DB_TABLE> <DB_HOST>
<DB_USER> <DB_PASS>");
+//
+//            return;
+//        }
+//        else if (argv.length == 5)
+//        {
+//            DB_NAME = argv[0];
+//            DB_TABLE = argv[1];
+//            DB_HOST = argv[2];
+//            DB_USER = argv[3];
+//            DB_PASS = argv[4];
+//            DB_CONNECTION = "jdbc:mysql://" + DB_HOST + "/" + DB_NAME + "?user=" + DB_USER
+ "&password=" + DB_PASS;
+//        }
+//
+//        getConnection();
+//
+//        testDeleteSomeRecords();
+//        testTableDataSet();
+//        testQueryDataSet();
+//        testSchemaResultSet();
+//        testTableDataSet2();
+//        testTableDataSet3();
+//        testTableDataSet4();
+//        testRemoveRecord();
+//    }
 
-            return;
+    public void setUp()
+    {
+        try
+        {
+            getConnection();
         }
-        else if (argv.length == 5)
+        catch (ClassNotFoundException e)
         {
-            DB_NAME = argv[0];
-            DB_TABLE = argv[1];
-            DB_HOST = argv[2];
-            DB_USER = argv[3];
-            DB_PASS = argv[4];
-            DB_CONNECTION = "jdbc:mysql://" + DB_HOST + "/" + DB_NAME + "?user=" + DB_USER
+ "&password=" + DB_PASS;
+            System.out.println("\n\nConnection failed : " + e.getMessage());
+        }
+        catch (SQLException e)
+        {
+            System.out.println("\n\nConnection failed : " + e.getMessage());
         }
+    }
 
-        getConnection();
+    protected void tearDown() throws Exception
+    {
+        // Empty the database.
+        PreparedStatement ps = conn.prepareStatement("delete from test");
+        ps.execute();
 
-        //      testDeleteSomeRecords();
-        //      testTableDataSet();
-        //      testQueryDataSet();
-        //      testTableDataSet2();
-        //      testTableDataSet3();
-        //      testTableDataSet4();
-        //      testRemoveRecord();
+        conn.close();
     }
 
     /**
-     * This test verifies that deleting multiple records actually works. after execution,
there should be no more records in the
-     * database.
+     * This test verifies that deleting multiple records actually works. after
+     * execution, there should be no more records in the database.
      */
     public static void testDeleteSomeRecords()
+            throws SQLException, DataSetException
     {
-        try
-        {
-            KeyDef kd = new KeyDef().addAttrib("e");
-            TableDataSet tds = new TableDataSet(conn, DB_TABLE, kd);
-            tds.where("e > 100");
-
-            // add some records
-            Record newRec = tds.addRecord();
-            newRec.setValue("e", "200");
-
-            Record newRec2 = tds.addRecord();
-            newRec2.setValue("e", "300");
-            tds.save();
-
-            // get those records
-            tds.fetchRecords();
-
-            for (int i = 0; i < tds.size(); i++)
-            {
-                Record rec = tds.getRecord(i);
-
-                // delete those records
-                rec.markToBeDeleted();
-                System.out.println("here " + i + ": " + rec.toString());
-            }
+        KeyDef kd = new KeyDef().addAttrib("e");
+        TableDataSet tds = new TableDataSet(conn, DB_TABLE, kd);
+        tds.where("e > 100");
 
-            tds.save();
-            tds.close();
-        }
-        catch (Exception e)
+        // add some records
+        Record newRec = tds.addRecord();
+        newRec.setValue("e", "200");
+
+        Record newRec2 = tds.addRecord();
+        newRec2.setValue("e", "300");
+        tds.save();
+
+        // get those records
+        tds.fetchRecords();
+
+        for (int i = 0; i < tds.size(); i++)
         {
-            debug(TDS, e);
+            Record rec = tds.getRecord(i);
+
+            // delete those records
+            rec.markToBeDeleted();
+            System.out.println("here " + i + ": " + rec.toString());
         }
+
+        tds.save();
+        tds.close();
     }
 
     /**
-     * This test will throw a DataSetException. The first getRecord will succeed and the
second one will fail.
+     * This test checks that a DataSetException is thrown when appropriate.
      */
     public static void testRemoveRecord()
+            throws SQLException, DataSetException
     {
-        try
-        {
-            TableDataSet tds = new TableDataSet(conn, DB_TABLE);
-            tds.addRecord();
+        TableDataSet tds = new TableDataSet(conn, DB_TABLE);
+        tds.addRecord();
 
-            Record rec = tds.getRecord(0);
-            tds.removeRecord(rec);
+        Record rec = tds.getRecord(0);
+        tds.removeRecord(rec);
 
+        try
+        {
             Record foo = tds.getRecord(0);
-            tds.close();
         }
-        catch (Exception e)
+        catch (DataSetException e)
         {
-            debug(TDS, e);
+            // expected
         }
+        tds.close();
     }
 
-    /**
-     * @TODO DOCUMENT ME!
-     */
     public static void testTableDataSet2()
+            throws SQLException, DataSetException
     {
-        try
-        {
-            TableDataSet tds = new TableDataSet(conn, DB_TABLE);
-            Record rec = tds.addRecord();
-            rec.setValue("b", 2);
-            tds.save();
-            tds.close();
-        }
-        catch (Exception e)
-        {
-            debug(TDS, e);
-        }
+        TableDataSet tds = new TableDataSet(conn, DB_TABLE);
+        Record rec = tds.addRecord();
+        rec.setValue("b", 2);
+        tds.save();
+        tds.close();
     }
 
-    /**
-     * @TODO DOCUMENT ME!
-     */
     public static void testTableDataSet3()
+            throws SQLException, DataSetException
     {
-        try
-        {
-            TableDataSet tds = new TableDataSet(conn, DB_TABLE);
-            Record rec = tds.addRecord();
-            rec.setValue("b", 2);
-            rec.save();
-            tds.close();
-        }
-        catch (Exception e)
-        {
-            debug(TDS, e);
-        }
+        TableDataSet tds = new TableDataSet(conn, DB_TABLE);
+        Record rec = tds.addRecord();
+        rec.setValue("b", 2);
+        rec.save();
+        tds.close();
     }
 
-    /**
-     * @TODO DOCUMENT ME!
-     */
     public static void testTableDataSet4()
+            throws SQLException, DataSetException
     {
-        try
-        {
-            KeyDef kd = new KeyDef().addAttrib("b");
-            TableDataSet tds = new TableDataSet(conn, DB_TABLE, kd);
-            Record rec = tds.addRecord();
-            rec.setValueNull("b");
-            System.out.println(rec.getSaveString());
-            rec.save();
-            rec.markToBeDeleted();
-            System.out.println(rec.getSaveString());
-            rec.save();
-            tds.close();
-        }
-        catch (Exception e)
-        {
-            debug(TDS, e);
-        }
+        KeyDef kd = new KeyDef().addAttrib("b");
+        TableDataSet tds = new TableDataSet(conn, DB_TABLE, kd);
+        Record rec = tds.addRecord();
+        rec.setValueNull("b");
+        System.out.println(rec.getSaveString());
+        rec.save();
+        rec.markToBeDeleted();
+        System.out.println(rec.getSaveString());
+        rec.save();
+        tds.close();
     }
 
-    /**
-     * @TODO DOCUMENT ME!
-     */
     public static void testTableDataSet()
+            throws SQLException, DataSetException
     {
-        try
-        {
-            KeyDef kd = new KeyDef().addAttrib("a");
-            TableDataSet tds = new TableDataSet(conn, DB_TABLE, kd);
-            tds.order("a");
-            tds.fetchRecords();
-
-            int size = tds.size();
-
-            debug(TDS, "size of fetchRecords", size);
-            debug(TDS, "getSelectString()", tds.getSelectString());
-            test(TDS, tds.getSelectString(), "SELECT * FROM test ORDER BY a");
-
-            // add a new record
-            Record addRec = tds.addRecord();
-            addRec.setValue("a", 1);
-            addRec.setValue("b", 2);
-            addRec.setValue("c", 2343);
-            addRec.setValue("d", 33333);
-            addRec.setValue("e", 22222);
-            addRec.setValue("f", 234324);
-            addRec.setValue("g", 3434);
-            addRec.setValue("h", 2343.30);
-            addRec.setValue("i", 2343.22);
-            addRec.setValue("j", 333.3);
-            addRec.setValue("k", 333.3);
-            addRec.setValue("l", "lskdfsd");
-            addRec.setValue("m", "lksdflkjsldf");
-            addRec.setValue("n", new java.util.Date());
-            addRec.setValue("o", new java.util.Date());
-            addRec.setValue("p", new java.util.Date());
-            addRec.setValue("q", new java.util.Date());
-            addRec.setValue("r", "lksdflkjsldf");
-            addRec.setValue("s", "lksdflkjsldf");
-            addRec.setValue("t", "lksdflkjsldf");
-            addRec.setValue("u", "lksdflkjsldf");
-            addRec.setValue("v", "lksdflkjsldf");
-            addRec.setValue("w", "lksdflkjsldf");
-            addRec.setValue("x", "lksdflkjsldf");
-
-            debug(TDS, "getSaveString() for insert", addRec.getSaveString());
-            test(TDS, addRec.getSaveString(),
-                "INSERT INTO test ( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r,
s, t, u, v, w, x ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ? )");
-
-            // save it (causing an INSERT to happen)
-            addRec.save();
-
-            debug(TDS, "size of TDS after save()", tds.size());
-            test(TDS, size + 1, tds.size());
-
-            Record updateRec = tds.getRecord(0);
-            updateRec.setValue("b", 234);
-            updateRec.setValue("c", 4);
-            updateRec.setValue("d", 4);
-            updateRec.setValue("e", 5);
-            updateRec.setValue("f", 6);
-            updateRec.setValue("g", 3);
-            updateRec.setValue("h", 3.4);
-            updateRec.setValue("i", 33.44);
-            updateRec.setValue("j", 33.55);
-            updateRec.setValue("k", 3333.7);
-            updateRec.setValue("l", "qweqwe");
-            updateRec.setValue("m", "qweqwe");
-            updateRec.setValue("n", new java.util.Date());
-            updateRec.setValue("o", new java.util.Date());
-            updateRec.setValue("p", new java.util.Date());
-            updateRec.setValue("q", new java.util.Date());
-            updateRec.setValue("r", "qweqwe");
-            updateRec.setValue("s", "qweqwe");
-            updateRec.setValue("t", "qweqwe");
-            updateRec.setValue("u", "qweqwe");
-            updateRec.setValue("v", "qweqwe");
-            updateRec.setValue("w", "qweqwe");
-            updateRec.setValue("x", "qweqwe");
-
-            debug(TDS, "updateRec.getRefreshQueryString()", updateRec.getRefreshQueryString());
-
-            debug(TDS, "updateRec.getSaveString() for update", updateRec.getSaveString());
-            test(TDS, updateRec.getSaveString(),
-                "UPDATE test SET b = ?, c = ?, d = ?, e = ?, f = ?, g = ?, h = ?, i = ?,
j = ?, k = ?, l = ?, m = ?, n = ?, o = ?, p = ?, q = ?, r = ?, s = ?, t = ?, u = ?, v = ?,
w = ?, x = ? WHERE a = ?");
-
-            updateRec.save();
-
-            // mark it for deletion
-            addRec.markToBeDeleted();
-
-            debug(TDS, "addRec.getSaveString() for delete", addRec.getSaveString());
-            test(TDS, addRec.getSaveString(), "DELETE FROM test WHERE a = ?");
-
-            // save it (causing a DELETE to happen and also remove the records from the TDS)
-            addRec.save();
-            test(TDS, tds.size(), 0);
-
-            tds.close();
-
-            // Start a new TableDataSet, this is to test the Record.refresh() method
-            tds = new TableDataSet(conn, DB_TABLE, kd);
-            tds.fetchRecords();
-            addRec = tds.addRecord();
-            addRec.setValue("a", 1);
-            addRec.save();
-
-            tds = new TableDataSet(conn, DB_TABLE, kd);
-            tds.fetchRecords();
-
-            Record getRec = tds.getRecord(0);
-
-            debug(TDS, "getRec.asString() 1a:", getRec.getValue("a").asString());
-            test(TDS, getRec.getValue("a").asString(), "1");
-            debug(TDS, "getRec.asString() 1b:", getRec.getValue("b").asString());
-            test(TDS, getRec.getValue("b").asString(), "0");
-
-            getRec.setValue("b", 5);
-
-            debug(TDS, "getRec.asString() 2b:", getRec.getValue("b").asString());
-            test(TDS, getRec.getValue("b").asString(), "5");
-
-            getRec.refresh(conn);
-
-            debug(TDS, "getRec.asString() 3b:", getRec.getValue("b").asString());
-            test(TDS, getRec.getValue("b").asString(), "0");
-            debug(TDS, "getRec.asString() 2a:", getRec.getValue("a").asString());
-            test(TDS, getRec.getValue("a").asString(), "1");
-
-            getRec.markToBeDeleted();
-            getRec.save();
-
-            System.out.println(tds.toString());
-            System.out.println(getRec.toString());
-            System.out.println(tds.schema().toString());
+        KeyDef kd = new KeyDef().addAttrib("a");
+        TableDataSet tds = new TableDataSet(conn, DB_TABLE, kd);
+        tds.order("a");
+        tds.fetchRecords();
+
+        int size = tds.size();
+        assertEquals(0, size);
+
+        debug(TDS, "size of fetchRecords", size);
+        debug(TDS, "getSelectString()", tds.getSelectString());
+        assertEquals("SELECT * FROM test ORDER BY a", tds.getSelectString());
+
+        // add a new record
+        Record addRec = tds.addRecord();
+        addRec.setValue("a", 1);
+        addRec.setValue("b", 2);
+        addRec.setValue("c", 2343);
+        addRec.setValue("d", 33333);
+        addRec.setValue("e", 22222);
+        addRec.setValue("f", 234324);
+        addRec.setValue("g", 3434);
+        addRec.setValue("h", 2343.30);
+        addRec.setValue("i", 2343.22);
+        addRec.setValue("j", 333.3);
+        addRec.setValue("k", 333.3);
+        addRec.setValue("l", "lskdfsd");
+        addRec.setValue("m", "lksdflkjsldf");
+        addRec.setValue("n", new java.util.Date());
+        addRec.setValue("o", new java.util.Date());
+        addRec.setValue("p", new java.util.Date());
+        addRec.setValue("q", new java.util.Date());
+        addRec.setValue("r", "lksdflkjsldf");
+        addRec.setValue("s", "lksdflkjsldf");
+        addRec.setValue("t", "lksdflkjsldf");
+        addRec.setValue("u", "lksdflkjsldf");
+        addRec.setValue("v", "lksdflkjsldf");
+        addRec.setValue("w", "lksdflkjsldf");
+        addRec.setValue("x", "lksdflkjsldf");
+
+        debug(TDS, "getSaveString() for insert", addRec.getSaveString());
+        assertEquals("INSERT INTO test ( a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p,
q, r, s, t, u, v, w, x ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
?, ?, ?, ?, ? )",
+                addRec.getSaveString());
+
+        // save it (causing an INSERT to happen)
+        addRec.save();
+
+        debug(TDS, "size of TDS after save()", tds.size());
+        assertEquals(1, tds.size());
+
+        Record updateRec = tds.getRecord(0);
+        updateRec.setValue("b", 234);
+        updateRec.setValue("c", 4);
+        updateRec.setValue("d", 4);
+        updateRec.setValue("e", 5);
+        updateRec.setValue("f", 6);
+        updateRec.setValue("g", 3);
+        updateRec.setValue("h", 3.4);
+        updateRec.setValue("i", 33.44);
+        updateRec.setValue("j", 33.55);
+        updateRec.setValue("k", 3333.7);
+        updateRec.setValue("l", "qweqwe");
+        updateRec.setValue("m", "qweqwe");
+        updateRec.setValue("n", new java.util.Date());
+        updateRec.setValue("o", new java.util.Date());
+        updateRec.setValue("p", new java.util.Date());
+        updateRec.setValue("q", new java.util.Date());
+        updateRec.setValue("r", "qweqwe");
+        updateRec.setValue("s", "qweqwe");
+        updateRec.setValue("t", "qweqwe");
+        updateRec.setValue("u", "qweqwe");
+        updateRec.setValue("v", "qweqwe");
+        updateRec.setValue("w", "qweqwe");
+        updateRec.setValue("x", "qweqwe");
+
+        debug(TDS, "updateRec.getRefreshQueryString()", updateRec.getRefreshQueryString());
+
+        debug(TDS, "updateRec.getSaveString() for update", updateRec.getSaveString());
+        assertEquals("UPDATE test SET b = ?, c = ?, d = ?, e = ?, f = ?, g = ?, h = ?, i
= ?, j = ?, k = ?, l = ?, m = ?, n = ?, o = ?, p = ?, q = ?, r = ?, s = ?, t = ?, u = ?, v
= ?, w = ?, x = ? WHERE a = ?",
+                updateRec.getSaveString());
+
+        updateRec.save();
+        assertEquals(1, tds.size());
+
+        // mark it for deletion
+        addRec.markToBeDeleted();
+        assertEquals(1, addRec.getValue(1).asInt());
+
+        debug(TDS, "addRec.getSaveString() for delete", addRec.getSaveString());
+        assertEquals("DELETE FROM test WHERE a = ?", addRec.getSaveString());
+
+        // save it (causing a DELETE to happen and also remove the records from the TDS)
+        assertEquals(1, addRec.save());
+        // The save() no longer deletes the record, but rather marks it for deletion.
+        assertEquals(Enums.ZOMBIE, addRec.getSaveType());
+        assertEquals(1, tds.size());
+        // Remove the zombie records.
+        tds.save();
+        assertEquals(0, tds.size());
+
+        tds.close();
+
+        // Start a new TableDataSet, this is to test the Record.refresh() method
+        tds = new TableDataSet(conn, DB_TABLE, kd);
+        tds.fetchRecords();
+        addRec = tds.addRecord();
+        addRec.setValue("a", 1);
+        addRec.save();
+        assertEquals(1, tds.size());
+
+        tds = new TableDataSet(conn, DB_TABLE, kd);
+        tds.fetchRecords();
+        assertEquals(1, tds.size());
+
+        Record getRec = tds.getRecord(0);
+
+        debug(TDS, "getRec.asString() 1a:", getRec.getValue("a").asString());
+        assertEquals("1", getRec.getValue("a").asString());
+        debug(TDS, "getRec.asString() 1b:", getRec.getValue("b").asString());
+        // TODO Check that smallint is supposed to return null now
+        assertNull(getRec.getValue("b").asString());
+
+        // Since there is no getRec.save() before the .refresh() the value being
+        // set here will not end up in the database.
+        getRec.setValue("b", 5);
+
+        debug(TDS, "getRec.asString() 2b:", getRec.getValue("b").asString());
+        assertEquals("5", getRec.getValue("b").asString());
+
+        // While the JavaDoc for Record.refresh() indicates that it cannot be
+        // done for a modified record, it certainly allows it and in fact seems
+        // to be the intended purpose of the method.
+        getRec.refresh(conn);
+
+        debug(TDS, "getRec.asString() 3b:", getRec.getValue("b").asString());
+        // TODO Check that smallint is supposed to return null now
+        assertNull(getRec.getValue("b").asString());
+        debug(TDS, "getRec.asString() 2a:", getRec.getValue("a").asString());
+        assertEquals("1", getRec.getValue("a").asString());
+
+        getRec.markToBeDeleted();
+        getRec.save();
+
+        System.out.println(tds.toString());
+        System.out.println(getRec.toString());
+        System.out.println(tds.schema().toString());
 
-            tds.close();
-        }
-        catch (Exception e)
-        {
-            debug(TDS, e);
-        }
+        tds.close();
     }
 
     /**
-     * @TODO DOCUMENT ME!
+     * @throws DataSetException 
+     * @throws SQLException 
      */
     public static void testQueryDataSet()
+            throws SQLException, DataSetException
     {
-        try
-        {
-            KeyDef kd = new KeyDef().addAttrib("a");
-            TableDataSet tds = new TableDataSet(conn, DB_TABLE, kd);
-            tds.fetchRecords();
-
-            // add a new record
-            Record addRec = tds.addRecord();
-            addRec.setValue("a", 1);
-            addRec.setValue("b", 2);
-            debug(TDS, "addRec.getSaveString()", addRec.getSaveString());
-            test(TDS, addRec.getSaveString(), "INSERT INTO test ( a, b ) VALUES ( ?, ? )");
-
-            // save it (causing an INSERT to happen)
-            addRec.save();
-            tds.close();
-
-            // get a QDS
-            QueryDataSet qds = new QueryDataSet(conn, "SELECT * FROM " + DB_TABLE);
-            qds.fetchRecords();
-
-            debug(QDS, "qds.getSelectString()", qds.getSelectString());
-            test(QDS, qds.getSelectString(), "SELECT * FROM test");
-
-            debug(QDS, "qds.size()", qds.size()); // should be 1
-
-            Record rec = qds.getRecord(0);
-            debug(QDS, "rec.size()", rec.size()); // should be 24
-
-            debug(QDS, "rec.getValue(\"a\").asString()", rec.getValue("a").asString());
-            debug(QDS, "rec.getValue(\"b\").asString()", rec.getValue("b").asString());
-            debug(QDS, "rec.getValue(\"c\").asString()", rec.getValue("c").asString());
-            debug(QDS, "rec.getValue(\"d\").asString()", rec.getValue("d").asString());
-
-            // this tests to make sure that "d" was assigned properly
-            // there was a bug where wasNull() was being checked and this wasn't
-            // being setup correctly.
-            test(QDS, rec.getValue("d").asString(), "0");
-            qds.close();
-
-            // delete the record
-            kd = new KeyDef().addAttrib("a");
-            tds = new TableDataSet(conn, DB_TABLE, kd);
-            tds.fetchRecords();
-
-            Record getRec = tds.getRecord(0);
-            getRec.markToBeDeleted();
-            getRec.save();
-            tds.close();
-        }
-        catch (Exception e)
-        {
-            debug(TDS, e);
-        }
+        KeyDef kd = new KeyDef().addAttrib("a");
+        TableDataSet tds = new TableDataSet(conn, DB_TABLE, kd);
+        tds.fetchRecords();
+
+        // add a new record
+        Record addRec = tds.addRecord();
+        addRec.setValue("a", 1);
+        addRec.setValue("b", 2);
+        debug(TDS, "addRec.getSaveString()", addRec.getSaveString());
+        assertEquals("INSERT INTO test ( a, b ) VALUES ( ?, ? )", addRec.getSaveString());
+
+        // save it (causing an INSERT to happen)
+        addRec.save();
+        tds.close();
+
+        // get a QDS
+        QueryDataSet qds = new QueryDataSet(conn, "SELECT * FROM " + DB_TABLE);
+        qds.fetchRecords();
+
+        debug(QDS, "qds.getSelectString()", qds.getSelectString());
+        assertEquals("SELECT * FROM test", qds.getSelectString());
+
+        debug(QDS, "qds.size()", qds.size()); // should be 1
+
+        Record rec = qds.getRecord(0);
+        debug(QDS, "rec.size()", rec.size()); // should be 24
+
+        debug(QDS, "rec.getValue(\"a\").asString()", rec.getValue("a").asString());
+        debug(QDS, "rec.getValue(\"b\").asString()", rec.getValue("b").asString());
+        debug(QDS, "rec.getValue(\"c\").asString()", rec.getValue("c").asString());
+        debug(QDS, "rec.getValue(\"d\").asString()", rec.getValue("d").asString());
+
+        // this tests to make sure that "d" was assigned properly
+        // there was a bug where wasNull() was being checked and this wasn't
+        // being setup correctly.
+        // TODO Check that tinyint is supposed to return null now
+        //assertEquals("0", rec.getValue("d").asString());
+        assertNull(rec.getValue("d").asString());
+        qds.close();
+
+        // delete the record
+        kd = new KeyDef().addAttrib("a");
+        tds = new TableDataSet(conn, DB_TABLE, kd);
+        tds.fetchRecords();
+
+        Record getRec = tds.getRecord(0);
+        getRec.markToBeDeleted();
+        getRec.save();
+        tds.close();
     }
 
     /**
-     * @TODO DOCUMENT ME!
+     * This is a test for TORQUE-8.
+     *
+     * @throws DataSetException 
+     * @throws SQLException 
      */
-    public static void getConnection()
+    public static void testSchemaResultSet()
+            throws SQLException, DataSetException
     {
-        try
+        for (int i = 0; i < SCHEMA_LOOPS; i++)
         {
-            Class.forName(DB_DRIVER);
-            conn = DriverManager.getConnection(DB_CONNECTION);
-        }
-        catch (Exception e)
-        {
-            System.out.println("\n\nConnection failed : " + e.getMessage());
+            System.out.println("testSchemaResultSet() run " + i + " of " + SCHEMA_LOOPS);
+            Schema schema = new Schema().schema(conn, "test", "a");
+            assertEquals(schema.getTableName(), "test");
         }
     }
+    
+    /**
+     * Get a connection. 
+     */
+    public static void getConnection()
+            throws ClassNotFoundException, SQLException
+    {
+        Class.forName(DB_DRIVER);
+        conn = DriverManager.getConnection(DB_CONNECTION);
+    }
 
     /**
-     * @TODO DOCUMENT ME!
+     * Print some debug info.
      *
-     * @param type @TODO DOCUMENT ME!
-     * @param e @TODO DOCUMENT ME!
+     * @param type
+     * @param e
      */
     public static void debug(int type, Exception e)
     {
@@ -518,10 +556,10 @@
     }
 
     /**
-     * @TODO DOCUMENT ME!
+     * Print some debug info.
      *
-     * @param type @TODO DOCUMENT ME!
-     * @param method @TODO DOCUMENT ME!
+     * @param type
+     * @param method
      */
     public static void debug(int type, String method)
     {
@@ -529,11 +567,11 @@
     }
 
     /**
-     * @TODO DOCUMENT ME!
+     * Print some debug info.
      *
-     * @param type @TODO DOCUMENT ME!
-     * @param method @TODO DOCUMENT ME!
-     * @param value @TODO DOCUMENT ME!
+     * @param type
+     * @param method
+     * @param value
      */
     public static void debug(int type, String method, int value)
     {
@@ -541,89 +579,11 @@
     }
 
     /**
-     * @TODO DOCUMENT ME!
-     *
-     * @param type @TODO DOCUMENT ME!
-     * @param test @TODO DOCUMENT ME!
-     * @param value @TODO DOCUMENT ME!
-     */
-    public static void test(int type, int test, int value)
-    {
-        if (debugging)
-        {
-            String name = "";
-
-            if (type == TDS)
-            {
-                name = "TableDataSet";
-            }
-            else
-            {
-                name = "QueryDataSet";
-            }
-
-            String val = "";
-
-            if (test == value)
-            {
-                val = "Passed";
-            }
-            else
-            {
-                val = "Failed";
-            }
-
-            System.out.print("[" + num++ + "] Test " + testCount++ + " - " + val + "!\n");
-
-            System.out.flush();
-        }
-    }
-
-    /**
-     * @TODO DOCUMENT ME!
-     *
-     * @param type @TODO DOCUMENT ME!
-     * @param test @TODO DOCUMENT ME!
-     * @param value @TODO DOCUMENT ME!
-     */
-    public static void test(int type, String test, String value)
-    {
-        if (debugging)
-        {
-            String name = "";
-
-            if (type == TDS)
-            {
-                name = "TableDataSet";
-            }
-            else
-            {
-                name = "QueryDataSet";
-            }
-
-            String val = "";
-
-            if (test.equals(value))
-            {
-                val = "Passed";
-            }
-            else
-            {
-                val = "Failed";
-            }
-
-            System.out.print("[" + num++ + "] Test " + testCount++ + " - " + val + "!\n");
-
-            System.out.flush();
-        }
-    }
-
-    /**
-     * @TODO DOCUMENT ME!
+     * Print some debug info.
      *
-     * @param type @TODO DOCUMENT ME!
-     * @param method @TODO DOCUMENT ME!
-     * @param value @TODO DOCUMENT ME!
+     * @param type
+     * @param method
+     * @param value
      */
     public static void debug(int type, String method, String value)
     {

Modified: db/torque/village/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/db/torque/village/trunk/xdocs/changes.xml?rev=619230&r1=619229&r2=619230&view=diff
==============================================================================
--- db/torque/village/trunk/xdocs/changes.xml (original)
+++ db/torque/village/trunk/xdocs/changes.xml Wed Feb  6 16:29:31 2008
@@ -1,41 +1,46 @@
-<?xml version="1.0"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements.  See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership.  The ASF licenses this file
- to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied.  See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-
-<document>
-  <properties>
-    <title>Changes</title>
-  </properties>
-
-  <body>
-  <release version="3.3-RC3" date="in SVN">
-    <action type="update" dev="tv">
-      Integration into Torque
-    </action>
-  </release>
-  <release version="2.0" date="2005-08-28">
-    <action type="update" dev="henning">
-      Added maven build
-    </action>
-    <action type="update" dev="henning">
-      Moved to subversion
-    </action>
-  </release>
-  </body>
-</document>
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<document>
+  <properties>
+    <title>Changes</title>
+  </properties>
+
+  <body>
+  <release version="3.3" date="in SVN">
+    <action type="update" dev="seade">
+      Refactored unit tests to use JUnit.  Added test case for TORQUE-8.
+    </action>
+  </release>
+  <release version="3.3-RC3" date="in SVN">
+    <action type="update" dev="tv">
+      Integration into Torque
+    </action>
+  </release>
+  <release version="2.0" date="2005-08-28">
+    <action type="update" dev="henning">
+      Added maven build
+    </action>
+    <action type="update" dev="henning">
+      Moved to subversion
+    </action>
+  </release>
+  </body>
+</document>



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message