db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1296802 - in /db/torque/torque4/trunk/torque-test/src: main/schema/save-method-in-peer-schema.xml test/java/org/apache/torque/generated/peer/SaveMethodsInPeerTest.java
Date Sun, 04 Mar 2012 13:11:05 GMT
Author: tfischer
Date: Sun Mar  4 13:11:05 2012
New Revision: 1296802

URL: http://svn.apache.org/viewvc?rev=1296802&view=rev
Log:
TORQUE-180 Added tests

Added:
    db/torque/torque4/trunk/torque-test/src/main/schema/save-method-in-peer-schema.xml
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SaveMethodsInPeerTest.java

Added: db/torque/torque4/trunk/torque-test/src/main/schema/save-method-in-peer-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/save-method-in-peer-schema.xml?rev=1296802&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/save-method-in-peer-schema.xml (added)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/save-method-in-peer-schema.xml Sun
Mar  4 13:11:05 2012
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
+<!--
+ 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.
+-->
+<!-- this schema is used to test save methods in peers instead of dbObjects -->
+
+<database name="@DATABASE_DEFAULT@" 
+    defaultIdMethod="@DATABASE_ID_METHOD@"
+    package="org.apache.torque.test"
+    defaultJavaType="object">
+
+  <table name="save_method_in_peer" saveMethodsInDbObjects="false">
+    <column name="id" primaryKey="true" type="INTEGER"/>
+    <column name="payload" type="VARCHAR" size="20" />
+  </table>
+
+  <table name="save_method_in_peer_fk" saveMethodsInDbObjects="false">
+    <column name="id" primaryKey="true" type="INTEGER"/>
+    <column name="save_method_in_peer_id" type="INTEGER" />
+    <column name="payload" type="VARCHAR" size="20" />
+
+    <foreign-key foreignTable="save_method_in_peer">
+      <reference local="save_method_in_peer_id" foreign="id"/>
+    </foreign-key>
+  </table>
+
+  <table name="save_method_in_object_fk">
+    <column name="id" primaryKey="true" type="INTEGER"/>
+    <column name="save_method_in_peer_id" type="INTEGER" />
+    <column name="payload" type="VARCHAR" size="20" />
+
+    <foreign-key foreignTable="save_method_in_peer">
+      <reference local="save_method_in_peer_id" foreign="id"/>
+    </foreign-key>
+  </table>
+</database>

