db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r422236 [3/3] - in /db/ojb/trunk/src: schema/ test/org/apache/ojb/broker/ test/org/apache/ojb/broker/cache/ test/org/apache/ojb/broker/cloneable/ test/org/apache/ojb/broker/metadata/ test/org/apache/ojb/broker/metadata/torque/
Date Sat, 15 Jul 2006 14:38:16 GMT
Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/PersistentFieldTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/PersistentFieldTest.java?rev=422236&r1=422235&r2=422236&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/PersistentFieldTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/PersistentFieldTest.java Sat Jul
15 07:38:14 2006
@@ -30,6 +30,7 @@
 import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDynaBeanImpl;
 import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldIntrospectorImpl;
 import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldPrivilegedImpl;
+import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldCGLibImpl;
 import org.apache.ojb.broker.util.ClassHelper;
 import org.apache.ojb.junit.OJBTestCase;
 
@@ -44,6 +45,7 @@
 {
     Class[] persistentFieldClasses = new Class[]{
         PersistentFieldDirectImpl.class
+        , PersistentFieldCGLibImpl.class
         , PersistentFieldIntrospectorImpl.class
         , PersistentFieldPrivilegedImpl.class
         , PersistentFieldAutoProxyImpl.class
@@ -241,6 +243,43 @@
         assertEquals("XXXX", result);
     }
 
+    public void testPersistentFieldAuto() throws Exception
+    {
+        PersistentField pf_id = new PersistentFieldAutoProxyImpl(TestObj.class, "id");
+        PersistentField pf_name = new PersistentFieldAutoProxyImpl(TestObj.class, "name");
+        PersistentField pf_int = new PersistentFieldAutoProxyImpl(TestObj.class, "aInt");
+        PersistentField pf_value = new PersistentFieldAutoProxyImpl(TestObj.class, "value");
+
+        TestObj obj = new TestObj(new Integer(17), "name", 33, "value");
+
+        assertEquals(new Integer(17), pf_id.get(obj));
+        assertEquals("name", pf_name.get(obj));
+        assertEquals(new Integer(33), pf_int.get(obj));
+        assertEquals("value", pf_value.get(obj));
+
+        pf_id.set(obj, new Integer(222));
+        pf_name.set(obj, "new");
+        pf_int.set(obj, new Integer(111));
+        pf_value.set(obj, "new_value");
+
+        assertEquals(new Integer(222), pf_id.get(obj));
+        assertEquals("new", pf_name.get(obj));
+        assertEquals(new Integer(111), pf_int.get(obj));
+        assertEquals("new_value", pf_value.get(obj));
+
+        // test for exception
+        try
+        {
+            PersistentField pf_NotExist = new PersistentFieldAutoProxyImpl(TestObj.class,
"not_exist");
+            pf_NotExist.get(obj);
+            fail("Expect error for invalid field");
+        }
+        catch(Exception expected)
+        {
+            //expected.printStackTrace();
+            // is expected
+        }
+    }
 
     //************************************************************************
     // helper methods
@@ -523,6 +562,51 @@
         public void setName(String name)
         {
             this.name = name;
+        }
+    }
+
+    abstract static class Base
+    {
+        Integer id;
+        private String name;
+        int aInt;
+
+        protected Base(Integer id, String name, int aInt)
+        {
+            this.id = id;
+            this.name = name;
+            this.aInt = aInt;
+        }
+    }
+
+    public static class TestObj extends Base
+    {
+        private String value;
+
+        public TestObj(Integer id, String name, int aInt, String value)
+        {
+            super(id, name, aInt);
+            this.value = value;
+        }
+
+        public int getaInt()
+        {
+            return aInt;
+        }
+
+        public void setaInt(int aInt)
+        {
+            this.aInt = aInt;
+        }
+
+        public String getValue()
+        {
+            return value;
+        }
+
+        public void setValue(String value)
+        {
+            this.value = value;
         }
     }
 }

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/ReadonlyTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/ReadonlyTest.java?rev=422236&r1=422235&r2=422236&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/ReadonlyTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/ReadonlyTest.java Sat Jul 15 07:38:14
2006
@@ -16,10 +16,45 @@
         junit.textui.TestRunner.main(arr);
     }
 
