Return-Path:
Delivered-To: apmail-db-torque-dev-archive@www.apache.org
Received: (qmail 26726 invoked from network); 31 Oct 2007 12:53:25 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2)
by minotaur.apache.org with SMTP; 31 Oct 2007 12:53:25 -0000
Received: (qmail 7173 invoked by uid 500); 31 Oct 2007 12:53:13 -0000
Delivered-To: apmail-db-torque-dev-archive@db.apache.org
Received: (qmail 7063 invoked by uid 500); 31 Oct 2007 12:53:13 -0000
Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm
Precedence: bulk
List-Unsubscribe:
List-Help:
List-Post:
List-Id: "Apache Torque Developers List"
Reply-To: "Apache Torque Developers List"
Delivered-To: mailing list torque-dev@db.apache.org
Received: (qmail 7052 invoked by uid 500); 31 Oct 2007 12:53:13 -0000
Received: (qmail 7048 invoked by uid 99); 31 Oct 2007 12:53:13 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Oct 2007 05:53:13 -0700
X-ASF-Spam-Status: No, hits=-100.0 required=10.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3)
by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Oct 2007 12:53:26 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id 3B3731A9832; Wed, 31 Oct 2007 05:52:49 -0700 (PDT)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r590655 - in
/db/torque/village/trunk/src/test/com/workingdogs/village: ./ TestMySQL.java
Date: Wed, 31 Oct 2007 12:52:48 -0000
To: torque-commits@db.apache.org
From: tv@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20071031125249.3B3731A9832@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: tv
Date: Wed Oct 31 05:52:43 2007
New Revision: 590655
URL: http://svn.apache.org/viewvc?rev=590655&view=rev
Log:
Initial import according to vote in
<471D3272.7040701@backstagetech.com.au>
Added:
db/torque/village/trunk/src/test/com/workingdogs/village/
db/torque/village/trunk/src/test/com/workingdogs/village/TestMySQL.java
Added: 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=590655&view=auto
==============================================================================
--- db/torque/village/trunk/src/test/com/workingdogs/village/TestMySQL.java (added)
+++ db/torque/village/trunk/src/test/com/workingdogs/village/TestMySQL.java Wed Oct 31 05:52:43 2007
@@ -0,0 +1,655 @@
+package com.workingdogs.village;
+
+/*
+ * 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.
+ */
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+/**
+ * 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.
+ *
+ *
+ * In order to do the testing, you will need to be able to connect via JDBC to your database. Since I use MySQL http://www.mysql.com/ , this testing suite is best for that database. I also use the mm MySQL
+ * drivers http://www.worldserver.com/mm.mysql/ because it is the best driver
+ * that I have found for MySQL.
+ *
+ *
+ *
+ * Note that Village should work with any JDBC compliant driver.
+ *
+ *
+ *
+ * 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 ):
+ *
+ * CREATE TABLE test
+ * (
+ * a TINYINT null,
+ * b SMALLINT null,
+ * c MEDIUMINT null,
+ * d INT null,
+ * e INTEGER null,
+ * f BIGINT null,
+ * g REAL null,
+ * h DOUBLE null,
+ * i FLOAT null,
+ * j DECIMAL(8,1) null,
+ * k NUMERIC(8,1) null,
+ * l CHAR(255) null,
+ * m VARCHAR(255) null,
+ * n DATE null,
+ * o TIME null,
+ * p TIMESTAMP null,
+ * q DATETIME null,
+ * r TINYBLOB null,
+ * s BLOB null,
+ * t MEDIUMBLOB null,
+ * u LONGBLOB null,
+ * v TINYTEXT null,
+ * w TEXT null,
+ * x MEDIUMTEXT null
+ * );
+ *
+ *
+ *
+ * @author Jon S. Stevens
+ * @version $Revision: 565 $
+ */
+public class TestMySQL
+{
+ /** The database connection */
+ static Connection conn;
+
+ /** This is the name of the database. Created with mysqladmin create */
+ private static String DB_NAME = "village";
+
+ /** This is the name of the table in the DB_NAME */
+ private static String DB_TABLE = "test";
+
+ /** This is the name of the machine that is hosting the MySQL server */
+ 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.
+ */
+ private static String DB_USER = "";
+
+ /** the password for the user */
+ private static String DB_PASS = "";
+
+ /** mm MySQL Driver setup */
+ private static String DB_DRIVER = "org.gjt.mm.mysql.Driver";
+
+ /** mm MySQL Driver setup */
+ 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;
+
+ /** used for debugging */
+ private static int num = 1;
+
+ /** used for debugging */
+ private static int testCount = 1;
+
+ /** used for debugging */
+ private static int TDS = 1;
+
+ /** used for debugging */
+ private static int QDS = 2;
+
+ /** used for debugging */
+ private static int PASSED = 1;
+
+ /** used for debugging */
+ private static int FAILED = 2;
+
+ /**
+ * @TODO DOCUMENT ME!
+ *
+ * @param argv @TODO DOCUMENT ME!
+ */
+ public static void main(String [] argv)
+ {
+ if ((argv.length > 0) && (argv.length < 5))
+ {
+ System.out.println("Format: TestMySQL ");
+
+ 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();
+ // testTableDataSet2();
+ // testTableDataSet3();
+ // testTableDataSet4();
+ // testRemoveRecord();
+ }
+
+ /**
+ * This test verifies that deleting multiple records actually works. after execution, there should be no more records in the
+ * database.
+ */
+ public static void testDeleteSomeRecords()
+ {
+ 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());
+ }
+
+ tds.save();
+ tds.close();
+ }
+ catch (Exception e)
+ {
+ debug(TDS, e);
+ }
+ }
+
+ /**
+ * This test will throw a DataSetException. The first getRecord will succeed and the second one will fail.
+ */
+ public static void testRemoveRecord()
+ {
+ try
+ {
+ TableDataSet tds = new TableDataSet(conn, DB_TABLE);
+ tds.addRecord();
+
+ Record rec = tds.getRecord(0);
+ tds.removeRecord(rec);
+
+ Record foo = tds.getRecord(0);
+ tds.close();
+ }
+ catch (Exception e)
+ {
+ debug(TDS, e);
+ }
+ }
+
+ /**
+ * @TODO DOCUMENT ME!
+ */
+ public static void testTableDataSet2()
+ {
+ 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);
+ }
+ }
+
+ /**
+ * @TODO DOCUMENT ME!
+ */
+ public static void testTableDataSet3()
+ {
+ 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);
+ }
+ }
+
+ /**
+ * @TODO DOCUMENT ME!
+ */
+ public static void testTableDataSet4()
+ {
+ 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);
+ }
+ }
+
+ /**
+ * @TODO DOCUMENT ME!
+ */
+ public static void testTableDataSet()
+ {
+ 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());
+
+ tds.close();
+ }
+ catch (Exception e)
+ {
+ debug(TDS, e);
+ }
+ }
+
+ /**
+ * @TODO DOCUMENT ME!
+ */
+ public static void testQueryDataSet()
+ {
+ 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);
+ }
+ }
+
+ /**
+ * @TODO DOCUMENT ME!
+ */
+ public static void getConnection()
+ {
+ try
+ {
+ Class.forName(DB_DRIVER);
+ conn = DriverManager.getConnection(DB_CONNECTION);
+ }
+ catch (Exception e)
+ {
+ System.out.println("\n\nConnection failed : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @TODO DOCUMENT ME!
+ *
+ * @param type @TODO DOCUMENT ME!
+ * @param e @TODO DOCUMENT ME!
+ */
+ public static void debug(int type, Exception e)
+ {
+ debug(TDS, e.getMessage());
+ e.printStackTrace();
+ System.out.println("\n");
+ }
+
+ /**
+ * @TODO DOCUMENT ME!
+ *
+ * @param type @TODO DOCUMENT ME!
+ * @param method @TODO DOCUMENT ME!
+ */
+ public static void debug(int type, String method)
+ {
+ debug(type, method, null);
+ }
+
+ /**
+ * @TODO DOCUMENT ME!
+ *
+ * @param type @TODO DOCUMENT ME!
+ * @param method @TODO DOCUMENT ME!
+ * @param value @TODO DOCUMENT ME!
+ */
+ public static void debug(int type, String method, int value)
+ {
+ debug(type, method, String.valueOf(value));
+ }
+
+ /**
+ * @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!
+ *
+ * @param type @TODO DOCUMENT ME!
+ * @param method @TODO DOCUMENT ME!
+ * @param value @TODO DOCUMENT ME!
+ */
+ public static void debug(int type, String method, String value)
+ {
+ if (debugging)
+ {
+ String name = "";
+
+ if (type == TDS)
+ {
+ name = "TableDataSet";
+ }
+ else
+ {
+ name = "QueryDataSet";
+ }
+
+ if (value != null)
+ {
+ System.out.print("[" + num++ + "] " + name + " - " + method + " = " + value + "\n");
+ }
+ else
+ {
+ System.out.print("[" + num++ + "] " + name + " - " + method + "\n");
+ }
+
+ System.out.flush();
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org