author | amurillo |
Fri, 19 Aug 2016 11:22:14 -0700 | |
changeset 40386 | cf75dd18b3cd |
parent 39006 | fd8c3312d043 |
permissions | -rw-r--r-- |
36744 | 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; |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
26 |
|
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
27 |
import java.awt.Component; |
36744 | 28 |
import javax.swing.tree.TreePath; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
29 |
|
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
30 |
import org.jtregext.GuiTestListener; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
31 |
|
36744 | 32 |
import org.netbeans.jemmy.ClassReference; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
33 |
import org.netbeans.jemmy.ComponentChooser; |
36744 | 34 |
import org.netbeans.jemmy.operators.JFrameOperator; |
35 |
import org.netbeans.jemmy.operators.JTreeOperator; |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
36 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
37 |
import org.testng.annotations.Listeners; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
38 |
import org.testng.annotations.Test; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
39 |
import static org.testng.AssertJUnit.*; |
36744 | 40 |
|
41 |
/* |
|
42 |
* @test |
|
43 |
* @key headful |
|
44 |
* @summary Verifies SwingSet3 TreeDemo by expanding all collapsed nodes in the |
|
45 |
* tree and then collapsing all the expanded nodes in the tree. It |
|
46 |
* verifies the number of nodes expanded, number of nodes collapsed and |
|
47 |
* number of rows in the tree in the begininng, after expanding and |
|
48 |
* after collapsing the nodes. It also checks that the tree grows |
|
49 |
* vertically (as ScrollPane allows it). |
|
50 |
* |
|
51 |
* @library /sanity/client/lib/jemmy/src |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
52 |
* @library /sanity/client/lib/Extensions/src |
36744 | 53 |
* @library /sanity/client/lib/SwingSet3/src |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
54 |
* @modules java.desktop |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
55 |
* java.logging |
36744 | 56 |
* @build org.jemmy2ext.JemmyExt |
57 |
* @build com.sun.swingset3.demos.tree.TreeDemo |
|
58 |
* @run testng TreeDemoTest |
|
59 |
*/ |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
60 |
@Listeners(GuiTestListener.class) |
36744 | 61 |
public class TreeDemoTest { |
62 |
||
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
63 |
private static final int NODES_TO_EXPAND = 75; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
64 |
private static final int NODES_TOTAL = 616; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
65 |
|
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
66 |
private void waitRowCount(JTreeOperator tree, int count) { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
67 |
tree.waitState(new ComponentChooser() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
68 |
public boolean checkComponent(Component comp) { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
69 |
return tree.getRowCount() == count; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
70 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
71 |
public String getDescription() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
72 |
return "A tree to have " + count + " rows"; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
73 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
74 |
}); |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
75 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
76 |
|
36744 | 77 |
@Test |
78 |
public void test() throws Exception { |
|
79 |
||
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
80 |
new ClassReference(TreeDemo.class.getCanonicalName()).startApplication(); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
81 |
|
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
82 |
JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
36744 | 83 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
84 |
JTreeOperator tree = new JTreeOperator(frame); |
36744 | 85 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
86 |
assertEquals("Initial number of rows in the tree", 4, tree.getRowCount()); |
36744 | 87 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
88 |
int initialTreeHeight = tree.getHeight(); |
36744 | 89 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
90 |
// expand all nodes |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
91 |
int expandsCount = 0; |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
92 |
for (int i = 0; i < tree.getRowCount(); i++) { |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
93 |
TreePath tp = tree.getPathForRow(i); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
94 |
if (tree.getChildCount(tp) > 0 && !tree.isExpanded(tp)) { |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
95 |
tree.expandRow(i); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
96 |
expandsCount++; |
36744 | 97 |
} |
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
98 |
} |
36744 | 99 |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
100 |
assertEquals("Number of rows expanded", NODES_TO_EXPAND, expandsCount); |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
101 |
waitRowCount(tree, NODES_TOTAL); |
36744 | 102 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
103 |
int expandedTreeHeight = tree.getHeight(); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
104 |
assertTrue("Expanded tree height has increased, current " |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
105 |
+ expandedTreeHeight + " > initial " + initialTreeHeight, |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
106 |
expandedTreeHeight > initialTreeHeight); |
36744 | 107 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
108 |
// collapse all nodes |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
109 |
int collapsesCount = 0; |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
110 |
for (int i = tree.getRowCount() - 1; i >= 0; i--) { |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
111 |
TreePath tp = tree.getPathForRow(i); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
112 |
if (tree.getChildCount(tp) > 0 && tree.isExpanded(tp)) { |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
113 |
tree.collapseRow(i); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
114 |
collapsesCount++; |
36744 | 115 |
} |
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
116 |
} |
36744 | 117 |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
118 |
assertEquals("Number of rows collapsed", NODES_TO_EXPAND + 1, collapsesCount); |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
119 |
waitRowCount(tree, 1); |
36744 | 120 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
121 |
int collapsedTreeHeight = tree.getHeight(); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
122 |
assertTrue("Collpased tree height is not longer than initial, " |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
123 |
+ "current " + collapsedTreeHeight + " <= initial " |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
124 |
+ initialTreeHeight, |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
125 |
collapsedTreeHeight <= initialTreeHeight); |
36744 | 126 |
|
127 |
} |
|
128 |
||
129 |
} |