|
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.list.ListDemo; |
|
25 import static com.sun.swingset3.demos.list.ListDemo.DEMO_TITLE; |
|
26 import static org.testng.AssertJUnit.*; |
|
27 import org.testng.annotations.Test; |
|
28 import static org.jemmy2ext.JemmyExt.getLabeledContainerOperator; |
|
29 import org.netbeans.jemmy.ClassReference; |
|
30 import org.netbeans.jemmy.operators.JCheckBoxOperator; |
|
31 import org.netbeans.jemmy.operators.JFrameOperator; |
|
32 import org.netbeans.jemmy.operators.JListOperator; |
|
33 import static org.jemmy2ext.JemmyExt.captureDebugInfoOnFail; |
|
34 |
|
35 /* |
|
36 * @test |
|
37 * @key headful |
|
38 * @summary Verifies SwingSet3 ListDemo page by checking and unchecking all |
|
39 * the checkboxes on the page and verifying the number of items in the |
|
40 * list. |
|
41 * |
|
42 * @library /sanity/client/lib/jemmy/src |
|
43 * @library /sanity/client/lib/Jemmy2Ext/src |
|
44 * @library /sanity/client/lib/SwingSet3/src |
|
45 * @build org.jemmy2ext.JemmyExt |
|
46 * @build com.sun.swingset3.demos.list.ListDemo |
|
47 * @run testng ListDemoTest |
|
48 */ |
|
49 public class ListDemoTest { |
|
50 |
|
51 private static final int CHECKBOX_COUNT = 50; |
|
52 |
|
53 @Test |
|
54 public void test() throws Exception { |
|
55 captureDebugInfoOnFail(() -> { |
|
56 new ClassReference(ListDemo.class.getCanonicalName()).startApplication(); |
|
57 |
|
58 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
|
59 JListOperator listOp = new JListOperator(frame); |
|
60 |
|
61 // Check *NO* Prefix and Suffixes Marked |
|
62 for (int i = 0; i < CHECKBOX_COUNT; i++) { |
|
63 JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); |
|
64 checkBox.changeSelection(false); |
|
65 } |
|
66 System.out.println("######## Number of Items = " + listOp.getModel().getSize()); |
|
67 assertEquals("Select None number of items is correct", 0, listOp.getModel().getSize()); |
|
68 |
|
69 // Check *ALL* Prefix and Suffixes Marked |
|
70 for (int i = 0; i < CHECKBOX_COUNT; i++) { |
|
71 JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); |
|
72 checkBox.changeSelection(true); |
|
73 } |
|
74 System.out.println("######## Number of Items = " + listOp.getModel().getSize()); |
|
75 assertEquals("Select All number of items is correct", CHECKBOX_COUNT / 2 * CHECKBOX_COUNT / 2, listOp.getModel().getSize()); |
|
76 |
|
77 // Check *ALL* Prefix and *NO* Suffixes Marked |
|
78 for (int i = 0; i < CHECKBOX_COUNT; i++) { |
|
79 JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); |
|
80 if (i < CHECKBOX_COUNT / 2) { |
|
81 checkBox.changeSelection(true); |
|
82 } else { |
|
83 checkBox.changeSelection(false); |
|
84 } |
|
85 } |
|
86 System.out.println("######## Number of Items = " + listOp.getModel().getSize()); |
|
87 assertEquals("Select All Prefixes and NO Suffixes number of items is correct", 0, listOp.getModel().getSize()); |
|
88 |
|
89 // Check *NO* Prefix and *ALL* Suffixes Marked |
|
90 for (int i = 0; i < CHECKBOX_COUNT; i++) { |
|
91 JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); |
|
92 if (i < CHECKBOX_COUNT / 2) { |
|
93 checkBox.changeSelection(false); |
|
94 } else { |
|
95 checkBox.changeSelection(true); |
|
96 } |
|
97 } |
|
98 System.out.println("######## Number of Items = " + listOp.getModel().getSize()); |
|
99 assertEquals("Select NO Prefixes and All Suffixes number of items is correct", 0, listOp.getModel().getSize()); |
|
100 }); |
|
101 } |
|
102 |
|
103 private JCheckBoxOperator getJCheckBoxOperator(JFrameOperator frame, int index) { |
|
104 |
|
105 // We map first half of indexes to the Prefixes panel and the second half |
|
106 // to the Suffixes panel |
|
107 String labelText; |
|
108 int subindex; |
|
109 if (index < CHECKBOX_COUNT / 2) { |
|
110 labelText = "Prefixes"; |
|
111 subindex = index; |
|
112 } else { |
|
113 labelText = "Suffixes"; |
|
114 subindex = index - CHECKBOX_COUNT / 2; |
|
115 } |
|
116 |
|
117 return new JCheckBoxOperator(getLabeledContainerOperator(frame, labelText), subindex); |
|
118 } |
|
119 |
|
120 } |