db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r367081 - /db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
Date Sun, 08 Jan 2006 20:05:09 GMT
Author: tv
Date: Sun Jan  8 12:05:06 2006
New Revision: 367081

URL: http://svn.apache.org/viewcvs?rev=367081&view=rev
Log:
Added test for doSelectAllExceptXXX()

Modified:
    db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java

Modified: db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java?rev=367081&r1=367080&r2=367081&view=diff
==============================================================================
--- db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java (original)
+++ db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java Sun Jan  8
12:05:06 2006
@@ -36,6 +36,8 @@
 import org.apache.torque.test.APeer;
 import org.apache.torque.test.Author;
 import org.apache.torque.test.AuthorPeer;
+import org.apache.torque.test.B;
+import org.apache.torque.test.BPeer;
 import org.apache.torque.test.BitTest;
 import org.apache.torque.test.BitTestPeer;
 import org.apache.torque.test.BlobTest;
@@ -44,6 +46,8 @@
 import org.apache.torque.test.BookPeer;
 import org.apache.torque.test.BooleanCheck;
 import org.apache.torque.test.BooleanCheckPeer;
+import org.apache.torque.test.C;
+import org.apache.torque.test.CPeer;
 import org.apache.torque.test.ClobTest;
 import org.apache.torque.test.ClobTestPeer;
 import org.apache.torque.test.DateTest;
@@ -58,6 +62,8 @@
 import org.apache.torque.test.MultiPkPeer;
 import org.apache.torque.test.NullValueTable;
 import org.apache.torque.test.NullValueTablePeer;
+import org.apache.torque.test.RAb;
+import org.apache.torque.test.RAbPeer;
 import org.apache.torque.util.BasePeer;
 import org.apache.torque.util.CountHelper;
 import org.apache.torque.util.Criteria;
@@ -71,6 +77,7 @@
  * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
  * @author <a href="mailto:patrick.carl@web.de">Patrick Carl</a>
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
  * @version $Id$
  */
 public class DataTest extends BaseRuntimeTestCase
@@ -671,6 +678,57 @@
     }
 
     /**
+     * Test joins using the XPeer.DoSelectJoinAllExceptYYY methods
+     * @throws Exception if the Test fails
+     */
+    public void testDoSelectJoinAllExceptY() throws Exception
+    {
+        cleanABC();
+        
+        // setup test data
+        A a = new A();
+        a.setName("test a");
+        a.save();
+        
+        B b = new B();
+        b.setName("test b");
+        b.save();
+        
+        RAb rab = new RAb();
+        rab.setName("test rab");
+        rab.setA(a);
+        rab.setB(b);
+        rab.save();
+        
+        C c = new C();
+        c.setName("test c");
+        c.setA(a);
+        c.setB(b);
+        c.setRAb(rab);
+        c.save();
+        
+        Criteria criteria =  new Criteria();
+        criteria.add(APeer.A_ID, a.getAId());
+        List list = MyCPeer.doSelectJoinAllExceptA(criteria);
+        assertTrue("list should contain 1 entry but contains "
+                + list.size(), list.size() == 1);
+        
+        C c1 = (C)list.get(0);
+        B b1 = c1.getB();
+        RAb rab1 = c1.getRAb();
+        
+        assertTrue("The name of c1 should be 'test c' but is " + c1.getName(),
+                c1.getName().equals("test c"));
+        assertTrue("The name of b1 should be 'test b' but is " + b1.getName(),
+                b1.getName().equals("test b"));
+        assertTrue("The name of rab1 should be 'test rab' but is " + rab1.getName(),
+                rab1.getName().equals("test rab"));
+        assertTrue ("The c's of b1 and rab1"
+                + " should point to the same instance",
+                b1.getCs().get(0) == rab1.getCs().get(0));
+    }
+
+    /**
      * test the order by, especially in joins and with aliases
      * @throws Exception if the test fails
      */
@@ -1093,10 +1151,7 @@
      */
     public void testSingleQuotes() throws Exception
     {
-        // clean A table
-        Criteria criteria = new Criteria();
-        criteria.add(APeer.A_ID, (Long) null, Criteria.NOT_EQUAL);
-        APeer.doDelete(criteria);
+        cleanABC();
 
         A a = new A();
         a.setName("has Single ' Quote");
@@ -1355,6 +1410,34 @@
         AuthorPeer.doDelete(criteria);
     }
 
+    /**
+     * Deletes all As, Bs, Cs and RAs
+     * @throws Exception if the cleanup fails
+     */
+    protected void cleanABC() throws Exception
+    {
+        // clean C table
+        Criteria criteria = new Criteria();
+        criteria.add(CPeer.C_ID, (Long) null, Criteria.NOT_EQUAL);
+        CPeer.doDelete(criteria);
+
+        // clean R_AB table
+        criteria.clear();
+        criteria.add(RAbPeer.A_ID, (Long) null, Criteria.NOT_EQUAL);
+        criteria.add(RAbPeer.B_ID, (Long) null, Criteria.NOT_EQUAL);
+        RAbPeer.doDelete(criteria);
+
+        // clean A table
+        criteria.clear();
+        criteria.add(APeer.A_ID, (Long) null, Criteria.NOT_EQUAL);
+        APeer.doDelete(criteria);
+
+        // clean B table
+        criteria.clear();
+        criteria.add(BPeer.B_ID, (Long) null, Criteria.NOT_EQUAL);
+        BPeer.doDelete(criteria);
+    }
+
 
     /**
      * Strips the schema and table name from a fully qualified colum name
@@ -1386,6 +1469,18 @@
                 throws TorqueException
         {
             return BookPeer.doSelectJoinAuthor(criteria);
+        }
+    }
+
+    /**
+     * Subclass of CPeer to make the doSelectJoinAllExceptA() visible
+     */
+    static class MyCPeer extends CPeer
+    {
+        public static List doSelectJoinAllExceptA(Criteria criteria)
+                throws TorqueException
+        {
+            return CPeer.doSelectJoinAllExceptA(criteria);
         }
     }
 }



---------------------------------------------------------------------
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