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.tree;
022:
023: import java.util.*;
024: import junit.framework.*;
025: import org.apache.log4j.*;
026: import com.methodhead.persistable.*;
027: import com.methodhead.test.*;
028:
029: public class ServerTreeRendererTest extends DbTestCase {
030:
031: FoldingTreeNode node0_ = null;
032: FoldingTreeNode node1_ = null;
033: FoldingTreeNode node11_ = null;
034: FoldingTreeNode node2_ = null;
035: FoldingTreeNode node21_ = null;
036:
037: public ServerTreeRendererTest(String name) {
038: super (name);
039: }
040:
041: protected void setUp() {
042: //setLogLevel( Level.DEBUG );
043: try {
044: node0_ = new FoldingTreeNode();
045: node0_.setLabel("node0");
046: node1_ = new FoldingTreeNode();
047: node1_.setLabel("node1");
048: node11_ = new FoldingTreeNode();
049: node11_.setLabel("node11");
050: node2_ = new FoldingTreeNode();
051: node2_.setLabel("node2");
052: node21_ = new FoldingTreeNode();
053: node21_.setLabel("node21");
054:
055: //
056: // - node0
057: // + node1
058: // (node11)
059: // - node2
060: // node21
061: //
062: node1_.add(node11_);
063: node2_.add(node21_);
064: node0_.add(node1_);
065: node0_.add(node2_);
066:
067: node0_.setOpened(true);
068: node2_.setOpened(true);
069: } catch (Exception e) {
070: fail(e.getMessage());
071: }
072: }
073:
074: protected void tearDown() {
075: }
076:
077: public void testGetRows() {
078: try {
079: ServerTreeRenderer renderer = new ServerTreeRenderer();
080: List nodes = new ArrayList();
081: FoldingTreeNode node = null;
082: renderer.getVisibleNodes(nodes, node0_);
083:
084: assertEquals(4, nodes.size());
085:
086: node = (FoldingTreeNode) nodes.get(0);
087:
088: assertEquals(node0_, node);
089:
090: node = (FoldingTreeNode) nodes.get(1);
091:
092: assertEquals(node1_, node);
093:
094: node = (FoldingTreeNode) nodes.get(2);
095:
096: assertEquals(node2_, node);
097:
098: node = (FoldingTreeNode) nodes.get(3);
099:
100: assertEquals(node21_, node);
101: } catch (Exception e) {
102: e.printStackTrace();
103: fail();
104: }
105: }
106:
107: public void testGetMaxLevel() {
108: try {
109: ServerTreeRenderer renderer = new ServerTreeRenderer();
110: List nodes = new ArrayList();
111: renderer.getVisibleNodes(nodes, node0_);
112:
113: assertEquals(2, renderer.getMaxLevel(nodes));
114:
115: nodes.clear();
116: node0_.setOpened(false);
117: renderer.getVisibleNodes(nodes, node0_);
118:
119: assertEquals(0, renderer.getMaxLevel(nodes));
120: } catch (Exception e) {
121: e.printStackTrace();
122: fail();
123: }
124: }
125:
126: public void testRenderHeaderFooter() {
127: try {
128: StringBuffer buf = new StringBuffer();
129: ServerTreeRenderer renderer = new ServerTreeRenderer();
130: renderer.renderHeader(buf);
131:
132: assertEquals("<table>\n", buf.toString());
133:
134: renderer.renderFooter(buf);
135:
136: assertEquals("<table>\n</table>\n", buf.toString());
137: } catch (Exception e) {
138: e.printStackTrace();
139: fail();
140: }
141: }
142: }
|