+    public void setUp() throws Exception
+    {
+        super.setUp();
+    }
+
+    public void tearDown() throws Exception
+    {
+        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();
@@ -28,21 +63,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

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/RepositoryPersistorTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/RepositoryPersistorTest.java?rev=422236&r1=422235&r2=422236&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/RepositoryPersistorTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/RepositoryPersistorTest.java Sat
Jul 15 07:38:14 2006
@@ -51,7 +51,7 @@
             numClasses++;
         }
 
-        RepositoryPersistor persistor = ojb.getMetadataManager().getRepositoryPersistor();
+        RepositoryPersistor persistor = ojb.getMetadataManager().createRepositoryPersistor();
         FileOutputStream fos = new FileOutputStream(fileNew);
         persistor.writeToFile(repository, conRepository, fos);
 
@@ -79,7 +79,7 @@
         int connectionCount = conRepository.getAllDescriptor().size();
 
         FileOutputStream fos = new FileOutputStream(filename);
-        RepositoryPersistor persistor = ojb.getMetadataManager().getRepositoryPersistor();
+        RepositoryPersistor persistor = ojb.getMetadataManager().createRepositoryPersistor();
         persistor.writeToFile(repository, conRepository, fos);
 
         ConnectionRepository second = persistor.readConnectionRepository(filename);

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueForeignKeyGeneratorTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueForeignKeyGeneratorTest.java?rev=422236&r1=422235&r2=422236&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueForeignKeyGeneratorTest.java
(original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueForeignKeyGeneratorTest.java
Sat Jul 15 07:38:14 2006
@@ -49,7 +49,7 @@
     public void setUp() throws Exception
     {
         super.setUp();
-        RepositoryPersistor repositoryPersistor = ojb.getMetadataManager().getRepositoryPersistor();
+        RepositoryPersistor repositoryPersistor = ojb.getMetadataManager().createRepositoryPersistor();
         DescriptorRepository descriptorRepository = repositoryPersistor.readDescriptorRepository(EXAMPLE_FILE);
         this.foreignKeyGenerator = new TorqueForeignKeyGenerator(descriptorRepository);
     }

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueRepositoryGeneratorTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueRepositoryGeneratorTest.java?rev=422236&r1=422235&r2=422236&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueRepositoryGeneratorTest.java
(original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueRepositoryGeneratorTest.java
Sat Jul 15 07:38:14 2006
@@ -25,7 +25,7 @@
 
     public void setUp() throws Exception {
         super.setUp();
-        RepositoryPersistor repositoryPersistor = ojb.getMetadataManager().getRepositoryPersistor();
+        RepositoryPersistor repositoryPersistor = ojb.getMetadataManager().createRepositoryPersistor();
         this.repository = repositoryPersistor.readDescriptorRepository(INPUT_FILE);
         this.torqueRepositoryGenerator = new TorqueRepositoryGenerator(INPUT_FILE, false);
     }

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueTableGeneratorTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueTableGeneratorTest.java?rev=422236&r1=422235&r2=422236&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueTableGeneratorTest.java
(original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueTableGeneratorTest.java
Sat Jul 15 07:38:14 2006
@@ -49,7 +49,7 @@
 
     public void setUp() throws Exception {
         super.setUp();
-        RepositoryPersistor repositoryPersistor = ojb.getMetadataManager().getRepositoryPersistor();
+        RepositoryPersistor repositoryPersistor = ojb.getMetadataManager().createRepositoryPersistor();
         this.repository = repositoryPersistor.readDescriptorRepository(EXAMPLE_FILE);
         this.torqueTableGenerator = new TorqueTableGenerator(this.repository, false);
     }

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueTablePreprocessorTest.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueTablePreprocessorTest.java?rev=422236&r1=422235&r2=422236&view=diff
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueTablePreprocessorTest.java
(original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/metadata/torque/TorqueTablePreprocessorTest.java
Sat Jul 15 07:38:14 2006
@@ -23,7 +23,7 @@
 
     public void setUp() throws Exception {
         super.setUp();
-        RepositoryPersistor repositoryPersistor = ojb.getMetadataManager().getRepositoryPersistor();
+        RepositoryPersistor repositoryPersistor = ojb.getMetadataManager().createRepositoryPersistor();
         DescriptorRepository descriptorRepository = repositoryPersistor.readDescriptorRepository(EXAMPLE_FILE);
         this.torqueTablePreprocessor = new TorqueTablePreprocessor(descriptorRepository);
     }



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