Author: arminw
Date: Fri Oct 13 10:08:35 2006
New Revision: 463738

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

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

Modified: 
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/TreeTest.java
URL: 
http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/TreeTest.java?view=diff&rev=463738&r1=463737&r2=463738
==============================================================================
--- 
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/TreeTest.java 
(original)
+++ 
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/TreeTest.java 
Fri Oct 13 10:08:35 2006
@@ -1,106 +1,63 @@
 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 org.apache.ojb.junit.PBTestCase;
+
 /**
  * Testing selfjoins and tree structures
  */
 public class TreeTest extends PBTestCase
 {
-       public static void main(String[] args)
-       {
-               String[] arr = {TreeTest.class.getName()};
-               junit.textui.TestRunner.main(arr);
-       }
-
-       public TreeTest(String name)
-
-       {
-               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
-       {
-               TreeGroup result = new TreeGroup();
-
-               FieldDescriptor idFld = 
broker.getClassDescriptor(Tree.class).getFieldDescriptorByName("id");
-               Integer idVal = (Integer) 
broker.serviceSequenceManager().getUniqueValue(idFld);
-
-        result.setId(idVal.intValue());
-               result.setData("" + result.getId());
-               result.setChilds(new Vector());
-               result.setMembers(new Vector());
-               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 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 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);
+    public static void main(String[] args)
+    {
+        String[] arr = {TreeTest.class.getName()};
+        junit.textui.TestRunner.main(arr);
+    }
 
-            root.setId(idVal.intValue());
-        }
-        catch (PersistenceBrokerException e)
+    public TreeTest(String name)
 
-            {
-        }
-        root.setData("a brand new root: " + root.getId());
+    {
+        super(name);
+    }
+
+    Tree createTreeNodeWithParent(Tree parent) throws Exception
+    {
+        Tree result = new Tree();
+        result.setData("tree node, parent_node is " + parent.getId());
+        result.setParentId(parent.getId());
+        result.setChilds(new Vector());
 
-        root.addChild(createTreeNodeWithParent(root));
-        root.addChild(createTreeNodeWithParent(root));
-        root.addChild(createTreeNodeWithParent(root));
-        root.addChild(createTreeNodeWithParent(root));
-        root.addChild(createTreeNodeWithParent(root));
+        return result;
+    }
+
+    Tree createTree(String data) throws Exception
+    {
+
+        Tree result = new Tree();
+        result.setData(data);
+        result.setChilds(new Vector());
+        return result;
+    }
+
+    public void testCreate() throws Exception
+    {
+        Tree root = new Tree();
+        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);
@@ -114,26 +71,30 @@
 
         Tree retrieved = (Tree) broker.getObjectByIdentity(oid);
 
-        //System.out.println("tree after reading from db:");
-        //System.out.println(retrieved);
+//        System.out.println("tree after reading from db:");
+//        System.out.println(retrieved);
 
         assertEquals(
             "tree should have same size after retrival",
             root.size(),
             retrieved.size());
-       }
+    }
+
+    TreeGroup createTreeGroup() throws Exception
+    {
+        TreeGroup result = new TreeGroup();
+        result.setData("group_node");
+        return result;
+    }
 
-       /**
-     *
-        */
-       public void testTreeGroup() throws Exception
-       {
+    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++)
@@ -152,17 +113,17 @@
             child.addChild(createTreeGroup());
         }
 
-        //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();
+//        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);
 
         Identity oid = broker.serviceIdentity().buildIdentity(root);
 
@@ -174,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);
@@ -183,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);
@@ -192,14 +153,14 @@
         //System.out.println(red_r);
         assertEquals(
             "tree should have same size after retrival",
-            red.size(),
+            1,
             red_r.size());
 
-       }
+    }
+
 
 
 
-    
     //*****************************************************************
     // inner classes - test objects
     //*****************************************************************
@@ -211,24 +172,18 @@
      * 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 Vector childs;
 
-        /**
-         * Tree constructor comment.
-         */
         public Tree()
         {
             super();
         }
 
-        /**
-         * Tree constructor comment.
-         */
         public Tree(int id, String data, int parentid)
         {
             this.id = id;
@@ -239,9 +194,7 @@
         public void addChild(Tree newChild)
         {
             if (childs == null) childs = new Vector();
-
             childs.add(newChild);
-
         }
 
         public Tree getChild(int index)
@@ -250,91 +203,46 @@
 
         }
 
-        /**
-         * Insert the method's description here.
-         * Creation date: (13.02.2001 18:33:02)
-         * @return java.util.Vector
-         */
         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 java.util.Vector
-         */
         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;
@@ -345,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()
         {
 
@@ -378,17 +281,11 @@
         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,62 +297,37 @@
         public void addChild(TreeGroup newChild)
         {
             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 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 java.util.Vector
-         */
         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;
@@ -464,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 java.util.Vector
-         */
         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 java.util.Vector
-         */
         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 java.util.Vector
-         */
         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;
@@ -559,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 Vector
-         */
+
         public Vector getChildren()
         {
             return children;
         }
 
-        /**
-         * Sets the children.
-         * @param children The children to set
-         */
         public void setChildren(Vector children)
         {
             this.children = children;
         }
 
-        /**
-         * Gets the groupMembers.
-         * @return Returns a Vector
-         */
         public Vector getGroupMembers()
         {
             return groupMembers;
         }
 
-        /**
-         * Sets the groupMembers.
-         * @param groupMembers The groupMembers to set
-         */
         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