db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker AnonymousFieldsTest.java
Date Thu, 13 May 2004 10:08:21 GMT
arminw      2004/05/13 03:08:20

  Modified:    src/test/org/apache/ojb/broker AnonymousFieldsTest.java
  Log:
  add new test for anonymous key using with proxy reference
  
  Revision  Changes    Path
  1.14      +109 -0    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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AnonymousFieldsTest.java	22 Apr 2004 16:12:35 -0000	1.13
  +++ AnonymousFieldsTest.java	13 May 2004 10:08:20 -0000	1.14
  @@ -10,6 +10,8 @@
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.junit.PBTestCase;
   
   /**
  @@ -382,6 +384,113 @@
           assertNotNull(aChild.getParentComponent());
           assertEquals(parent, aChild.getParentComponent());
           assertNotNull(lookedUpGroup);
  +    }
  +
  +    public void testSerializedObjectsRefreshWithProxy()
  +    {
  +        String prefix = "testSerializedObjectsRefreshWithProxy_" + System.currentTimeMillis()
+ "_";
  +
  +        ClassDescriptor cld = broker.getClassDescriptor(ObjectRepository.Component.class);
  +        ObjectReferenceDescriptor ord = cld.getObjectReferenceDescriptorByName("parentComponent");
  +        boolean oldState = ord.isLazy();
  +        try
  +        {
  +            ord.setLazy(true);
  +            ObjectRepository.Component parent = new ObjectRepository.Component();
  +            parent.setName(prefix + "main_component");
  +
  +            ObjectRepository.Component compSub1 = new ObjectRepository.Component();
  +            compSub1.setName(prefix + "sub_1");
  +
  +            ObjectRepository.Component compSub2 = new ObjectRepository.Component();
  +            compSub2.setName(prefix + "sub_2");
  +
  +            ObjectRepository.Component compSub3 = new ObjectRepository.Component();
  +            compSub2.setName(prefix + "sub_3");
  +
  +            ObjectRepository.Group group = new ObjectRepository.Group();
  +            group.setName(prefix + "test_group");
  +
  +            compSub1.setParentComponent(parent);
  +            compSub2.setParentComponent(parent);
  +            compSub3.setParentComponent(parent);
  +            ArrayList list = new ArrayList();
  +            list.add(compSub1);
  +            list.add(compSub2);
  +            list.add(compSub3);
  +            parent.setChildComponents(list);
  +            parent.setGroup(group);
  +
  +            broker.beginTransaction();
  +            broker.store(parent);
  +            broker.commitTransaction();
  +
  +            broker.clearCache();
  +            Query query = QueryFactory.newQuery(parent);
  +            parent = (ObjectRepository.Component) broker.getObjectByQuery(query);
  +
  +            Query groupQuery = QueryFactory.newQuery(group);
  +            ObjectRepository.Group lookedUpGroup = (ObjectRepository.Group) broker.getObjectByQuery(groupQuery);
  +
  +            assertNotNull(parent);
  +            assertNotNull(parent.getGroup());
  +            assertNotNull(parent.getChildComponents());
  +            assertNotNull(parent.getName());
  +            assertEquals(3, parent.getChildComponents().size());
  +            assertEquals(group.getName(), (parent.getGroup().getName()));
  +            ObjectRepository.Component aChild = (ObjectRepository.Component) parent.getChildComponents().iterator().next();
  +            assertNotNull(aChild);
  +            assertNotNull(aChild.getParentComponent());
  +            assertEquals(parent, aChild.getParentComponent());
  +            assertNotNull(lookedUpGroup);
  +
  +            //*************************************
  +            assertNotNull(parent);
  +            assertNotNull(parent.getGroup());
  +            parent = (ObjectRepository.Component) serializeDeserializeObject(parent);
  +            broker.retrieveAllReferences(parent);
  +            assertNotNull(parent);
  +            /*
  +            Now we have a problem! After serialization we can't find the anonymous keys
  +            for parent object, because object identity has changed!!
  +            This is now fixed in class QueryReferenceBroker#getReferencedObjectIdentity
  +            */
  +            assertNotNull(parent.getGroup());
  +            //*************************************
  +            assertNotNull(parent.getChildComponents());
  +            assertNotNull(parent.getName());
  +            assertEquals(3, parent.getChildComponents().size());
  +            aChild = (ObjectRepository.Component) parent.getChildComponents().iterator().next();
  +            assertNotNull(aChild);
  +            assertNotNull(aChild.getParentComponent());
  +            assertEquals(parent, aChild.getParentComponent());
  +
  +            broker.beginTransaction();
  +            broker.store(parent);
  +            broker.commitTransaction();
  +
  +            // now nothing should happen, because we don't make any changes
  +            broker.clearCache();
  +            query = QueryFactory.newQuery(parent);
  +            parent = (ObjectRepository.Component) broker.getObjectByQuery(query);
  +            groupQuery = QueryFactory.newQuery(group);
  +            lookedUpGroup = (ObjectRepository.Group) broker.getObjectByQuery(groupQuery);
  +            assertNotNull(parent);
  +            assertNotNull(parent.getGroup());
  +            assertNotNull(parent.getChildComponents());
  +            assertNotNull(parent.getName());
  +            assertEquals(3, parent.getChildComponents().size());
  +            assertEquals(group.getName(), (parent.getGroup().getName()));
  +            aChild = (ObjectRepository.Component) parent.getChildComponents().iterator().next();
  +            assertNotNull(aChild);
  +            assertNotNull(aChild.getParentComponent());
  +            assertEquals(parent, aChild.getParentComponent());
  +            assertNotNull(lookedUpGroup);
  +        }
  +        finally
  +        {
  +            ord.setLazy(oldState);
  +        }
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message