< prev index next >

test/sanity/client/SwingSet/src/TextFieldDemoTest.java

Print this page




   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 org.jtregext.GuiTestListener;
  25 import com.sun.swingset3.demos.textfield.JHistoryTextField;
  26 import com.sun.swingset3.demos.textfield.TextFieldDemo;
  27 import static com.sun.swingset3.demos.textfield.TextFieldDemo.*;

  28 import java.awt.Color;

  29 import java.awt.event.KeyEvent;
  30 import java.util.Calendar;
  31 import java.util.Date;
  32 import java.util.Locale;
  33 import javax.swing.JFormattedTextField;

  34 import static org.jemmy2ext.JemmyExt.*;
  35 import static org.testng.AssertJUnit.*;
  36 import org.testng.annotations.Test;
  37 import org.netbeans.jemmy.ClassReference;

  38 import org.netbeans.jemmy.QueueTool;
  39 import org.netbeans.jemmy.operators.ContainerOperator;
  40 import org.netbeans.jemmy.operators.JButtonOperator;
  41 import org.netbeans.jemmy.operators.JFrameOperator;
  42 import org.netbeans.jemmy.operators.JLabelOperator;
  43 import org.netbeans.jemmy.operators.JPasswordFieldOperator;
  44 import org.netbeans.jemmy.operators.JTextFieldOperator;



  45 import org.testng.annotations.Listeners;


  46 
  47 /*
  48  * @test
  49  * @key headful
  50  * @summary Verifies SwingSet3 TextFieldDemo by entering text in each field and
  51  *          checking that app reacts accordingly.
  52  *
  53  * @library /sanity/client/lib/jemmy/src
  54  * @library /sanity/client/lib/Extensions/src
  55  * @library /sanity/client/lib/SwingSet3/src


  56  * @build org.jemmy2ext.JemmyExt
  57  * @build com.sun.swingset3.demos.textfield.TextFieldDemo
  58  * @run testng TextFieldDemoTest
  59  */
  60 @Listeners(GuiTestListener.class)
  61 public class TextFieldDemoTest {
  62 
  63     @Test
  64     public void test() throws Exception {
  65 
  66         new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication();
  67 
  68         JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
  69 
  70         historyTextField(frame);
  71         dateTextField(frame);
  72         passwordField(frame);
  73     }
  74 
  75     private void historyTextField(JFrameOperator jfo) throws Exception {


  78 
  79         jtfo.pressKey(KeyEvent.VK_DOWN);
  80         jtfo.pressKey(KeyEvent.VK_DOWN);
  81         jtfo.pressKey(KeyEvent.VK_ENTER);
  82 
  83         final String expectedValue = "category";
  84         jtfo.waitText(expectedValue);
  85         assertEquals("Select History Item", expectedValue, jtfo.getText());
  86     }
  87 
  88     public void dateTextField(JFrameOperator jfo) throws Exception {
  89         JTextFieldOperator jtfo = new JTextFieldOperator(jfo,
  90                 new ByClassChooser(JFormattedTextField.class));
  91         ContainerOperator<?> containerOperator = new ContainerOperator<>(jtfo.getParent());
  92         JButtonOperator jbo = new JButtonOperator(containerOperator, GO);
  93         JLabelOperator dowLabel = new JLabelOperator(containerOperator);
  94         Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
  95 
  96         // Check default date Day of the Week
  97         jbo.push();
  98         assertEquals("Default DOW",
  99                 calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH),
 100                 dowLabel.getText());
 101 
 102         // Check Custom Day of the Week
 103         calendar.set(2012, 9, 11); // Represents "Oct 11, 2012"
 104         Date date = calendar.getTime();
 105         String dateString = jtfo.getQueueTool().invokeAndWait(
 106                 new QueueTool.QueueAction<String>("Formatting the value using JFormattedTextField formatter") {
 107 
 108             @Override
 109             public String launch() throws Exception {
 110                 return ((JFormattedTextField) jtfo.getSource()).getFormatter().valueToString(date);
 111             }
 112         });
 113         System.out.println("dateString = " + dateString);
 114         jtfo.enterText(dateString);
 115 
 116         jbo.push();
 117         assertEquals("Custom DOW", "Thursday", dowLabel.getText());
 118     }
 119 
 120     public void passwordField(JFrameOperator jfo) throws Exception {
 121         JPasswordFieldOperator password1 = new JPasswordFieldOperator(jfo, 0);
 122         JPasswordFieldOperator password2 = new JPasswordFieldOperator(jfo, 1);
 123 
 124         password1.typeText("password");
 125         password2.typeText("password");
 126 
 127         // Check Matching Passwords
 128         assertEquals("Matching Passwords", Color.green, password1.getBackground());
 129         assertEquals("Matching Passwords", Color.green, password2.getBackground());







 130 
 131         // Check non-matching passwords
 132         password2.typeText("passwereertegrs");
 133         assertEquals("Non-Matching Passwords", Color.white, password1.getBackground());
 134         assertEquals("Non-Matching Passwords", Color.white, password2.getBackground());







 135     }
 136 
 137 }


   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.textfield.JHistoryTextField;
  25 import com.sun.swingset3.demos.textfield.TextFieldDemo;
  26 import static com.sun.swingset3.demos.textfield.TextFieldDemo.*;
  27 
  28 import java.awt.Color;
  29 import java.awt.Component;
  30 import java.awt.event.KeyEvent;
  31 import java.util.Calendar;
  32 import java.util.Date;
  33 import java.util.Locale;
  34 import javax.swing.JFormattedTextField;
  35 
  36 import static org.jemmy2ext.JemmyExt.*;
  37 

  38 import org.netbeans.jemmy.ClassReference;
  39 import org.netbeans.jemmy.ComponentChooser;
  40 import org.netbeans.jemmy.QueueTool;
  41 import org.netbeans.jemmy.operators.ContainerOperator;
  42 import org.netbeans.jemmy.operators.JButtonOperator;
  43 import org.netbeans.jemmy.operators.JFrameOperator;
  44 import org.netbeans.jemmy.operators.JLabelOperator;
  45 import org.netbeans.jemmy.operators.JPasswordFieldOperator;
  46 import org.netbeans.jemmy.operators.JTextFieldOperator;
  47 
  48 import org.jtregext.GuiTestListener;
  49 
  50 import org.testng.annotations.Listeners;
  51 import org.testng.annotations.Test;
  52 import static org.testng.AssertJUnit.*;
  53 
  54 /*
  55  * @test
  56  * @key headful
  57  * @summary Verifies SwingSet3 TextFieldDemo by entering text in each field and
  58  *          checking that app reacts accordingly.
  59  *
  60  * @library /sanity/client/lib/jemmy/src
  61  * @library /sanity/client/lib/Extensions/src
  62  * @library /sanity/client/lib/SwingSet3/src
  63  * @modules java.desktop
  64  *          java.logging
  65  * @build org.jemmy2ext.JemmyExt
  66  * @build com.sun.swingset3.demos.textfield.TextFieldDemo
  67  * @run testng TextFieldDemoTest
  68  */
  69 @Listeners(GuiTestListener.class)
  70 public class TextFieldDemoTest {
  71 
  72     @Test
  73     public void test() throws Exception {
  74 
  75         new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication();
  76 
  77         JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
  78 
  79         historyTextField(frame);
  80         dateTextField(frame);
  81         passwordField(frame);
  82     }
  83 
  84     private void historyTextField(JFrameOperator jfo) throws Exception {


  87 
  88         jtfo.pressKey(KeyEvent.VK_DOWN);
  89         jtfo.pressKey(KeyEvent.VK_DOWN);
  90         jtfo.pressKey(KeyEvent.VK_ENTER);
  91 
  92         final String expectedValue = "category";
  93         jtfo.waitText(expectedValue);
  94         assertEquals("Select History Item", expectedValue, jtfo.getText());
  95     }
  96 
  97     public void dateTextField(JFrameOperator jfo) throws Exception {
  98         JTextFieldOperator jtfo = new JTextFieldOperator(jfo,
  99                 new ByClassChooser(JFormattedTextField.class));
 100         ContainerOperator<?> containerOperator = new ContainerOperator<>(jtfo.getParent());
 101         JButtonOperator jbo = new JButtonOperator(containerOperator, GO);
 102         JLabelOperator dowLabel = new JLabelOperator(containerOperator);
 103         Calendar calendar = Calendar.getInstance(Locale.ENGLISH);
 104 
 105         // Check default date Day of the Week
 106         jbo.push();
 107         dowLabel.waitText(calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH));


 108 
 109         // Check Custom Day of the Week
 110         calendar.set(2012, 9, 11); // Represents "Oct 11, 2012"
 111         Date date = calendar.getTime();
 112         String dateString = jtfo.getQueueTool().invokeAndWait(
 113                 new QueueTool.QueueAction<String>("Formatting the value using JFormattedTextField formatter") {
 114 
 115             @Override
 116             public String launch() throws Exception {
 117                 return ((JFormattedTextField) jtfo.getSource()).getFormatter().valueToString(date);
 118             }
 119         });
 120         System.out.println("dateString = " + dateString);
 121         jtfo.enterText(dateString);
 122 
 123         jbo.push();
 124         dowLabel.waitText("Thursday");
 125     }
 126 
 127     public void passwordField(JFrameOperator jfo) throws Exception {
 128         JPasswordFieldOperator password1 = new JPasswordFieldOperator(jfo, 0);
 129         JPasswordFieldOperator password2 = new JPasswordFieldOperator(jfo, 1);
 130 
 131         password1.typeText("password");
 132         password2.typeText("password");
 133 
 134         // Check Matching Passwords
 135         password1.waitState(new ComponentChooser() {
 136             public boolean checkComponent(Component comp) {
 137                 return password1.getBackground().equals(Color.green) &&
 138                        password2.getBackground().equals(Color.green);
 139             }
 140             public String getDescription() {
 141                 return "Passwords to match";
 142             }
 143         });
 144 
 145         // Check non-matching passwords
 146         password2.typeText("passwereertegrs");
 147         password1.waitState(new ComponentChooser() {
 148             public boolean checkComponent(Component comp) {
 149                 return password1.getBackground().equals(Color.white) &&
 150                        password2.getBackground().equals(Color.white);
 151             }
 152             public String getDescription() {
 153                 return "Passwords not to match";
 154             }
 155         });
 156     }
 157 
 158 }
< prev index next >