Author: arminw
Date: Fri Oct 13 10:08:53 2006
New Revision: 463739

URL: http://svn.apache.org/viewvc?view=rev&rev=463739
Log:
cleanup, improve

Modified:
    db/ojb/trunk/src/test/org/apache/ojb/broker/TreeTest.java

Modified: db/ojb/trunk/src/test/org/apache/ojb/broker/TreeTest.java
URL: 
http://svn.apache.org/viewvc/db/ojb/trunk/src/test/org/apache/ojb/broker/TreeTest.java?view=diff&rev=463739&r1=463738&r2=463739
==============================================================================
--- db/ojb/trunk/src/test/org/apache/ojb/broker/TreeTest.java (original)
+++ db/ojb/trunk/src/test/org/apache/ojb/broker/TreeTest.java Fri Oct 13 
10:08:53 2006
@@ -1,10 +1,9 @@
 package org.apache.ojb.broker;
 
-import org.apache.ojb.broker.metadata.FieldDescriptor;
-import org.apache.ojb.junit.PBTestCase;
+import java.io.Serializable;
+import java.util.Vector;
 
-import java.util.List;
-import java.util.ArrayList;
+import org.apache.ojb.junit.PBTestCase;
 
 /**
  * Testing selfjoins and tree structures
@@ -23,85 +22,42 @@
                super(name);
        }
 
-       /**
-        * Insert the method's description here.
-        * Creation date: (13.02.2001 18:50:29)
-        * @return TestThreadsNLocks.org.apache.ojb.broker.Tree
-        */
-       public TreeGroup createTreeGroup() throws Exception
+    Tree createTreeNodeWithParent(Tree parent) throws Exception
        {
-               TreeGroup result = new TreeGroup();
-
-               FieldDescriptor idFld = 
broker.getClassDescriptor(Tree.class).getFieldDescriptorByName("id");
-               Integer idVal = (Integer) 
broker.serviceSequenceManager().getUniqueValue(idFld);
+        Tree result = new Tree();
+        result.setData("tree node, parent_node is " + parent.getId());
+        result.setParentId(parent.getId());
+        result.setChilds(new Vector());
 
-        result.setId(idVal.intValue());
-               result.setData("" + result.getId());
-               result.setChilds(new ArrayList());
-               result.setMembers(new ArrayList());
                return result;
        }
 
-       /**
-        * Insert the method's description here.
-        * Creation date: (13.02.2001 18:50:29)
-        * @return TestThreadsNLocks.org.apache.ojb.broker.Tree
-        * @param parent TestThreadsNLocks.org.apache.ojb.broker.Tree
-        */
-       public Tree createTreeNodeWithParent(Tree parent) throws Exception
+    Tree createTree(String data) throws Exception
        {
 
                Tree result = new Tree();
-               try
-               {
-                       FieldDescriptor idFld = 
broker.getClassDescriptor(Tree.class).getFieldDescriptorByName("id");
-                       Integer idVal = (Integer) 
broker.serviceSequenceManager().getUniqueValue(idFld);
-
-                       result.setId(idVal.intValue());
-               }
-               catch (PersistenceBrokerException e)
-
-                       {
-               }
-               result.setData(parent.getId() + "-" + result.getId());
-               result.setParentId(parent.getId());
-               result.setChilds(new ArrayList());
-
+        result.setData(data);
+        result.setChilds(new Vector());
                return result;
        }
 
-       /**
-        */
        public void testCreate() throws Exception
        {
         Tree root = new Tree();
-        try
-        {
-            FieldDescriptor idFld = 
broker.getClassDescriptor(Tree.class).getFieldDescriptorByName("id");
-            Integer idVal = (Integer) 
broker.serviceSequenceManager().getUniqueValue(idFld);
-
-            root.setId(idVal.intValue());
-        }
-        catch (PersistenceBrokerException e)
-
-            {
-        }
-        root.setData("a brand new root: " + root.getId());
-
-        root.addChild(createTreeNodeWithParent(root));
-        root.addChild(createTreeNodeWithParent(root));
-        root.addChild(createTreeNodeWithParent(root));
-        root.addChild(createTreeNodeWithParent(root));
-        root.addChild(createTreeNodeWithParent(root));
+        root.setData("a brand new root");
+        root.addChild(createTree("child of root - L1"));
+        root.addChild(createTree("child of root - L1"));
+        root.addChild(createTree("child of root - L1"));
+        root.addChild(createTree("child of root - L1"));
+        root.addChild(createTree("child of root - L1"));
 
         Tree child = root.getChild(0);
-        child.addChild(createTreeNodeWithParent(child));
-        child.addChild(createTreeNodeWithParent(child));
-        child.addChild(createTreeNodeWithParent(child));
+        child.addChild(createTree("child of child - L2"));
+        child.addChild(createTree("child of child - L2"));
+        child.addChild(createTree("child of child - L2"));
 
         child = child.getChild(1);
-        child.addChild(createTreeNodeWithParent(child));
-        child.addChild(createTreeNodeWithParent(child));
+        child.addChild(createTree("child of child of child - L3"));
 
         //System.out.println("original tree:");
         //System.out.println(root);
@@ -124,17 +80,21 @@
             retrieved.size());
        }
 
