Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 15518 invoked from network); 5 Jul 2004 14:46:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 5 Jul 2004 14:46:32 -0000 Received: (qmail 60488 invoked by uid 500); 5 Jul 2004 14:46:35 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 60419 invoked by uid 500); 5 Jul 2004 14:46:33 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 60388 invoked by uid 500); 5 Jul 2004 14:46:33 -0000 Received: (qmail 60377 invoked by uid 99); 5 Jul 2004 14:46:32 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Mon, 05 Jul 2004 07:46:32 -0700 Received: (qmail 15498 invoked by uid 1510); 5 Jul 2004 14:46:26 -0000 Date: 5 Jul 2004 14:46:26 -0000 Message-ID: <20040705144626.15497.qmail@minotaur.apache.org> From: arminw@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/test/org/apache/ojb repository_junit_reference.xml X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N arminw 2004/07/05 07:46:26 Modified: src/schema ojbtest-schema.xml src/test/org/apache/ojb repository_junit_reference.xml Added: src/test/org/apache/ojb/broker TreeExtentedTest.java Log: add new test case a tree test a using abstract base class for parent, child nodes and two real implementation classes Revision Changes Path 1.82 +17 -0 db-ojb/src/schema/ojbtest-schema.xml Index: ojbtest-schema.xml =================================================================== RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v retrieving revision 1.81 retrieving revision 1.82 diff -u -r1.81 -r1.82 --- ojbtest-schema.xml 3 Jul 2004 23:32:16 -0000 1.81 +++ ojbtest-schema.xml 5 Jul 2004 14:46:26 -0000 1.82 @@ -1205,6 +1205,23 @@ + + + + + + + + + + + +
+ + + + + 1.1 db-ojb/src/test/org/apache/ojb/broker/TreeExtentedTest.java Index: TreeExtentedTest.java =================================================================== package org.apache.ojb.broker; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.ojb.junit.PBTestCase; /** * Testing selfjoins and tree structures */ public class TreeExtentedTest extends PBTestCase { public static void main(String[] args) { String[] arr = {TreeExtentedTest.class.getName()}; junit.textui.TestRunner.main(arr); } public TreeExtentedTest(String name) { super(name); } public void testTree() { String postfix = "_" + System.currentTimeMillis(); NodeCategory cat = new NodeCategory(); cat.setName("Start" + postfix); NodeCategory mobile = new NodeCategory(); mobile.setName("mobile" + postfix); NodeCategory building = new NodeCategory(); building.setName("building" + postfix); NodeCategory car = new NodeCategory(); car.setName("car" + postfix); NodeCategory bicycle = new NodeCategory(); bicycle.setName("bicycle" + postfix); NodeProduct mercedes = new NodeProduct(); mercedes.setName("mercedes" + postfix); NodeProduct slc = new NodeProduct(); slc.setName("mercedes slc" + postfix); NodeCategory extras = new NodeCategory(); extras.setName("mercedes - extras" + postfix); NodeProduct sticker = new NodeProduct(); sticker.setName("mercedes - sticker" + postfix); cat.addChild(mobile); cat.addChild(building); mobile.addChild(bicycle); mobile.addChild(car); car.addChild(mercedes); mercedes.addChild(slc); mercedes.addChild(extras); mercedes.addChild(sticker); broker.beginTransaction(); broker.store(cat); broker.commitTransaction(); Identity oidCat = new Identity(cat, broker); Identity oidSticker = new Identity(sticker, broker); broker.clearCache(); Node newSticker = (Node) broker.getObjectByIdentity(oidSticker); Node newCat = (Node) broker.getObjectByIdentity(oidCat); Node newMercedes = newSticker.getParent(); assertEquals(3, newMercedes.getChilds().size()); assertEquals(2, newCat.getChilds().size()); assertEquals(8, newCat.size()); broker.beginTransaction(); broker.delete(newMercedes); broker.commitTransaction(); // current used cache needs sync with DB broker.clearCache(); newCat = (Node) broker.getObjectByIdentity(oidCat); assertEquals(4, newCat.size()); broker.beginTransaction(); broker.delete(newCat); broker.commitTransaction(); newCat = (Node) broker.getObjectByIdentity(oidCat); assertNull(newCat); } //***************************************************************** // inner classes - test objects //***************************************************************** public static class NodeCategory extends Node { } public static class NodeProduct extends Node { } /** * Node is recursive type: a Node element contains some data * and a Vector of child Node elements. * This sample demonstrates what is needed to map such a data * structure on a DB table * * @author Thomas Mahler */ public static abstract class Node implements Serializable { private Integer id; private String name; private List childs; private Node parent; private Integer childId; public Node() { } public Node(Integer id, String name, List childs, Node parent) { this.id = id; this.name = name; this.childs = childs; this.parent = parent; } 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 List getChilds() { return childs; } public void setChilds(List childs) { this.childs = childs; } public void addChild(Node newChild) { if (childs == null) childs = new ArrayList(); newChild.setParent(this); childs.add(newChild); } public Node getParent() { return parent; } public void setParent(Node parent) { this.parent = parent; } public Integer getChildId() { return childId; } public void setChildId(Integer childId) { this.childId = childId; } public int size() { return countChilds() - 1; } private int countChilds() { int result = 1; if(childs != null) { for (int i = 0; i < childs.size(); i++) { int c = ((Node) childs.get(i)).countChilds(); result += c; } } return result; } public String toString() { return new ToStringBuilder(this) .append("id", id) .append("name", name) .append("parent-name", parent != null ? parent.getName() : null) .append("childs-size", childs != null ? childs.size() : 0) .toString(); } } } 1.18 +116 -1 db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml Index: repository_junit_reference.xml =================================================================== RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit_reference.xml,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- repository_junit_reference.xml 23 Jun 2004 18:24:17 -0000 1.17 +++ repository_junit_reference.xml 5 Jul 2004 14:46:26 -0000 1.18 @@ -1619,4 +1619,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org