db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r414922 - in /db/ojb/branches/OJB_1_0_RELEASE/src: schema/ojbtest-schema.xml test/org/apache/ojb/broker/AllTests.java test/org/apache/ojb/broker/JdbcJavaObjectTest.java test/org/apache/ojb/repository_junit.xml
Date Fri, 16 Jun 2006 21:29:25 GMT
Author: arminw
Date: Fri Jun 16 14:29:24 2006
New Revision: 414922

URL: http://svn.apache.org/viewvc?rev=414922&view=rev
Log:
add test to check handling of jdbc type JAVA_OBJECT

Added:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/JdbcJavaObjectTest.java
Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml?rev=414922&r1=414921&r2=414922&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/schema/ojbtest-schema.xml Fri Jun 16 14:29:24 2006
@@ -1814,4 +1814,11 @@
   <table name="Ownable2">
     <column name="id" required="true" primaryKey="true" type="INTEGER"/>
   </table>
+
+    <table name="CONTAINER_TBL">
+        <column name="ID_" required="true" primaryKey="true" type="INTEGER"/>
+        <column name="NAME" type="VARCHAR" size="150"/>
+        <column name="TARGET" type="JAVA_OBJECT"/>
+        <column name="EDITOR" type="JAVA_OBJECT"/>
+  </table>
 </database>

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java?rev=414922&r1=414921&r2=414922&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java Fri Jun 16
14:29:24 2006
@@ -125,6 +125,7 @@
         suite.addTestSuite(NoPkReferenceTest.class);
         suite.addTestSuite(UnwrapHelperTest.class);
         suite.addTestSuite(LOBTest.class);
+        suite.addTestSuite(JdbcJavaObjectTest.class);
 
         // BRJ: ensure shutdown of hsqldb
         suite.addTestSuite(HsqldbShutdown.class);

