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.optionpane.OptionPaneDemo; 25 import static com.sun.swingset3.demos.optionpane.OptionPaneDemo.*; 26 27 import javax.swing.UIManager; 28 29 import org.jtregext.GuiTestListener; 30 31 import org.netbeans.jemmy.ClassReference; 32 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator; 33 import org.netbeans.jemmy.operators.JButtonOperator; 34 import org.netbeans.jemmy.operators.JComboBoxOperator; 35 import org.netbeans.jemmy.operators.JDialogOperator; 36 import org.netbeans.jemmy.operators.JFrameOperator; 37 import org.netbeans.jemmy.operators.JLabelOperator; 38 import org.netbeans.jemmy.operators.JTextFieldOperator; 39 40 import org.testng.annotations.Listeners; 41 import org.testng.annotations.Test; 42 import static org.testng.AssertJUnit.*; 43 44 45 /* 46 * @test 47 * @key headful 48 * @summary Verifies SwingSet3 OptionPaneDemo page by opening all the dialogs 49 * and choosing different options in them. 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.optionpane.OptionPaneDemo 57 * @run testng OptionPaneDemoTest 58 */ 59 @Listeners(GuiTestListener.class) 60 public class OptionPaneDemoTest { 61 62 public static final String SOME_TEXT_TO_TYPE = "I am some text"; 63 public static final String MESSAGE = UIManager.getString("OptionPane.messageDialogTitle"); 64 public static final String OK = "OK"; 65 public static final String CANCEL = "Cancel"; 66 public static final String INPUT = UIManager.getString("OptionPane.inputDialogTitle"); 67 public static final String TEXT_TO_TYPE = "Hooray! I'm a textField"; 68 public static final String NO = "No"; 69 public static final String YES = "Yes"; 70 public static final String SELECT_AN_OPTION = UIManager.getString("OptionPane.titleText"); 71 72 @Test 73 public void test() throws Exception { 74 75 new ClassReference(OptionPaneDemo.class.getCanonicalName()).startApplication(); 76 77 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); 78 79 showInputDialog(frame); 80 showWarningDialog(frame); 81 showMessageDialog(frame); 82 showComponentDialog(frame); 83 showConfirmationDialog(frame); 84 } 85 86 private void checkMessage(String message) { 87 JDialogOperator jdo1 = new JDialogOperator(MESSAGE); 88 final String labelText = COMPONENT_R3; 89 JLabelOperator jLabelOperator = new JLabelOperator(jdo1, message); 90 new JButtonOperator(jdo1, OK).push(); 91 jdo1.waitClosed(); 92 } 93 94 private void useInputDialog(JFrameOperator jfo, String textToType, String buttonToPush) { 95 new JButtonOperator(jfo, INPUT_BUTTON).pushNoBlock(); 96 JDialogOperator jdo = new JDialogOperator(INPUT); 97 if(textToType != null) { 98 new JTextFieldOperator(jdo).typeText(textToType); 99 } 100 new JButtonOperator(jdo, buttonToPush).push(); 101 jdo.waitClosed(); 102 } 103 104 public void showInputDialog(JFrameOperator jfo) throws Exception { 105 // Cancel with text case 106 useInputDialog(jfo, SOME_TEXT_TO_TYPE, CANCEL); 107 //TODO: wait for no dialog displayed 108 109 // Cancel with *NO* text case 110 useInputDialog(jfo, null, CANCEL); 111 //TODO: wait for no dialog displayed 112 113 // Text field has *NO* input 114 useInputDialog(jfo, null, OK); 115 //TODO: wait for no dialog displayed 116 117 // Text field has input 118 { 119 final String enteredText = "Rambo"; 120 121 useInputDialog(jfo, enteredText, OK); 122 checkMessage(enteredText + INPUT_RESPONSE); 123 } 124 } 125 126 public void showWarningDialog(JFrameOperator jfo) throws Exception { 127 new JButtonOperator(jfo, WARNING_BUTTON).pushNoBlock(); 128 129 JDialogOperator jdo = new JDialogOperator(WARNING_TITLE); 130 131 new JButtonOperator(jdo, OK).push(); 132 133 jdo.waitClosed(); 134 } 135 136 public void showMessageDialog(JFrameOperator jfo) throws Exception { 137 new JButtonOperator(jfo, MESSAGE_BUTTON).pushNoBlock(); 138 139 JDialogOperator jdo = new JDialogOperator(MESSAGE); 140 141 new JButtonOperator(jdo, OK).push(); 142 143 jdo.waitClosed(); 144 } 145 146 private void callADialogAndClose(JFrameOperator jfo, String buttonToOpenDialog, 147 String dialogTitle, String buttonToPush) { 148 new JButtonOperator(jfo, buttonToOpenDialog).pushNoBlock(); 149 JDialogOperator jdo = new JDialogOperator(dialogTitle); 150 new JButtonOperator(jdo, buttonToPush).push(); 151 jdo.waitClosed(); 152 } 153 154 public void showComponentDialog(JFrameOperator jfo) throws Exception { 155 // Case: Cancel 156 callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP5); 157 //TODO: wait for no dialog displayed 158 159 // Case: Yes option selected 160 { 161 callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP1); 162 checkMessage(COMPONENT_R1); 163 } 164 165 // Case: No option selected 166 { 167 callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP2); 168 checkMessage(COMPONENT_R2); 169 } 170 171 // Case: Maybe option selected 172 { 173 callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP3); 174 checkMessage(COMPONENT_R3); 175 } 176 177 // Case: Probably option selected 178 { 179 callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP4); 180 checkMessage(COMPONENT_R4); 181 } 182 183 // Case TextField and ComboBox functional 184 { 185 new JButtonOperator(jfo, COMPONENT_BUTTON).push(); 186 187 JDialogOperator jdo = new JDialogOperator(COMPONENT_TITLE); 188 189 JTextFieldOperator jto = new JTextFieldOperator(jdo); 190 jto.clearText(); 191 jto.typeText(TEXT_TO_TYPE); 192 jto.waitText(TEXT_TO_TYPE); 193 194 JComboBoxOperator jcbo = new JComboBoxOperator(jdo); 195 jcbo.selectItem(2); 196 jcbo.waitItemSelected(2); 197 198 new JButtonOperator(jdo, COMPONENT_OP5).push(); 199 jdo.waitClosed(); 200 //TODO: wait for no dialog displayed 201 } 202 } 203 204 public void showConfirmationDialog(JFrameOperator jfo) throws Exception { 205 // Case: Yes option selected 206 { 207 callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, YES); 208 checkMessage(CONFIRM_YES); 209 } 210 211 // Case: No option selected 212 { 213 callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, NO); 214 checkMessage(CONFIRM_NO); 215 } 216 217 // Case: Cancel option selected 218 { 219 callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, CANCEL); 220 //TODO: wait for no dialog displayed 221 } 222 } 223 224 }