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 27 import java.awt.Component; 28 import javax.swing.JList; 29 30 import org.netbeans.jemmy.ClassReference; 31 import org.netbeans.jemmy.ComponentChooser; 32 import org.netbeans.jemmy.operators.JCheckBoxOperator; 33 import org.netbeans.jemmy.operators.JFrameOperator; 34 import org.netbeans.jemmy.operators.JListOperator; 35 36 import static org.jemmy2ext.JemmyExt.*; 37 38 import org.jtregext.GuiTestListener; 39 40 import org.testng.annotations.Listeners; 41 import org.testng.annotations.Test; 42 import static org.testng.AssertJUnit.*; 43 44 /* 45 * @test 46 * @key headful 47 * @summary Verifies SwingSet3 ListDemo page by checking and unchecking all 48 * the checkboxes on the page and verifying the number of items in the 49 * list. 50 * 51 * @library /sanity/client/lib/jemmy/src 52 * @library /sanity/client/lib/Extensions/src 53 * @library /sanity/client/lib/SwingSet3/src 54 * @modules java.desktop 55 * @build org.jemmy2ext.JemmyExt 56 * @build com.sun.swingset3.demos.list.ListDemo 57 * @run testng ListDemoTest 58 */ 59 @Listeners(GuiTestListener.class) 60 public class ListDemoTest { 61 62 private static final int CHECKBOX_COUNT = 50; 63 64 private void waitModelSize(JListOperator listOp, int size) { 65 listOp.waitState(new ComponentChooser() { 66 public boolean checkComponent(Component comp) { 67 return getUIValue(listOp, (JList list) -> list.getModel().getSize()) == size; 68 } 69 public String getDescription() { 70 return "Model size to be equal to " + size; 71 } 72 }); 73 } 74 75 @Test 76 public void test() throws Exception { 77 78 new ClassReference(ListDemo.class.getCanonicalName()).startApplication(); 79 80 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); 81 JListOperator listOp = new JListOperator(frame); 82 83 // Check *NO* Prefix and Suffixes Marked 84 for (int i = 0; i < CHECKBOX_COUNT; i++) { 85 JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); 86 checkBox.changeSelection(false); 87 } 88 waitModelSize(listOp, 0); 89 90 // Check *ALL* Prefix and Suffixes Marked 91 for (int i = 0; i < CHECKBOX_COUNT; i++) { 92 JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); 93 checkBox.changeSelection(true); 94 } 95 waitModelSize(listOp, CHECKBOX_COUNT * CHECKBOX_COUNT / 4); 96 97 // Check *ALL* Prefix and *NO* Suffixes Marked 98 for (int i = 0; i < CHECKBOX_COUNT; i++) { 99 JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); 100 if (i < CHECKBOX_COUNT / 2) { 101 checkBox.changeSelection(true); 102 } else { 103 checkBox.changeSelection(false); 104 } 105 } 106 waitModelSize(listOp, 0); 107 108 // Check *NO* Prefix and *ALL* Suffixes Marked 109 for (int i = 0; i < CHECKBOX_COUNT; i++) { 110 JCheckBoxOperator checkBox = getJCheckBoxOperator(frame, i); 111 if (i < CHECKBOX_COUNT / 2) { 112 checkBox.changeSelection(false); 113 } else { 114 checkBox.changeSelection(true); 115 } 116 } 117 waitModelSize(listOp, 0); 118 } 119 120 private JCheckBoxOperator getJCheckBoxOperator(JFrameOperator frame, int index) { 121 122 // We map first half of indexes to the Prefixes panel and the second half 123 // to the Suffixes panel 124 String labelText; 125 int subindex; 126 if (index < CHECKBOX_COUNT / 2) { 127 labelText = "Prefixes"; 128 subindex = index; 129 } else { 130 labelText = "Suffixes"; 131 subindex = index - CHECKBOX_COUNT / 2; 132 } 133 134 JCheckBoxOperator result = new JCheckBoxOperator(getLabeledContainerOperator(frame, labelText), subindex); 135 result.setVerification(true); 136 return result; 137 } 138 139 }