Author: arminw
Date: Wed Oct 4 04:28:42 2006
New Revision: 452843
URL: http://svn.apache.org/viewvc?view=rev&rev=452843
Log:
add new test
Modified:
db/ojb/trunk/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java
Modified:
db/ojb/trunk/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java
URL:
http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java?view=diff&rev=452843&r1=452842&r2=452843
==============================================================================
---
db/ojb/trunk/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java
(original)
+++
db/ojb/trunk/src/test/org/apache/ojb/broker/BidirectionalAssociationTest.java
Wed Oct 4 04:28:42 2006
@@ -3,12 +3,15 @@
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.ojb.broker.query.ReportQueryByCriteria;
import org.apache.ojb.broker.util.ObjectModification;
import org.apache.ojb.junit.PBTestCase;
@@ -37,6 +40,42 @@
public void tearDown() throws Exception
{
super.tearDown();
+ }
+
+ public void testQuery()
+ {
+ ojbChangeReferenceSetting(ObjectA.class, "relatedB", true,
+ ObjectReferenceDescriptor.CASCADE_OBJECT,
ObjectReferenceDescriptor.CASCADE_OBJECT, false);
+ ojbChangeReferenceSetting(ObjectB.class, "relatedA", true,
+ ObjectReferenceDescriptor.CASCADE_OBJECT,
ObjectReferenceDescriptor.CASCADE_OBJECT, false);
+
+ String postfix = "testQuery_" + System.currentTimeMillis();
+
+ String aPK = "a_" + postfix;
+ String bPK = "b_" + postfix;
+ ObjectA a = new ObjectA();
+ ObjectB b = new ObjectB();
+ a.setPk(aPK);
+ b.setPk(bPK);
+ broker.beginTransaction();
+ // first store both objects
+ broker.store(a, ObjectModification.INSERT);
+ broker.store(b, ObjectModification.INSERT);
+ // now set references
+ a.setRelatedB(b);
+ b.setRelatedA(a);
+ // update both
+ broker.store(a, ObjectModification.UPDATE);
+ broker.commitTransaction();
+
+ Criteria c = new Criteria()
+ .addEqualTo("pk", aPK)
+ .addEqualTo("relatedB.pk", bPK);
+ ReportQueryByCriteria query =
QueryFactory.newReportQuery(ObjectA.class, c);
+ query.setAttributes(new String[] {"pk"});
+
+ List result = new ArrayList(broker.getCollectionByQuery(query));
+ assertEquals(1, result.size());
}
public void testCreateDeleteWithAutoincrement_1()
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]