Source Code Cross Referenced for JTreeLocationTest.java in  » Testing » abbot-1.0.1 » abbot » tester » 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 » Testing » abbot 1.0.1 » abbot.tester 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package abbot.tester;
002:
003:        import java.awt.Point;
004:        import java.awt.Rectangle;
005:
006:        import javax.swing.JTree;
007:        import javax.swing.tree.*;
008:
009:        import junit.extensions.abbot.TestHelper;
010:        import junit.framework.TestCase;
011:        import abbot.script.parsers.TreePathParser;
012:
013:        public class JTreeLocationTest extends TestCase {
014:
015:            protected JTree createTree() {
016:                DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
017:                DefaultMutableTreeNode parent = new DefaultMutableTreeNode(
018:                        "parent");
019:                DefaultMutableTreeNode child = new DefaultMutableTreeNode(
020:                        "child");
021:                root.add(parent);
022:                parent.add(child);
023:                return new JTree(root);
024:            }
025:
026:            public void testRowPoint() {
027:                JTree tree = createTree();
028:                Point p = new JTreeLocation(0).getPoint(tree);
029:                Rectangle rect = tree.getRowBounds(0);
030:                assertTrue("Row point should be within row", rect.contains(p));
031:
032:                p = new JTreeLocation(0, true).getPoint(tree);
033:                assertTrue("Row point should be in expansion control",
034:                        JTreeTester.isLocationInExpandControl(tree, p.x, p.y));
035:            }
036:
037:            public void testPathPoint() {
038:                JTree tree = createTree();
039:                TreePath path = new TreePath(tree.getModel().getRoot());
040:                Point p = new JTreeLocation(path).getPoint(tree);
041:                Rectangle rect = tree.getRowBounds(0);
042:                assertTrue("Path point should be within path's row", rect
043:                        .contains(p));
044:
045:                p = new JTreeLocation(path, true).getPoint(tree);
046:                assertTrue("Path point should be in expansion control",
047:                        JTreeTester.isLocationInExpandControl(tree, p.x, p.y));
048:            }
049:
050:            public void testParsePoint() {
051:                JTreeLocation loc = new JTreeLocation();
052:                String parse = "(1,1)";
053:                assertEquals("Badly parsed: " + parse, new JTreeLocation(
054:                        new Point(1, 1)), loc.parse(parse));
055:            }
056:
057:            public void testParseRow() {
058:                JTreeLocation loc = new JTreeLocation();
059:                String parse = "[1]";
060:                JTreeLocation loc2 = new JTreeLocation(1);
061:                assertEquals("Badly parsed: " + parse, loc2, loc.parse(parse));
062:                assertEquals("Wrong row-based toString", parse, loc.toString());
063:
064:                parse = " [ 10 ] ";
065:                loc2 = new JTreeLocation(10);
066:                assertEquals("Badly parsed: " + parse, loc2, loc.parse(parse));
067:                assertEquals("Wrong row-based toString", "[10]", loc.toString());
068:
069:                parse = "+[10]";
070:                loc2 = new JTreeLocation(10, true);
071:                assertEquals("Badly parsed: " + parse, loc2, loc.parse(parse));
072:
073:                assertEquals("Wrong row-based toString", parse, loc.toString());
074:            }
075:
076:            public void testParsePath() {
077:                JTreeLocation loc = new JTreeLocation();
078:                String parse = "[root, parent, child]";
079:                TreePath path = (TreePath) new TreePathParser().parse(parse);
080:                JTreeLocation loc2 = new JTreeLocation(path);
081:                assertEquals("Badly parsed: " + parse, loc2, loc.parse("\""
082:                        + parse + "\""));
083:                assertEquals("Wrong path-based toString", "\"" + parse + "\"",
084:                        loc.toString());
085:
086:                loc2.setInExpansion(true);
087:                assertEquals("Badly parsed: +" + parse, loc2, loc.parse("+\""
088:                        + parse + "\""));
089:                assertEquals("Wrong path-based toString", "+\"" + parse + "\"",
090:                        loc.toString());
091:            }
092:
093:            public void testParsePathHiddenRoot() {
094:                JTreeLocation loc = new JTreeLocation();
095:                String parse = "[null, parent, child]";
096:                assertEquals("Badly parsed: " + parse, new JTreeLocation(
097:                        (TreePath) new TreePathParser().parse(parse)), loc
098:                        .parse("\"" + parse + "\""));
099:            }
100:
101:            public void testConvertHiddenRoot() {
102:                // Should be able to use path with or without the root reference
103:                JTree tree = createTree();
104:                tree.setRootVisible(false);
105:                Object root = tree.getModel().getRoot();
106:                Object parent = tree.getModel().getChild(root, 0);
107:                Object child = tree.getModel().getChild(parent, 0);
108:                TreePath p1 = (TreePath) new TreePathParser()
109:                        .parse("[null, parent, child]");
110:                TreePath p2 = JTreeLocation.findMatchingPath(tree, p1);
111:                assertTrue("Got a null path", p2 != null);
112:                assertEquals("Wrong root", root, p2.getPathComponent(0));
113:                assertEquals("Wrong parent", parent, p2.getPathComponent(1));
114:                assertEquals("Wrong child", child, p2.getPathComponent(2));
115:
116:                p1 = (TreePath) new TreePathParser().parse("[parent, child]");
117:                p2 = JTreeLocation.findMatchingPath(tree, p1);
118:                assertTrue("Got a null path", p2 != null);
119:                assertEquals("Wrong root", root, p2.getPathComponent(0));
120:                assertEquals("Wrong parent", parent, p2.getPathComponent(1));
121:                assertEquals("Wrong child", child, p2.getPathComponent(2));
122:            }
123:
124:            private static int count = 0;
125:
126:            public void testFindMatchingPath() {
127:                class Bar {
128:                    private int id = count++;
129:
130:                    public String toString() {
131:                        return String.valueOf(id);
132:                    }
133:                }
134:                DefaultMutableTreeNode root = new DefaultMutableTreeNode(
135:                        new Bar());
136:                DefaultMutableTreeNode parent = new DefaultMutableTreeNode(
137:                        new Bar());
138:                DefaultMutableTreeNode child = new DefaultMutableTreeNode(
139:                        new Bar());
140:                root.add(parent);
141:                parent.add(child);
142:                JTree tree = new JTree(root);
143:                TreePath path = new TreePath(
144:                        new Object[] { root, parent, child });
145:                TreePath strPath = new TreePath(new String[] { "0", "1", "2" });
146:                JTreeLocation loc = new JTreeLocation(path);
147:                assertEquals(
148:                        "String path should be converted to real TreePath",
149:                        path, JTreeLocation.findMatchingPath(tree, strPath));
150:
151:                class Foo {
152:                }
153:                root = new DefaultMutableTreeNode(new Foo());
154:                parent = new DefaultMutableTreeNode(new Foo());
155:                child = new DefaultMutableTreeNode(new Foo());
156:                root.add(parent);
157:                parent.add(child);
158:                tree = new JTree(root);
159:
160:                path = new TreePath(new Object[] { root, parent, child });
161:                loc = new JTreeLocation(path);
162:                assertEquals("Should return original tree path if it's not a "
163:                        + "string-based path", path, JTreeLocation
164:                        .findMatchingPath(tree, path));
165:            }
166:
167:            public void testFindDuplicateMatchingPath() {
168:                class Bar {
169:                    private int id;
170:
171:                    public Bar(int id) {
172:                        this .id = id;
173:                    }
174:
175:                    public String toString() {
176:                        return String.valueOf(id);
177:                    }
178:                }
179:                DefaultMutableTreeNode root = new DefaultMutableTreeNode(
180:                        new Bar(0));
181:                DefaultMutableTreeNode parent = new DefaultMutableTreeNode(
182:                        new Bar(0));
183:                DefaultMutableTreeNode parent2 = new DefaultMutableTreeNode(
184:                        new Bar(0));
185:                // Make these have the same string value
186:                DefaultMutableTreeNode child = new DefaultMutableTreeNode(
187:                        new Bar(1));
188:                DefaultMutableTreeNode child2 = new DefaultMutableTreeNode(
189:                        new Bar(1));
190:                DefaultMutableTreeNode child3 = new DefaultMutableTreeNode(
191:                        new Bar(1));
192:                DefaultMutableTreeNode child4 = new DefaultMutableTreeNode(
193:                        new Bar(1));
194:                root.add(parent);
195:                root.add(parent2);
196:                parent.add(child);
197:                parent.add(child2);
198:                parent2.add(child3);
199:                parent2.add(child4);
200:                JTree tree = new JTree(root);
201:                TreePath path = new TreePath(new Object[] { root, parent,
202:                        child2 });
203:                TreePath strpath = new TreePath(
204:                        new String[] { "0", "0", "1[1]" });
205:                JTreeLocation loc = new JTreeLocation(path);
206:                assertEquals(
207:                        "String path should be converted to real TreePath",
208:                        path, JTreeLocation.findMatchingPath(tree, strpath));
209:
210:                path = new TreePath(new Object[] { root, parent, child });
211:                strpath = new TreePath(new String[] { "0", "0", "1" });
212:                loc = new JTreeLocation(path);
213:                assertEquals(
214:                        "String path should be converted to real TreePath",
215:                        path, JTreeLocation.findMatchingPath(tree, strpath));
216:
217:                path = new TreePath(new Object[] { root, parent2, child3 });
218:                strpath = new TreePath(new String[] { "0", "0[1]", "1" });
219:                loc = new JTreeLocation(path);
220:                assertEquals(
221:                        "String path should be converted to real TreePath",
222:                        path, JTreeLocation.findMatchingPath(tree, strpath));
223:
224:                path = new TreePath(new Object[] { root, parent2, child4 });
225:                strpath = new TreePath(new String[] { "0", "0[1]", "1[1]" });
226:                loc = new JTreeLocation(path);
227:                assertEquals(
228:                        "String path should be converted to real TreePath",
229:                        path, JTreeLocation.findMatchingPath(tree, strpath));
230:
231:            }
232:
233:            // TODO: add recorder test as well
234:            public JTreeLocationTest(String name) {
235:                super (name);
236:            }
237:
238:            public static void main(String[] args) {
239:                TestHelper.runTests(args, JTreeLocationTest.class);
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.