tfischer 2004/12/16 00:04:36
Modified: src/rttest/org/apache/torque Tag: TORQUE_3_1_BRANCH
DataTest.java
Log:
Added a test case which tests whether same column names in different tables
are handled correctly
Codestyle: Some corrections to positions of braces
Revision Changes Path
No revision
No revision
1.8.2.5 +66 -8 db-torque/src/rttest/org/apache/torque/DataTest.java
Index: DataTest.java
===================================================================
RCS file: /home/cvs/db-torque/src/rttest/org/apache/torque/DataTest.java,v
retrieving revision 1.8.2.4
retrieving revision 1.8.2.5
diff -u -r1.8.2.4 -r1.8.2.5
--- DataTest.java 6 Dec 2004 19:53:54 -0000 1.8.2.4
+++ DataTest.java 16 Dec 2004 08:04:36 -0000 1.8.2.5
@@ -34,6 +34,8 @@
import org.apache.torque.util.BasePeer;
import org.apache.torque.util.Criteria;
+import com.workingdogs.village.Record;
+
/**
* Runtime tests.
*
@@ -248,7 +250,8 @@
/**
* test whether delete works as expected
*/
- public void testDelete() {
+ public void testDelete()
+ {
cleanBookstore();
Author author = null;
Book book = null;
@@ -339,7 +342,8 @@
/**
* test special cases in the select clause
*/
- public void testSelectClause() {
+ public void testSelectClause()
+ {
// test double functions in select columns
Criteria criteria = new Criteria();
criteria.addSelectColumn("count(distinct(" + BookPeer.BOOK_ID +
"))");
@@ -360,7 +364,8 @@
/**
* test joins
*/
- public void testJoins() {
+ public void testJoins()
+ {
cleanBookstore();
try
{
@@ -494,7 +499,8 @@
/**
* test the order by, especially in joins and with aliases
*/
- public void testOrderBy() {
+ public void testOrderBy()
+ {
cleanBookstore();
try
{
@@ -667,7 +673,8 @@
/**
* Tests whether ignoreCase works correctly
*/
- public void testIgnoreCase() {
+ public void testIgnoreCase()
+ {
cleanBookstore();
try
{
@@ -696,7 +703,8 @@
/**
* tests AsColumns produce valid SQL code
*/
- public void testAsColumn() {
+ public void testAsColumn()
+ {
try
{
Criteria criteria = new Criteria();
@@ -714,11 +722,61 @@
+ " : " + e.getMessage());
}
}
+
+ /**
+ * Test whether same column name in different tables
+ * are handled correctly
+ */
+ public void testSameColumnName()
+ {
+ try
+ {
+ cleanBookstore();
+ Author author = new Author();
+ author.setName("Name");
+ author.save();
+
+ author = new Author();
+ author.setName("NotCorrespondingName");
+ author.save();
+
+ Book book = new Book();
+ book.setTitle("Name");
+ book.setAuthor(author);
+ book.setIsbn("unknown");
+ book.save();
+
+ Criteria criteria = new Criteria();
+ criteria.addJoin(BookPeer.TITLE, AuthorPeer.NAME);
+ BookPeer.addSelectColumns(criteria);
+ AuthorPeer.addSelectColumns(criteria);
+ // basically a BaseBookPeer.setDbName(criteria);
+ // and BasePeer.doSelect(criteria);
+ List villageRecords = BookPeer.doSelectVillageRecords(criteria);
+ Record record = (Record) villageRecords.get(0);
+ book = new Book();
+ BookPeer.populateObject(record, 1, book);
+ author = new Author();
+ AuthorPeer.populateObject(record, BookPeer.numColumns + 1,
author);
+ if (book.getAuthorId() == author.getAuthorId()) {
+ fail("wrong Ids read");
+ }
+ }
+ catch( Exception e)
+ {
+ e.printStackTrace();
+ fail("Exception caught : "
+ + e.getClass().getName()
+ + " : " + e.getMessage());
+ }
+ }
+
/**
* Deletes all authors and books in the bookstore tables
*/
- protected void cleanBookstore() {
+ protected void cleanBookstore()
+ {
Criteria criteria = new Criteria();
criteria.add(BookPeer.BOOK_ID, (Long) null, Criteria.NOT_EQUAL);
try
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]