001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.shim;
022:
023: import java.util.*;
024: import java.sql.*;
025: import junit.framework.*;
026: import org.apache.log4j.*;
027: import com.methodhead.persistable.*;
028: import com.methodhead.test.*;
029: import com.methodhead.tree.*;
030:
031: public class SiteMapTreeTest extends DbTestCase {
032:
033: public SiteMapTreeTest(String name) {
034: super (name);
035: }
036:
037: private FoldingTreeNode node1_ = null;
038: private FoldingTreeNode node2_ = null;
039: private FoldingTreeNode node3_ = null;
040: private FoldingTreeNode node4_ = null;
041: private FoldingTreeNode node5_ = null;
042:
043: private Link link1_ = null;
044: private Link link2_ = null;
045: private Link link3_ = null;
046: private Link link4_ = null;
047: private Link link5_ = null;
048:
049: private SiteMap siteMap1_ = null;
050:
051: private void createData() {
052: // Node1
053: // Node2
054: // Node3
055: // Node4
056: // Node5
057: node1_ = new FoldingTreeNode();
058: node1_.setUserObject(new Integer(1));
059: node2_ = new FoldingTreeNode();
060: node2_.setUserObject(new Integer(2));
061: node3_ = new FoldingTreeNode();
062: node3_.setUserObject(new Integer(3));
063: node4_ = new FoldingTreeNode();
064: node4_.setUserObject(new Integer(4));
065: node5_ = new FoldingTreeNode();
066: node5_.setUserObject(new Integer(5));
067:
068: node1_.add(node2_);
069: node2_.add(node3_);
070: node1_.add(node4_);
071: node1_.add(node5_);
072:
073: link1_ = new Link();
074: link1_.setPageId(1);
075: link1_.setTitle("Page1");
076: link2_ = new Link();
077: link2_.setPageId(2);
078: link2_.setTitle("Page2");
079: link3_ = new Link();
080: link3_.setPageId(3);
081: link3_.setTitle("Page3");
082: link4_ = new Link();
083: link4_.setPageId(4);
084: link4_.setTitle("Page4");
085: link5_ = new Link();
086: link5_.setPageId(5);
087: link5_.setTitle("Page5");
088:
089: link1_.add(link2_);
090: link2_.add(link3_);
091: link1_.add(link4_);
092: link1_.add(link5_);
093:
094: siteMap1_ = new SiteMap();
095: siteMap1_.setRoot(link1_);
096: }
097:
098: protected void setUp() {
099: //setLogLevel( Level.DEBUG );
100: try {
101: } catch (Exception e) {
102: fail(e.getMessage());
103: }
104: }
105:
106: protected void tearDown() {
107: }
108:
109: public void testBuild() {
110: try {
111: FoldingTreeNode node = null;
112: FoldingTreeNode subnode = null;
113: FoldingTreeNode subsubnode = null;
114: SiteMapTree tree = null;
115:
116: createData();
117: tree = new SiteMapTree();
118: tree.build(siteMap1_);
119: node = (FoldingTreeNode) tree.getRoot();
120:
121: assertNotNull(node);
122: assertEquals(new Integer(1), node.getUserObject());
123: assertEquals("Page1", node.getLabel());
124: assertEquals("editPage.do?id=1", node.getUrl());
125: assertEquals("PAGE", node.getIconHint());
126: assertEquals(3, node.getChildCount());
127:
128: subnode = (FoldingTreeNode) node.getChildAt(0);
129: assertEquals(new Integer(2), subnode.getUserObject());
130: assertEquals("Page2", subnode.getLabel());
131: assertEquals("editPage.do?id=2", subnode.getUrl());
132: assertEquals("PAGE", subnode.getIconHint());
133: assertEquals(1, subnode.getChildCount());
134:
135: subsubnode = (FoldingTreeNode) subnode.getChildAt(0);
136: assertEquals(new Integer(3), subsubnode.getUserObject());
137: assertEquals("Page3", subsubnode.getLabel());
138: assertEquals("editPage.do?id=3", subsubnode.getUrl());
139: assertEquals("PAGE", subsubnode.getIconHint());
140: assertEquals(0, subsubnode.getChildCount());
141:
142: subnode = (FoldingTreeNode) node.getChildAt(1);
143: assertEquals(new Integer(4), subnode.getUserObject());
144: assertEquals("Page4", subnode.getLabel());
145: assertEquals("editPage.do?id=4", subnode.getUrl());
146: assertEquals("PAGE", subnode.getIconHint());
147: assertEquals(0, subnode.getChildCount());
148:
149: subnode = (FoldingTreeNode) node.getChildAt(2);
150: assertEquals(new Integer(5), subnode.getUserObject());
151: assertEquals("Page5", subnode.getLabel());
152: assertEquals("editPage.do?id=5", subnode.getUrl());
153: assertEquals("PAGE", subnode.getIconHint());
154: assertEquals(0, subnode.getChildCount());
155: } catch (Exception e) {
156: e.printStackTrace();
157: fail();
158: }
159: }
160:
161: public void testFind() {
162: try {
163: FoldingTreeNode node = null;
164: SiteMapTree tree = null;
165:
166: createData();
167: tree = new SiteMapTree();
168: tree.setRoot(node1_);
169:
170: assertNull(tree.find(666));
171:
172: node = tree.find(3);
173: assertNotNull(node);
174: assertEquals(node, node3_);
175:
176: node = tree.find(5);
177: assertNotNull(node);
178: assertEquals(node, node5_);
179: } catch (Exception e) {
180: e.printStackTrace();
181: fail();
182: }
183: }
184: }
|