1 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 name ) { 38 super( name ); 39 } 40 41 protected void setUp() { 42 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 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 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 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 e ) { 124 e.printStackTrace(); 125 fail(); 126 } 127 } 128 129 public void testRenderHeaderFooter() { 130 try { 131 StringBuffer buf = new StringBuffer (); 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 e ) { 142 e.printStackTrace(); 143 fail(); 144 } 145 } 146 } 147 | Popular Tags |