-       /**
-     *
-        */
+    TreeGroup createTreeGroup() throws Exception
+    {
+        TreeGroup result = new TreeGroup();
+        result.setData("group_node");
+        return result;
+    }
+
        public void testTreeGroup() throws Exception
        {
         TreeGroup root = createTreeGroup();
-        root.setData("The Tree Group root: " + root.getId());
+        root.setData("The Tree Group root node");
         TreeGroup green = createTreeGroup();
-        green.setData("the GREEN group " + green.getId());
+        green.setData("the GREEN group");
         TreeGroup red = createTreeGroup();
-        red.setData("the RED group " + red.getId());
+        red.setData("the RED group");
 
         TreeGroup child;
         for (int i = 0; i < 3; i++)
@@ -153,17 +113,17 @@
             child.addChild(createTreeGroup());
         }
 
+        broker.beginTransaction();
+        broker.store(root);
+        broker.store(green);
+        broker.store(red);
+        broker.commitTransaction();
         //System.out.println("original TreeGroup:");
         //System.out.println(root);
         //System.out.println("GREEN TreeGroup:");
         //System.out.println(green);
         //System.out.println("RED TreeGroup:");
         //System.out.println(red);
-        broker.beginTransaction();
-        broker.store(root);
-        broker.store(green);
-        broker.store(red);
-        broker.commitTransaction();
 
         Identity oid = broker.serviceIdentity().buildIdentity(root);
 
@@ -175,7 +135,7 @@
         assertNotNull(root_r);
         assertEquals(
             "tree should have same size after retrival",
-            root.size(),
+            13,
             root_r.size());
 
         oid = broker.serviceIdentity().buildIdentity(green);
@@ -184,7 +144,7 @@
         //System.out.println(green_r);
         assertEquals(
             "tree should have same size after retrival",
-            green.size(),
+            1,
             green_r.size());
 
         oid = broker.serviceIdentity().buildIdentity(red);
@@ -193,7 +153,7 @@
         //System.out.println(red_r);
         assertEquals(
             "tree should have same size after retrival",
-            red.size(),
+            1,
             red_r.size());
 
        }
@@ -207,29 +167,23 @@
 
     /**
      * Tree is  recursive type: a Tree element contains some data
-     * and a List of child Tree elements.
+     * and a Vector of child Tree elements.
      * This sample demonstrates what is needed to map such a data
      * structure on a DB table
      * @author Thomas Mahler
      */
