|
1 /* |
|
2 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 import com.sun.swingset3.demos.tree.TreeDemo; |
|
25 import static com.sun.swingset3.demos.tree.TreeDemo.DEMO_TITLE; |
|
26 import javax.swing.tree.TreePath; |
|
27 import static org.testng.AssertJUnit.*; |
|
28 import org.testng.annotations.Test; |
|
29 import org.netbeans.jemmy.ClassReference; |
|
30 import org.netbeans.jemmy.operators.JFrameOperator; |
|
31 import org.netbeans.jemmy.operators.JTreeOperator; |
|
32 import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; |
|
33 |
|
34 /* |
|
35 * @test |
|
36 * @key headful |
|
37 * @summary Verifies SwingSet3 TreeDemo by expanding all collapsed nodes in the |
|
38 * tree and then collapsing all the expanded nodes in the tree. It |
|
39 * verifies the number of nodes expanded, number of nodes collapsed and |
|
40 * number of rows in the tree in the begininng, after expanding and |
|
41 * after collapsing the nodes. It also checks that the tree grows |
|
42 * vertically (as ScrollPane allows it). |
|
43 * |
|
44 * @library /sanity/client/lib/jemmy/src |
|
45 * @library /sanity/client/lib/Jemmy2Ext/src |
|
46 * @library /sanity/client/lib/SwingSet3/src |
|
47 * @build org.jemmy2ext.JemmyExt |
|
48 * @build com.sun.swingset3.demos.tree.TreeDemo |
|
49 * @run testng TreeDemoTest |
|
50 */ |
|
51 public class TreeDemoTest { |
|
52 |
|
53 @Test |
|
54 public void test() throws Exception { |
|
55 captureDebugInfoOnFail(() -> { |
|
56 new ClassReference(TreeDemo.class.getCanonicalName()).startApplication(); |
|
57 |
|
58 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
|
59 |
|
60 JTreeOperator tree = new JTreeOperator(frame); |
|
61 |
|
62 assertEquals("Initial number of rows in the tree", 4, tree.getRowCount()); |
|
63 |
|
64 int initialTreeHeight = tree.getHeight(); |
|
65 |
|
66 // expand all nodes |
|
67 int expandsCount = 0; |
|
68 for (int i = 0; i < tree.getRowCount(); i++) { |
|
69 TreePath tp = tree.getPathForRow(i); |
|
70 if (tree.getChildCount(tp) > 0 && !tree.isExpanded(tp)) { |
|
71 tree.expandRow(i); |
|
72 expandsCount++; |
|
73 } |
|
74 } |
|
75 |
|
76 assertEquals("Number of rows expanded", 75, expandsCount); |
|
77 assertEquals("Number of rows in the tree after expanding all of them", |
|
78 616, tree.getRowCount()); |
|
79 |
|
80 int expandedTreeHeight = tree.getHeight(); |
|
81 assertTrue("Expanded tree height has increased, current " |
|
82 + expandedTreeHeight + " > initial " + initialTreeHeight, |
|
83 expandedTreeHeight > initialTreeHeight); |
|
84 |
|
85 // collapse all nodes |
|
86 int collapsesCount = 0; |
|
87 for (int i = tree.getRowCount() - 1; i >= 0; i--) { |
|
88 TreePath tp = tree.getPathForRow(i); |
|
89 if (tree.getChildCount(tp) > 0 && tree.isExpanded(tp)) { |
|
90 tree.collapseRow(i); |
|
91 collapsesCount++; |
|
92 } |
|
93 } |
|
94 |
|
95 assertEquals("Number of rows collapsed", 76, collapsesCount); |
|
96 assertEquals("Number of rows in the tree after collapsing all of them", |
|
97 1, tree.getRowCount()); |
|
98 |
|
99 int collapsedTreeHeight = tree.getHeight(); |
|
100 assertTrue("Collpased tree height is not longer than initial, " |
|
101 + "current " + collapsedTreeHeight + " <= initial " |
|
102 + initialTreeHeight, |
|
103 collapsedTreeHeight <= initialTreeHeight); |
|
104 |
|
105 }); |
|
106 } |
|
107 |
|
108 } |