Added: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SaveMethodsInPeerTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SaveMethodsInPeerTest.java?rev=1296802&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SaveMethodsInPeerTest.java
(added)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SaveMethodsInPeerTest.java
Sun Mar  4 13:11:05 2012
@@ -0,0 +1,142 @@
+package org.apache.torque.generated.peer;
+
+/*
+ * 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.util.List;
+
+import org.apache.torque.BaseDatabaseTestCase;
+import org.apache.torque.criteria.Criteria;
+import org.apache.torque.test.SaveMethodInObjectFk;
+import org.apache.torque.test.SaveMethodInObjectFkPeer;
+import org.apache.torque.test.SaveMethodInPeer;
+import org.apache.torque.test.SaveMethodInPeerFk;
+import org.apache.torque.test.SaveMethodInPeerFkPeer;
+import org.apache.torque.test.SaveMethodInPeerPeer;
+import org.apache.torque.util.CountHelper;
+
+/**
+ * Tests whether the save methods work in the peer classes.
+ *
+ * @version $Id: DataTest.java 1103512 2011-05-15 19:37:41Z tfischer $
+ */
+public class SaveMethodsInPeerTest extends BaseDatabaseTestCase
+{
+    /**
+     * Tests the save method for a simple object.
+     *
+     * @throws Exception if a database error occurs.
+     */
+    public void testInsert() throws Exception
+    {
+        // prepare
+        SaveMethodInPeerFkPeer.doDelete(new Criteria());
+        SaveMethodInObjectFkPeer.doDelete(new Criteria());
+        SaveMethodInPeerPeer.doDelete(new Criteria());
+
+        SaveMethodInPeer toSave = new SaveMethodInPeer();
+        toSave.setPayload("payload 1");
+
+        // execute
+        SaveMethodInPeerPeer.save(toSave);
+
+        // verify
+        assertNotNull(toSave.getId());
+        assertEquals("payload 1", toSave.getPayload());
+
+        Criteria criteria = new Criteria()
+            .where(SaveMethodInPeerPeer.ID, toSave.getId())
+            .and(SaveMethodInPeerPeer.PAYLOAD, "payload 1");
+        List<SaveMethodInPeer> loadedList
+                = SaveMethodInPeerPeer.doSelect(criteria);
+        assertEquals(1, loadedList.size());
+
+        assertEquals(
+                1,
+                new CountHelper().count(SaveMethodInPeerPeer.getTableMap()));
+    }
+
+    /**
+     * Tests that the save method propagates "down" for a foreign key,
+     * i.e. if save is called on an object which contains another
+     * referencing object, the referencing object must also be saved.
+     *
+     * @throws Exception if a database error occurs.
+     */
+    public void testPropagationDown() throws Exception
+    {
+        // prepare
+        SaveMethodInPeerFkPeer.doDelete(new Criteria());
+        SaveMethodInObjectFkPeer.doDelete(new Criteria());
+        SaveMethodInPeerPeer.doDelete(new Criteria());
+
+        SaveMethodInPeer toSave = new SaveMethodInPeer();
+        toSave.setPayload("payload");
+        SaveMethodInPeerFk child1 = new SaveMethodInPeerFk();
+        toSave.addSaveMethodInPeerFk(child1);
+        child1.setPayload("payload 1");
+        SaveMethodInObjectFk child2 = new SaveMethodInObjectFk();
+        toSave.addSaveMethodInObjectFk(child2);
+        child2.setPayload("payload 2");
+
+        // execute
+        SaveMethodInPeerPeer.save(toSave);
+
+        // verify
+        assertNotNull(toSave.getId());
+        assertEquals("payload", toSave.getPayload());
+        assertNotNull(child1.getId());
+        assertEquals("payload 1", child1.getPayload());
+        assertNotNull(child2.getId());
+        assertEquals("payload 2", child2.getPayload());
+
+        Criteria criteria = new Criteria()
+            .where(SaveMethodInPeerPeer.ID, toSave.getId())
+            .and(SaveMethodInPeerPeer.PAYLOAD, "payload");
+        List<SaveMethodInPeer> loadedList
+                = SaveMethodInPeerPeer.doSelect(criteria);
+        assertEquals(1, loadedList.size());
+        assertEquals(
+                1,
+                new CountHelper().count(SaveMethodInPeerPeer.getTableMap()));
+
+        criteria = new Criteria()
+            .where(SaveMethodInPeerFkPeer.SAVE_METHOD_IN_PEER_ID, toSave.getId())
+            .and(SaveMethodInPeerFkPeer.ID, child1.getId())
+            .and(SaveMethodInPeerFkPeer.PAYLOAD, "payload 1");
+        List<SaveMethodInPeerFk> child1List
+                = SaveMethodInPeerFkPeer.doSelect(criteria);
+        assertEquals(1, child1List.size());
+        assertEquals(
+                1,
+                new CountHelper().count(SaveMethodInPeerFkPeer.getTableMap()));
+
+        criteria = new Criteria()
+            .where(SaveMethodInObjectFkPeer.SAVE_METHOD_IN_PEER_ID, toSave.getId())
+            .and(SaveMethodInObjectFkPeer.ID, child2.getId())
+            .and(SaveMethodInObjectFkPeer.PAYLOAD, "payload 2");
+        List<SaveMethodInObjectFk> child2List
+                = SaveMethodInObjectFkPeer.doSelect(criteria);
+        assertEquals(1, child2List.size());
+        assertEquals(
+                1,
+                new CountHelper().count(
+                        SaveMethodInObjectFkPeer.getTableMap()));
+    }
+}



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