Source Code Cross Referenced for JTree_DynamicUtilTreeNodeTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Anton Avtamonov
019:         * @version $Revision$
020:         */package javax.swing;
021:
022:        import java.io.Serializable;
023:        import java.util.Enumeration;
024:        import java.util.Hashtable;
025:        import java.util.Vector;
026:        import javax.swing.JTree.DynamicUtilTreeNode;
027:        import javax.swing.tree.DefaultMutableTreeNode;
028:
029:        public class JTree_DynamicUtilTreeNodeTest extends BasicSwingTestCase {
030:            private JTree.DynamicUtilTreeNode node;
031:
032:            public JTree_DynamicUtilTreeNodeTest(final String name) {
033:                super (name);
034:            }
035:
036:            @Override
037:            protected void setUp() throws Exception {
038:                node = new DynamicUtilTreeNode("value", null);
039:            }
040:
041:            @Override
042:            protected void tearDown() throws Exception {
043:                node = null;
044:            }
045:
046:            public void testDynamicUtilTreeNode() throws Exception {
047:                assertNull(node.childValue);
048:                assertFalse(node.hasChildren);
049:                assertTrue(node.loadedChildren);
050:                assertEquals("value", node.getUserObject());
051:                assertFalse(node.getAllowsChildren());
052:                assertTrue(node.isLeaf());
053:                assertEquals(0, node.getChildCount());
054:                node = new DynamicUtilTreeNode("value", "children value");
055:                assertEquals(node.childValue, "children value");
056:                assertTrue(node.loadedChildren);
057:                node = new DynamicUtilTreeNode("value", new Object[] { "1" });
058:                assertFalse(node.loadedChildren);
059:                node = new DynamicUtilTreeNode("value", new Object[] {});
060:                assertFalse(node.loadedChildren);
061:            }
062:
063:            public void testCreateChildren() throws Exception {
064:                DynamicUtilTreeNode.createChildren(null, "any");
065:                DefaultMutableTreeNode root = new DefaultMutableTreeNode();
066:                DynamicUtilTreeNode.createChildren(root, "any");
067:                assertEquals(0, root.getChildCount());
068:                assertTrue(root.isLeaf());
069:                int[] privitiveArrayChildren = new int[] { 1, 2, 3 };
070:                DynamicUtilTreeNode
071:                        .createChildren(root, privitiveArrayChildren);
072:                assertEquals(0, root.getChildCount());
073:                assertTrue(root.isLeaf());
074:                assertTrue(root.getAllowsChildren());
075:                Object[] objectArrayChildren = new Object[] { "a", "b", "c" };
076:                DynamicUtilTreeNode.createChildren(root, objectArrayChildren);
077:                assertEquals(3, root.getChildCount());
078:                assertTrue(root.getChildAt(0) instanceof  JTree.DynamicUtilTreeNode);
079:                assertFalse(root.isLeaf());
080:                assertEquals("a", ((DefaultMutableTreeNode) root.getChildAt(0))
081:                        .getUserObject());
082:                Vector<String> vectorChildren = new Vector<String>();
083:                vectorChildren.add("1");
084:                vectorChildren.add("2");
085:                DynamicUtilTreeNode.createChildren(root, vectorChildren);
086:                assertEquals(5, root.getChildCount());
087:                assertTrue(root.getChildAt(4) instanceof  JTree.DynamicUtilTreeNode);
088:                assertTrue(root.getChildAt(4).isLeaf());
089:                assertFalse(root.getChildAt(4).getAllowsChildren());
090:                assertEquals("1", ((DefaultMutableTreeNode) root.getChildAt(3))
091:                        .getUserObject());
092:                Hashtable<String, String> hashChildren = new Hashtable<String, String>();
093:                hashChildren.put("key1", "value1");
094:                hashChildren.put("key2", "value2");
095:                DynamicUtilTreeNode.createChildren(root, hashChildren);
096:                assertEquals(7, root.getChildCount());
097:                assertTrue(root.getChildAt(5) instanceof  JTree.DynamicUtilTreeNode);
098:                assertEquals(hashChildren.keys().nextElement(),
099:                        ((DefaultMutableTreeNode) root.getChildAt(5))
100:                                .getUserObject());
101:                assertEquals(0, root.getChildAt(5).getChildCount());
102:                root = new DefaultMutableTreeNode();
103:                Hashtable<String, String> subSubChildren = new Hashtable<String, String>();
104:                subSubChildren.put("221", "any");
105:                subSubChildren.put("222", "any");
106:                Vector<Serializable> subChildren = new Vector<Serializable>();
107:                subChildren.add("21");
108:                subChildren.add(subSubChildren);
109:                subChildren.add("23");
110:                Object[] complexChildren = new Object[] { "1", subChildren, "3" };
111:                DynamicUtilTreeNode.createChildren(root, complexChildren);
112:                assertEquals(3, root.getChildCount());
113:                DynamicUtilTreeNode child1 = (DynamicUtilTreeNode) root
114:                        .getChildAt(0);
115:                assertFalse(child1.getAllowsChildren());
116:                assertEquals(0, child1.getChildCount());
117:                assertEquals("1", child1.getUserObject());
118:                assertEquals("1", child1.childValue);
119:                assertTrue(child1.loadedChildren);
120:                DynamicUtilTreeNode child2 = (DynamicUtilTreeNode) root
121:                        .getChildAt(1);
122:                assertTrue(child2.getAllowsChildren());
123:                assertEquals(3, child2.getChildCount());
124:                assertEquals(subChildren, child2.getUserObject());
125:                assertSame(subChildren, child2.childValue);
126:                assertTrue(child2.loadedChildren);
127:                assertEquals(0, root.getChildAt(2).getChildCount());
128:                assertEquals("3", ((DefaultMutableTreeNode) root.getChildAt(2))
129:                        .getUserObject());
130:                assertEquals(3, child2.getChildCount());
131:                assertEquals(0, child2.getChildAt(0).getChildCount());
132:                assertEquals(2, child2.getChildAt(1).getChildCount());
133:                assertEquals(0, child2.getChildAt(2).getChildCount());
134:            }
135:
136:            public void testIsLeaf() throws Exception {
137:                DynamicUtilTreeNode node = new DynamicUtilTreeNode("value",
138:                        null);
139:                assertFalse(node.getAllowsChildren());
140:                assertTrue(node.isLeaf());
141:                node.setAllowsChildren(true);
142:                assertFalse(node.isLeaf());
143:            }
144:
145:            public void testGetChildCount() throws Exception {
146:                DynamicUtilTreeNode node = new DynamicUtilTreeNode("value",
147:                        new Object[] { "1", "2" });
148:                assertFalse(node.loadedChildren);
149:                assertEquals(2, node.getChildCount());
150:                assertTrue(node.loadedChildren);
151:            }
152:
153:            public void testGetChildAt() throws Exception {
154:                DynamicUtilTreeNode node = new DynamicUtilTreeNode("value",
155:                        new Object[] { "1", "2" });
156:                assertFalse(node.loadedChildren);
157:                assertEquals("1", ((DynamicUtilTreeNode) node.getChildAt(0))
158:                        .getUserObject());
159:                assertTrue(node.loadedChildren);
160:            }
161:
162:            public void testChildren() throws Exception {
163:                DynamicUtilTreeNode node = new DynamicUtilTreeNode("value",
164:                        new Object[] { "1", "2" });
165:                assertFalse(node.loadedChildren);
166:                Enumeration<?> children = node.children();
167:                assertTrue(node.loadedChildren);
168:                assertEquals("1", ((DefaultMutableTreeNode) children
169:                        .nextElement()).getUserObject());
170:                assertEquals("2", ((DefaultMutableTreeNode) children
171:                        .nextElement()).getUserObject());
172:            }
173:
174:            public void testLoadChildren() throws Exception {
175:                Object[] children = new Object[] { "1", "2" };
176:                DynamicUtilTreeNode node = new DynamicUtilTreeNode("value",
177:                        children);
178:                assertFalse(node.loadedChildren);
179:                assertEquals(children, node.childValue);
180:                assertEquals("value", node.getUserObject());
181:                node.loadChildren();
182:                assertTrue(node.loadedChildren);
183:                assertEquals(2, node.getChildCount());
184:                node.childValue = "any";
185:                node.loadChildren();
186:                assertEquals(2, node.getChildCount());
187:                assertEquals("value", node.getUserObject());
188:                node.childValue = new Object[] { "3", "4", "5" };
189:                node.loadChildren();
190:                assertTrue(node.loadedChildren);
191:                assertEquals(5, node.getChildCount());
192:                assertEquals("5", ((DefaultMutableTreeNode) node.getChildAt(4))
193:                        .getUserObject());
194:                node.childValue = new Object[] { "6" };
195:                assertEquals(5, node.getChildCount());
196:                node.loadedChildren = false;
197:                assertEquals(6, node.getChildCount());
198:            }
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.