KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > tree > ServerTreeRendererTest


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.tree;
22
23 import java.util.*;
24 import junit.framework.*;
25 import org.apache.log4j.*;
26 import com.methodhead.persistable.*;
27 import com.methodhead.test.*;
28
29 public class ServerTreeRendererTest extends DbTestCase {
30
31   FoldingTreeNode node0_ = null;
32   FoldingTreeNode node1_ = null;
33   FoldingTreeNode node11_ = null;
34   FoldingTreeNode node2_ = null;
35   FoldingTreeNode node21_ = null;
36
37   public ServerTreeRendererTest( String JavaDoc name ) {
38     super( name );
39   }
40
41   protected void setUp() {
42     //setLogLevel( Level.DEBUG );
43
try {
44       node0_ = new FoldingTreeNode();
45       node0_.setLabel( "node0" );
46       node1_ = new FoldingTreeNode();
47       node1_.setLabel( "node1" );
48       node11_ = new FoldingTreeNode();
49       node11_.setLabel( "node11" );
50       node2_ = new FoldingTreeNode();
51       node2_.setLabel( "node2" );
52       node21_ = new FoldingTreeNode();
53       node21_.setLabel( "node21" );
54
55       //
56
// - node0
57
// + node1
58
// (node11)
59
// - node2
60
// node21
61
//
62
node1_.add( node11_ );
63       node2_.add( node21_ );
64       node0_.add( node1_ );
65       node0_.add( node2_ );
66
67       node0_.setOpened( true );
68       node2_.setOpened( true );
69     }
70     catch ( Exception JavaDoc e ) {
71       fail( e.getMessage() );
72     }
73   }
74
75   protected void tearDown() {
76   }
77
78   public void testGetRows() {
79     try {
80       ServerTreeRenderer renderer = new ServerTreeRenderer();
81       List nodes = new ArrayList();
82       FoldingTreeNode node = null;
83       renderer.getVisibleNodes( nodes, node0_ );
84
85       assertEquals( 4, nodes.size() );
86
87       node = ( FoldingTreeNode )nodes.get( 0 );
88
89       assertEquals( node0_, node );
90
91       node = ( FoldingTreeNode )nodes.get( 1 );
92
93       assertEquals( node1_, node );
94
95       node = ( FoldingTreeNode )nodes.get( 2 );
96
97       assertEquals( node2_, node );
98
99       node = ( FoldingTreeNode )nodes.get( 3 );
100
101       assertEquals( node21_, node );
102     }
103     catch ( Exception JavaDoc e ) {
104       e.printStackTrace();
105       fail();
106     }
107   }
108
109   public void testGetMaxLevel() {
110     try {
111       ServerTreeRenderer renderer = new ServerTreeRenderer();
112       List nodes = new ArrayList();
113       renderer.getVisibleNodes( nodes, node0_ );
114
115       assertEquals( 2, renderer.getMaxLevel( nodes ) );
116
117       nodes.clear();
118       node0_.setOpened( false );
119       renderer.getVisibleNodes( nodes, node0_ );
120
121       assertEquals( 0, renderer.getMaxLevel( nodes ) );
122     }
123     catch ( Exception JavaDoc e ) {
124       e.printStackTrace();
125       fail();
126     }
127   }
128
129   public void testRenderHeaderFooter() {
130     try {
131       StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
132       ServerTreeRenderer renderer = new ServerTreeRenderer();
133       renderer.renderHeader( buf );
134
135       assertEquals( "<table>\n", buf.toString() );
136
137       renderer.renderFooter( buf );
138
139       assertEquals( "<table>\n</table>\n", buf.toString() );
140     }
141     catch ( Exception JavaDoc e ) {
142       e.printStackTrace();
143       fail();
144     }
145   }
146 }
147
Popular Tags