Added: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/JdbcJavaObjectTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/JdbcJavaObjectTest.java?rev=414922&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/JdbcJavaObjectTest.java
(added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/JdbcJavaObjectTest.java
Fri Jun 16 14:29:24 2006
@@ -0,0 +1,227 @@
+package org.apache.ojb.broker;
+
+/* Copyright 2002-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.lang.Object;
+import java.io.Serializable;
+
+import org.apache.ojb.junit.PBTestCase;
+import org.apache.ojb.broker.query.QueryFactory;
+import org.apache.ojb.broker.query.Query;
+import org.apache.ojb.broker.query.Criteria;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.EqualsBuilder;
+
+/**
+ * This class
+ *
+ * @version $Id: $
+ */
+public class JdbcJavaObjectTest extends PBTestCase
+{
+    public static void main(String[] args)
+    {
+        String[] arr = {JdbcJavaObjectTest.class.getName()};
+        junit.textui.TestRunner.main(arr);
+    }
+
+    public void testInsert()
+    {
+        Container c = new Container("testInsert", new Editor(2, "object_test"), new Editor(3,
"editor_test"));
+        doInsert(c);
+    }
+
+    public void testDelete()
+    {
+        Container c = new Container("testDelete", new Editor(2, "object_test"), new Editor(3,
"editor_test"));
+        doInsert(c);
+        doDelete(c);
+    }
+
+    public void testRead()
+    {
+        Container c = new Container("testRead", new Editor(2, "object_test"), new Editor(3,
"editor_test"));
+        doInsert(c);
+
+        Identity oid = broker.serviceIdentity().buildIdentity(c);
+        Container read = (Container) broker.getObjectByIdentity(oid);
+        assertEquals(c, read);
+
+        broker.clearCache();
+        read = (Container) broker.getObjectByIdentity(oid);
+        assertEquals(c, read);
+
+        doDelete(c);
+    }
+
+    public void testQuery()
+    {
+        Container c = new Container("testQuery", new Editor(2, "object_test"), new Editor(3,
"editor_test"));
+        doInsert(c);
+
+        Criteria crit = new Criteria().addEqualTo("id", c.getId());
+        Query q = QueryFactory.newQuery(Container.class, crit);
+        Container read = (Container) broker.getObjectByQuery(q);
+        assertEquals(c, read);
+
+        broker.clearCache();
+        read = (Container) broker.getObjectByQuery(q);
+        assertEquals(c, read);
+
+        doDelete(c);
+    }
+
+    public void testUpdate()
+    {
+        Container c = new Container("testUpdate", new Editor(2, "object_test"), new Editor(3,
"editor_test"));
+        doInsert(c);
+
+        broker.beginTransaction();
+        c.setName(getName() + "_update_1");
+        c.getEditor().str = c.getEditor().str + "_update_1";
+        ((Editor) c.getTarget()).str = ((Editor) c.getTarget()).str + "_update_1";
+        broker.store(c);
+        broker.commitTransaction();
+
+        Identity oid = broker.serviceIdentity().buildIdentity(c);
+        Container read = (Container) broker.getObjectByIdentity(oid);
+        assertEquals(c, read);
+
+        broker.clearCache();
+        read = (Container) broker.getObjectByIdentity(oid);
+        assertEquals(c, read);
+
+        broker.clearCache();
+        broker.beginTransaction();
+        c = read;
+        c.setName(getName() + "_update_2");
+        c.getEditor().str = c.getEditor().str + "_update_2";
+        ((Editor) c.getTarget()).str = ((Editor) c.getTarget()).str + "_update_2";
+        broker.store(c);
+        broker.commitTransaction();
+
+        broker.clearCache();
+        read = (Container) broker.getObjectByIdentity(oid);
+        assertEquals(c, read);
+
+        doDelete(c);
+    }
+
+    void doInsert(Container c)
+    {
+        broker.beginTransaction();
+        broker.store(c);
+        broker.commitTransaction();
+    }
+
+    void doDelete(Container c)
+    {
+        broker.beginTransaction();
+        broker.delete(c);
+        broker.commitTransaction();
+    }
+
+    public static class Container implements Serializable
+    {
+        private Integer id;
+        private String name;
+        private Object target;
+        private Editor editor;
+
+        public Container()
+        {
+        }
+
+        public Container(String name, Object target, Editor editor)
+        {
+            this.name = name;
+            this.target = target;
+            this.editor = editor;
+        }
+
+        public Integer getId()
+        {
+            return id;
+        }
+
+        public void setId(Integer id)
+        {
+            this.id = id;
+        }
+
+        public String getName()
+        {
+            return name;
+        }
+
+        public void setName(String name)
+        {
+            this.name = name;
+        }
+
+        public Object getTarget()
+        {
+            return target;
+        }
+
+        public void setTarget(Object target)
+        {
+            this.target = target;
+        }
+
+        public Editor getEditor()
+        {
+            return editor;
+        }
+
+        public void setEditor(Editor editor)
+        {
+            this.editor = editor;
+        }
+
+        public boolean equals(Object obj)
+        {
+            return EqualsBuilder.reflectionEquals(this, obj);
+        }
+
+        public String toString()
+        {
+            return ToStringBuilder.reflectionToString(this);
+        }
+    }
+
+    public static class Editor implements Serializable
+    {
+        String str;
+        int aInt;
+
+        public Editor(int aInt, String str)
+        {
+            this.aInt = aInt;
+            this.str = str;
+        }
+
+        public boolean equals(Object obj)
+        {
+            return EqualsBuilder.reflectionEquals(this, obj);
+        }
+
+        public String toString()
+        {
+            return ToStringBuilder.reflectionToString(this);
+        }
+    }
+}

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml?rev=414922&r1=414921&r2=414922&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml Fri Jun 16
14:29:24 2006
@@ -3229,4 +3229,36 @@
        >
        </field-descriptor>
     </class-descriptor>
+
+
+    <class-descriptor
+        class="org.apache.ojb.broker.JdbcJavaObjectTest$Container"
+        table="CONTAINER_TBL"
+    >
+        <field-descriptor
+             name="id"
+             column="ID_"
+             jdbc-type="INTEGER"
+             primarykey="true"
+             autoincrement="true"
+        />
+
+        <field-descriptor
+             name="name"
+             column="NAME"
+             jdbc-type="VARCHAR"
+        />
+
+        <field-descriptor
+             name="target"
+             column="TARGET"
+             jdbc-type="JAVA_OBJECT"
+        />
+
+        <field-descriptor
+             name="editor"
+             column="EDITOR"
+             jdbc-type="JAVA_OBJECT"
+        />
+    </class-descriptor>
 <!-- Mapping of classes used in junit tests and tutorials ends here -->



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