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/metadata ReadonlyTest.java
Date Mon, 05 Dec 2005 15:06:32 GMT
arminw      2005/12/05 07:06:32

  Modified:    src/test/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        ReadonlyTest.java
  Log:
  add new test, declare all non-PK fields read-only
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.4.1   +62 -19    db-ojb/src/test/org/apache/ojb/broker/metadata/ReadonlyTest.java
  
  Index: ReadonlyTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/metadata/ReadonlyTest.java,v
  retrieving revision 1.1
  retrieving revision 1.1.4.1
  diff -u -r1.1 -r1.1.4.1
  --- ReadonlyTest.java	9 Dec 2003 13:46:47 -0000	1.1
  +++ ReadonlyTest.java	5 Dec 2005 15:06:32 -0000	1.1.4.1
  @@ -6,42 +6,60 @@
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.junit.PBTestCase;
   
   /**
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class ReadonlyTest extends TestCase
  +public class ReadonlyTest extends PBTestCase
   {
  -    private PersistenceBroker broker;
  -
       public static void main(String[] args)
       {
           String[] arr = {ReadonlyTest.class.getName()};
           junit.textui.TestRunner.main(arr);
       }
   
  -    public void setUp() throws PBFactoryException
  +    public void setUp() throws Exception
       {
  -        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        super.setUp();
       }
   
  -    public void tearDown()
  +    public void tearDown() throws Exception
       {
  -        try
  -        {
  -            if(broker != null) broker.close();
  -        }
  -        catch (PersistenceBrokerException e)
  -        {
  -        }
  +        super.tearDown();
       }
   
       public void testReadonly() throws Exception
       {
           long timestamp = System.currentTimeMillis();
  -        TestObject obj = new TestObject(null, "readonly test_"+timestamp, "should not persisted",
new Long(timestamp));
  +        TestObject obj = new TestObject(null, "testReadonly_"+timestamp, "should not persisted",
new Long(timestamp));
  +
  +        broker.beginTransaction();
  +        broker.store(obj);
  +        broker.commitTransaction();
  +        broker.clearCache();
  +
  +        broker.beginTransaction();
  +        Identity oid = broker.serviceIdentity().buildIdentity(obj);
  +        TestObject ret_obj = (TestObject) broker.getObjectByIdentity(oid);
  +        broker.commitTransaction();
  +
  +        assertNotNull(ret_obj);
  +        assertNotNull(ret_obj.getName());
  +        assertNull("Field should not be populated", ret_obj.getReadonlyLong());
  +        assertNull("Field should not be populated", ret_obj.getReadonlyString());
  +    }
  +
  +    public void testReadonlyAll() throws Exception
  +    {
  +        long timestamp = System.currentTimeMillis();
  +        TestObject obj = new TestObject(null, "testReadonlyAll_"+timestamp, "should not
persisted", new Long(timestamp));
  +        ClassDescriptor cld = broker.getClassDescriptor(TestObject.class);
  +        FieldDescriptor fld_id = cld.getFieldDescriptorByName("objId");
  +        FieldDescriptor fld_name = cld.getFieldDescriptorByName("name");
  +
           try
           {
               broker.beginTransaction();
  @@ -50,21 +68,46 @@
               broker.clearCache();
   
               broker.beginTransaction();
  -            Identity oid = new Identity(obj, broker);
  +            Identity oid = broker.serviceIdentity().buildIdentity(obj);
               TestObject ret_obj = (TestObject) broker.getObjectByIdentity(oid);
               broker.commitTransaction();
   
  +            fld_id.setAccess("readonly");
  +            fld_name.setAccess("readonly");
  +
  +            assertNotNull(ret_obj);
  +            assertNotNull(ret_obj.getName());
  +            assertNull("Field should not be populated", ret_obj.getReadonlyLong());
  +            assertNull("Field should not be populated", ret_obj.getReadonlyString());
  +
  +            broker.beginTransaction();
  +            oid = broker.serviceIdentity().buildIdentity(obj);
  +            ret_obj = (TestObject) broker.getObjectByIdentity(oid);
  +            broker.store(ret_obj);
  +            broker.commitTransaction();
  +
               assertNotNull(ret_obj);
               assertNotNull(ret_obj.getName());
               assertNull("Field should not be populated", ret_obj.getReadonlyLong());
               assertNull("Field should not be populated", ret_obj.getReadonlyString());
  +
  +            broker.beginTransaction();
  +            oid = broker.serviceIdentity().buildIdentity(obj);
  +            ret_obj = (TestObject) broker.getObjectByIdentity(oid);
  +            // nevertheless we can remove the whole object
  +            broker.delete(ret_obj);
  +            broker.commitTransaction();
  +
  +            oid = broker.serviceIdentity().buildIdentity(obj);
  +            ret_obj = (TestObject) broker.getObjectByIdentity(oid);
  +
  +            assertNull(ret_obj);
           }
           finally
           {
  -            if(broker != null) broker.close();
  +            if(fld_id != null) fld_id.setAccess("readwrite");
  +            if(fld_name != null) fld_name.setAccess("readwrite");
           }
  -
  -
       }
   
       public static class TestObject
  
  
  

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