-    public static class Tree implements java.io.Serializable
+    public static class Tree implements Serializable
     {
         private int id;
         private String data;
         private int parentId;
-        private List childs;
+        private Vector childs;
 
-        /**
-         * Tree constructor comment.
-         */
         public Tree()
         {
             super();
         }
 
-        /**
-         * Tree constructor comment.
-         */
         public Tree(int id, String data, int parentid)
         {
             this.id = id;
@@ -239,10 +193,8 @@
 
         public void addChild(Tree newChild)
         {
-            if (childs == null) childs = new ArrayList();
-
+            if (childs == null) childs = new Vector();
             childs.add(newChild);
-
         }
 
         public Tree getChild(int index)
@@ -251,91 +203,46 @@
 
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return List
-         */
-        public List getChilds()
+        public Vector getChilds()
         {
             return childs;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return java.lang.String
-         */
-        public java.lang.String getData()
+        public String getData()
         {
             return data;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return int
-         */
         public int getId()
         {
             return id;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return int
-         */
         public int getParentId()
         {
             return parentId;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @param newChilds List
-         */
-        public void setChilds(List newChilds)
+        public void setChilds(Vector newChilds)
         {
             childs = newChilds;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @param newData java.lang.String
-         */
-        public void setData(java.lang.String newData)
+        public void setData(String newData)
         {
             data = newData;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @param newId int
-         */
         public void setId(int newId)
         {
             id = newId;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @param newParentId int
-         */
         public void setParentId(int newParentId)
         {
             parentId = newParentId;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (14.02.2001 19:51:23)
-         * @return int
-         */
         public int size()
         {
             int result = 1;
@@ -346,11 +253,6 @@
             return result;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:41)
-         * @return java.lang.String
-         */
         public String toString()
         {
 
@@ -360,7 +262,7 @@
 
     /**
      * Tree is  recursive type: a Tree element contains some data
-     * and a List of child Tree elements.
+     * and a Vector of child Tree elements.
      * This sample demonstrates what is needed to map such a data
      * structure on a DB table
      * @author Thomas Mahler
@@ -371,25 +273,19 @@
         private String data;
 
         private int parentId;
-        private List children;
+        private Vector children;
         private TreeGroup myParent;
 
         private int groupId;
-        private List groupMembers;
+        private Vector groupMembers;
         private TreeGroup myGroup;
 
 
-        /**
-         * Tree constructor comment.
-         */
         public TreeGroup()
         {
             super();
         }
 
-        /**
-         * Tree constructor comment.
-         */
         public TreeGroup(int id, String data, int parentid, int groupid)
         {
             this.id = id;
@@ -400,63 +296,38 @@
 
         public void addChild(TreeGroup newChild)
         {
-            if (children == null) children = new ArrayList();
-
+            if (children == null) children = new Vector();
             children.add(newChild);
-            newChild.setParentId(this.getId());
-
+            newChild.setMyParent(this);
         }
 
         public void addMember(TreeGroup newMember)
         {
-            if (groupMembers == null) groupMembers = new ArrayList();
-
+            if (groupMembers == null) groupMembers = new Vector();
             groupMembers.add(newMember);
-            newMember.setGroupId(this.getId());
-
+            newMember.setMyGroup(this);
         }
 
         public TreeGroup getChild(int index)
         {
             return (TreeGroup) children.get(index);
-
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return List
-         */
-        public List getChilds()
+        public Vector getChilds()
         {
             return children;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return java.lang.String
-         */
         public String getData()
         {
             return data;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return int
-         */
         public int getGroupId()
         {
             return groupId;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return int
-         */
         public int getId()
         {
             return id;
@@ -465,90 +336,48 @@
         public TreeGroup getMember(int index)
         {
             return (TreeGroup) groupMembers.get(index);
-
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return List
-         */
-        public List getMembers()
+        public Vector getMembers()
         {
             return groupMembers;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return int
-         */
         public int getParentId()
         {
             return parentId;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @param newChilds List
-         */
-        public void setChilds(List newChilds)
+        public void setChilds(Vector newChilds)
         {
             children = newChilds;
         }
 
-        /**
-         * Sets the data.
-         * @param data The data to set
-         */
         public void setData(String data)
         {
             this.data = data;
         }
 
-        /**
-         * Sets the groupId.
-         * @param groupId The groupId to set
-         */
         public void setGroupId(int groupId)
         {
             this.groupId = groupId;
         }
 
-        /**
-         * Sets the id.
-         * @param id The id to set
-         */
         public void setId(int id)
         {
             this.id = id;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @param newMembers List
-         */
-        public void setMembers(List newMembers)
+        public void setMembers(Vector newMembers)
         {
             groupMembers = newMembers;
         }
 
-        /**
-         * Sets the parentId.
-         * @param parentId The parentId to set
-         */
         public void setParentId(int parentId)
         {
             this.parentId = parentId;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (14.02.2001 19:51:23)
-         * @return int
-         */
         public int size()
         {
             int result = 1;
@@ -560,90 +389,52 @@
             return result;
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:41)
-         * @return java.lang.String
-         */
         public String toString()
         {
             return data
                     + ((children == null || (children.size() == 0)) ? "" : " 
children: " + children.toString())
                     + ((groupMembers == null || (groupMembers.size() == 0)) ? 
"" : " members: " + groupMembers.toString());
         }
-        /**
-         * Gets the children.
-         * @return Returns a List
-         */
-        public List getChildren()
+
+        public Vector getChildren()
         {
             return children;
         }
 
-        /**
-         * Sets the children.
-         * @param children The children to set
-         */
-        public void setChildren(List children)
+        public void setChildren(Vector children)
         {
             this.children = children;
         }
 
-        /**
-         * Gets the groupMembers.
-         * @return Returns a List
-         */
-        public List getGroupMembers()
+        public Vector getGroupMembers()
         {
             return groupMembers;
         }
 
-        /**
-         * Sets the groupMembers.
-         * @param groupMembers The groupMembers to set
-         */
-        public void setGroupMembers(List groupMembers)
+        public void setGroupMembers(Vector groupMembers)
         {
             this.groupMembers = groupMembers;
         }
 
-        /**
-         * Gets the myGroup.
-         * @return Returns a TreeGroup
-         */
         public TreeGroup getMyGroup()
         {
             return myGroup;
         }
 
-        /**
-         * Sets the myGroup.
-         * @param myGroup The myGroup to set
-         */
         public void setMyGroup(TreeGroup myGroup)
         {
             this.myGroup = myGroup;
         }
 
-        /**
-         * Gets the myParent.
-         * @return Returns a TreeGroup
-         */
         public TreeGroup getMyParent()
         {
             return myParent;
         }
 
-        /**
-         * Sets the myParent.
-         * @param myParent The myParent to set
-         */
         public void setMyParent(TreeGroup myParent)
         {
             this.myParent = myParent;
         }
 
     }
-
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to