Path: blob/master/test/jdk/sanity/client/SwingSet/src/OptionPaneDemoTest.java
41153 views
/*1* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import com.sun.swingset3.demos.optionpane.OptionPaneDemo;24import static com.sun.swingset3.demos.optionpane.OptionPaneDemo.*;2526import javax.swing.UIManager;2728import org.jtregext.GuiTestListener;2930import org.netbeans.jemmy.ClassReference;31import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;32import org.netbeans.jemmy.operators.JButtonOperator;33import org.netbeans.jemmy.operators.JComboBoxOperator;34import org.netbeans.jemmy.operators.JDialogOperator;35import org.netbeans.jemmy.operators.JFrameOperator;36import org.netbeans.jemmy.operators.JLabelOperator;37import org.netbeans.jemmy.operators.JTextFieldOperator;3839import org.testng.annotations.Listeners;40import org.testng.annotations.Test;41import static org.testng.AssertJUnit.*;424344/*45* @test46* @key headful47* @summary Verifies SwingSet3 OptionPaneDemo page by opening all the dialogs48* and choosing different options in them.49*50* @library /sanity/client/lib/jemmy/src51* @library /sanity/client/lib/Extensions/src52* @library /sanity/client/lib/SwingSet3/src53* @modules java.desktop54* java.logging55* @build org.jemmy2ext.JemmyExt56* @build com.sun.swingset3.demos.optionpane.OptionPaneDemo57* @run testng/timeout=600 OptionPaneDemoTest58*/59@Listeners(GuiTestListener.class)60public class OptionPaneDemoTest {6162public static final String SOME_TEXT_TO_TYPE = "I am some text";63public static final String MESSAGE = UIManager.getString("OptionPane.messageDialogTitle");64public static final String OK = "OK";65public static final String CANCEL = "Cancel";66public static final String INPUT = UIManager.getString("OptionPane.inputDialogTitle");67public static final String TEXT_TO_TYPE = "Hooray! I'm a textField";68public static final String NO = "No";69public static final String YES = "Yes";70public static final String SELECT_AN_OPTION = UIManager.getString("OptionPane.titleText");7172@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)73public void test(String lookAndFeel) throws Exception {74UIManager.setLookAndFeel(lookAndFeel);7576new ClassReference(OptionPaneDemo.class.getCanonicalName()).startApplication();7778JFrameOperator frame = new JFrameOperator(DEMO_TITLE);7980showInputDialog(frame);81showWarningDialog(frame);82showMessageDialog(frame);83showComponentDialog(frame);84showConfirmationDialog(frame);85}8687private void checkMessage(String message) {88JDialogOperator jdo = new JDialogOperator(MESSAGE);89new JLabelOperator(jdo, message);90new JButtonOperator(jdo, OK).push();91jdo.waitClosed();92}9394private void useInputDialog(JFrameOperator jfo, String textToType, String buttonToPush) {95new JButtonOperator(jfo, INPUT_BUTTON).pushNoBlock();96JDialogOperator jdo = new JDialogOperator(INPUT);97if (textToType != null) {98JTextFieldOperator jto = new JTextFieldOperator(jdo);99jto.typeText(textToType);100jto.waitText(textToType);101}102new JButtonOperator(jdo, buttonToPush).push();103jdo.waitClosed();104}105106public void showInputDialog(JFrameOperator jfo) throws Exception {107// Cancel with text case108useInputDialog(jfo, SOME_TEXT_TO_TYPE, CANCEL);109//TODO: wait for no dialog displayed110111// Cancel with *NO* text case112useInputDialog(jfo, null, CANCEL);113//TODO: wait for no dialog displayed114115// Text field has *NO* input116useInputDialog(jfo, null, OK);117//TODO: wait for no dialog displayed118119// Text field has input120{121final String enteredText = "Rambo";122123useInputDialog(jfo, enteredText, OK);124checkMessage(enteredText + INPUT_RESPONSE);125}126}127128public void showWarningDialog(JFrameOperator jfo) throws Exception {129new JButtonOperator(jfo, WARNING_BUTTON).pushNoBlock();130131JDialogOperator jdo = new JDialogOperator(WARNING_TITLE);132133new JButtonOperator(jdo, OK).push();134135jdo.waitClosed();136}137138public void showMessageDialog(JFrameOperator jfo) throws Exception {139new JButtonOperator(jfo, MESSAGE_BUTTON).pushNoBlock();140141JDialogOperator jdo = new JDialogOperator(MESSAGE);142143new JButtonOperator(jdo, OK).push();144145jdo.waitClosed();146}147148private void callADialogAndClose(JFrameOperator jfo, String buttonToOpenDialog,149String dialogTitle, String buttonToPush) {150new JButtonOperator(jfo, buttonToOpenDialog).pushNoBlock();151JDialogOperator jdo = new JDialogOperator(dialogTitle);152new JButtonOperator(jdo, buttonToPush).push();153jdo.waitClosed();154}155156public void showComponentDialog(JFrameOperator jfo) throws Exception {157// Case: Cancel158callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP5);159//TODO: wait for no dialog displayed160161// Case: Yes option selected162{163callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP1);164checkMessage(COMPONENT_R1);165}166167// Case: No option selected168{169callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP2);170checkMessage(COMPONENT_R2);171}172173// Case: Maybe option selected174{175callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP3);176checkMessage(COMPONENT_R3);177}178179// Case: Probably option selected180{181callADialogAndClose(jfo, COMPONENT_BUTTON, COMPONENT_TITLE, COMPONENT_OP4);182checkMessage(COMPONENT_R4);183}184185// Case TextField and ComboBox functional186{187new JButtonOperator(jfo, COMPONENT_BUTTON).push();188189JDialogOperator jdo = new JDialogOperator(COMPONENT_TITLE);190191JTextFieldOperator jto = new JTextFieldOperator(jdo);192jto.clearText();193jto.typeText(TEXT_TO_TYPE);194jto.waitText(TEXT_TO_TYPE);195196JComboBoxOperator jcbo = new JComboBoxOperator(jdo);197jcbo.selectItem(2);198jcbo.waitItemSelected(2);199200new JButtonOperator(jdo, COMPONENT_OP5).push();201jdo.waitClosed();202//TODO: wait for no dialog displayed203}204}205206public void showConfirmationDialog(JFrameOperator jfo) throws Exception {207// Case: Yes option selected208{209callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, YES);210checkMessage(CONFIRM_YES);211}212213// Case: No option selected214{215callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, NO);216checkMessage(CONFIRM_NO);217}218219// Case: Cancel option selected220{221callADialogAndClose(jfo, CONFIRM_BUTTON, SELECT_AN_OPTION, CANCEL);222//TODO: wait for no dialog displayed223}224}225226}227228229