You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by br...@apache.org on 2003/10/01 20:57:09 UTC
cvs commit: db-ojb/src/test/org/apache/ojb/broker AnonymousFieldsTest.java
brj 2003/10/01 11:57:09
Modified: src/test/org/apache/ojb/broker AnonymousFieldsTest.java
Log:
new testcases for multilevel hierarchy
Revision Changes Path
1.9 +106 -69 db-ojb/src/test/org/apache/ojb/broker/AnonymousFieldsTest.java
Index: AnonymousFieldsTest.java
===================================================================
RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AnonymousFieldsTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AnonymousFieldsTest.java 19 Sep 2003 19:07:21 -0000 1.8
+++ AnonymousFieldsTest.java 1 Oct 2003 18:57:09 -0000 1.9
@@ -1,12 +1,14 @@
package org.apache.ojb.broker;
+import java.util.Collection;
+
import junit.framework.TestCase;
+import org.apache.ojb.broker.ObjectRepository.F1;
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.query.QueryByCriteria;
import org.apache.ojb.broker.query.QueryFactory;
-import java.util.Collection;
-
/**
* This TestClass tests the anonymous fields feature.
*/
@@ -14,34 +16,34 @@
{
public static void main(String[] args)
{
- String[] arr = {AnonymousFieldsTest.class.getName()};
+ String[] arr = { AnonymousFieldsTest.class.getName()};
junit.textui.TestRunner.main(arr);
}
private PersistenceBroker broker;
/**
- * Insert the method's description here.
- * Creation date: (24.12.2000 00:33:40)
- */
+ * Insert the method's description here. Creation date: (24.12.2000
+ * 00:33:40)
+ */
public AnonymousFieldsTest(String name)
{
super(name);
}
/**
- * Insert the method's description here.
- * Creation date: (06.12.2000 21:58:53)
- */
+ * Insert the method's description here. Creation date: (06.12.2000
+ * 21:58:53)
+ */
public void setUp() throws Exception
{
broker = PersistenceBrokerFactory.defaultPersistenceBroker();
}
/**
- * Insert the method's description here.
- * Creation date: (06.12.2000 21:59:14)
- */
+ * Insert the method's description here. Creation date: (06.12.2000
+ * 21:59:14)
+ */
public void tearDown()
{
try
@@ -54,34 +56,32 @@
}
}
-
/**
- * write an entry using vertical inheritance and try to read it again.
- * E-F
- */
+ * write an entry using vertical inheritance and try to read it again. E-F
+ */
public void testVerticalInheritanceStoreAndLoad() throws Exception
{
- // produce some test data
- ObjectRepository.F entry = new ObjectRepository.F();
- entry.setSomeSuperValue(31415926);
- entry.setSomeValue(123456);
- broker.store(entry);
+ // produce some test data
+ ObjectRepository.F entry = new ObjectRepository.F();
+ entry.setSomeSuperValue(31415926);
+ entry.setSomeValue(123456);
+ broker.store(entry);
Identity oid = new Identity(entry, broker);
-
- // clear cache and retrieve a copy from the DB
- broker.clearCache();
- ObjectRepository.F copy = (ObjectRepository.F) broker.getObjectByIdentity(oid);
- // check equality
- assertEquals(entry.getSomeValue(), copy.getSomeValue());
- assertEquals(entry.getSomeSuperValue(), copy.getSomeSuperValue());
+ // clear cache and retrieve a copy from the DB
+ broker.clearCache();
+ ObjectRepository.F copy = (ObjectRepository.F) broker.getObjectByIdentity(oid);
+
+ // check equality
+ assertEquals(entry.getSomeValue(), copy.getSomeValue());
+ assertEquals(entry.getSomeSuperValue(), copy.getSomeSuperValue());
}
/**
- * write an entry using vertical inheritance and try to read it again.
- * E-F-G
- */
+ * write an entry using vertical inheritance and try to read it again.
+ * E-F-G
+ */
public void testVerticalInheritanceStoreAndLoad2() throws Exception
{
// produce some test data G
@@ -104,10 +104,10 @@
}
/**
- * write an entry using vertical inheritance and try to read it again.
- * E-F1-G1, autoincrement id in E
- */
- public void _fails_testVerticalInheritanceStoreAndLoad3() throws Exception
+ * write an entry using vertical inheritance and try to read it again.
+ * E-F1-G1, autoincrement id in E
+ */
+ public void testVerticalInheritanceStoreAndLoad3() throws Exception
{
// produce some test data G1
ObjectRepository.G1 entry = new ObjectRepository.G1();
@@ -115,7 +115,7 @@
entry.setSomeValue(123456);
entry.setSomeSubValue(4242);
broker.store(entry);
-
+
Identity oid = new Identity(entry, broker);
// clear cache and retrieve a copy from the DB
@@ -127,38 +127,37 @@
assertEquals(entry.getSomeSuperValue(), copy.getSomeSuperValue());
assertEquals(entry.getSomeSubValue(), copy.getSomeSubValue());
}
-
+
/**
- * write an entry using vertical inheritance and try to read it again.
- * E-F
- */
+ * write an entry using vertical inheritance and try to read it again. E-F
+ */
public void testVerticalInheritanceUpdate() throws Exception
{
- // produce some test data
- ObjectRepository.F entry = new ObjectRepository.F();
- entry.setSomeSuperValue(2718281);
- entry.setSomeValue(9999);
- broker.store(entry);
+ // produce some test data
+ ObjectRepository.F entry = new ObjectRepository.F();
+ entry.setSomeSuperValue(2718281);
+ entry.setSomeValue(9999);
+ broker.store(entry);
Identity oid = new Identity(entry, broker);
-
- entry.setSomeSuperValue(2718282);
- entry.setSomeValue(10000);
- broker.store(entry);
- // clear cache and retrieve a copy from the DB
- broker.clearCache();
- ObjectRepository.F copy = (ObjectRepository.F) broker.getObjectByIdentity(oid);
+ entry.setSomeSuperValue(2718282);
+ entry.setSomeValue(10000);
+ broker.store(entry);
+
+ // clear cache and retrieve a copy from the DB
+ broker.clearCache();
+ ObjectRepository.F copy = (ObjectRepository.F) broker.getObjectByIdentity(oid);
- // check equality
- assertEquals(entry.getSomeValue(), copy.getSomeValue());
- assertEquals(entry.getSomeSuperValue(), copy.getSomeSuperValue());
+ // check equality
+ assertEquals(entry.getSomeValue(), copy.getSomeValue());
+ assertEquals(entry.getSomeSuperValue(), copy.getSomeSuperValue());
}
/**
- * write an entry using vertical inheritance and try to read it again.
- * E-F-G
- */
+ * write an entry using vertical inheritance and try to read it again.
+ * E-F-G
+ */
public void testVerticalInheritanceUpdate2() throws Exception
{
// produce some test data
@@ -169,7 +168,7 @@
broker.store(entry);
Identity oid = new Identity(entry, broker);
-
+
entry.setSomeSuperValue(2718282);
entry.setSomeValue(10000);
entry.setSomeSubValue(7777);
@@ -186,10 +185,10 @@
}
/**
- * write an entry using vertical inheritance and try to read it again.
- * E-F1-G1, autoincrement id in E
- */
- public void _fails_testVerticalInheritanceUpdate3() throws Exception
+ * write an entry using vertical inheritance and try to read it again.
+ * E-F1-G1, autoincrement id in E
+ */
+ public void testVerticalInheritanceUpdate3() throws Exception
{
// produce some test data
ObjectRepository.G1 entry = new ObjectRepository.G1();
@@ -216,9 +215,8 @@
}
/**
- * Query Attribute of Super class
- * E-F
- */
+ * Query Attribute of Super class E-F
+ */
public void testQuerySuperField()
{
int data1 = (int) (Math.random() * Integer.MAX_VALUE);
@@ -249,9 +247,8 @@
}
/**
- * Query Attribute of Super class
- * E-F-G
- */
+ * Query Attribute of Super class E-F-G
+ */
public void testQuerySuperField2()
{
int data1 = (int) (Math.random() * Integer.MAX_VALUE);
@@ -284,5 +281,45 @@
assertEquals(data1, ret.getSomeValue());
assertEquals(data2, ret.getSomeSuperValue());
assertEquals(data3, ret.getSomeSubValue());
+ }
+
+ public void testMultipleJoinedInheritanceAndExtents()
+ {
+ ObjectRepository.F1 entry = new ObjectRepository.F1();
+ entry.setSomeSuperValue(1);
+ entry.setSomeValue(2);
+ broker.store(entry);
+ int id = entry.getId();
+ broker.clearCache();
+ entry = (F1) findById(ObjectRepository.F1.class, id);
+ assertEquals(id, entry.getId());
+ assertEquals(1, entry.getSomeSuperValue());
+ assertEquals(2, entry.getSomeValue());
+ }
+
+
+ // --------------------------------------------------------------------------------------
+ // Utiltity methods.
+ private Object findById(Class type, int id)
+ {
+ Collection result = broker.getCollectionByQuery(createQueryById(type,id));
+ if (result == null || result.size() == 0)
+ {
+ return null;
+ }
+ if (result.size() > 1)
+ {
+ throw new RuntimeException("Unexpected unique id constraint violation ");
+ }
+
+ return result.iterator().next();
+
+ }
+
+ private Query createQueryById(Class type, int id)
+ {
+ Criteria byIdCriteria = new Criteria();
+ byIdCriteria.addEqualTo("id", new Integer(id));
+ return new QueryByCriteria(type, byIdCriteria);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org