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 * @build org.jemmy2ext.JemmyExt 65 * @build com.sun.swingset3.demos.textfield.TextFieldDemo 66 * @run testng TextFieldDemoTest 67 */ 68 @Listeners(GuiTestListener.class) 69 public class TextFieldDemoTest { 70 71 @Test 72 public void test() throws Exception { 73 74 new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication(); 75 76 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); 77 78 historyTextField(frame); 79 dateTextField(frame); 80 passwordField(frame); 81 } 82 83 private void historyTextField(JFrameOperator jfo) throws Exception { 86 87 jtfo.pressKey(KeyEvent.VK_DOWN); 88 jtfo.pressKey(KeyEvent.VK_DOWN); 89 jtfo.pressKey(KeyEvent.VK_ENTER); 90 91 final String expectedValue = "category"; 92 jtfo.waitText(expectedValue); 93 assertEquals("Select History Item", expectedValue, jtfo.getText()); 94 } 95 96 public void dateTextField(JFrameOperator jfo) throws Exception { 97 JTextFieldOperator jtfo = new JTextFieldOperator(jfo, 98 new ByClassChooser(JFormattedTextField.class)); 99 ContainerOperator<?> containerOperator = new ContainerOperator<>(jtfo.getParent()); 100 JButtonOperator jbo = new JButtonOperator(containerOperator, GO); 101 JLabelOperator dowLabel = new JLabelOperator(containerOperator); 102 Calendar calendar = Calendar.getInstance(Locale.ENGLISH); 103 104 // Check default date Day of the Week 105 jbo.push(); 106 dowLabel.waitText(calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH)); 107 108 // Check Custom Day of the Week 109 calendar.set(2012, 9, 11); // Represents "Oct 11, 2012" 110 Date date = calendar.getTime(); 111 String dateString = jtfo.getQueueTool().invokeAndWait( 112 new QueueTool.QueueAction<String>("Formatting the value using JFormattedTextField formatter") { 113 114 @Override 115 public String launch() throws Exception { 116 return ((JFormattedTextField) jtfo.getSource()).getFormatter().valueToString(date); 117 } 118 }); 119 System.out.println("dateString = " + dateString); 120 jtfo.enterText(dateString); 121 122 jbo.push(); 123 dowLabel.waitText("Thursday"); 124 } 125 126 public void passwordField(JFrameOperator jfo) throws Exception { 127 JPasswordFieldOperator password1 = new JPasswordFieldOperator(jfo, 0); 128 JPasswordFieldOperator password2 = new JPasswordFieldOperator(jfo, 1); 129 130 password1.typeText("password"); 131 password2.typeText("password"); 132 133 // Check Matching Passwords 134 password1.waitState(new ComponentChooser() { 135 public boolean checkComponent(Component comp) { 136 return password1.getBackground().equals(Color.green) && 137 password2.getBackground().equals(Color.green); 138 } 139 public String getDescription() { 140 return "Passwords to match"; 141 } 142 }); 143 144 // Check non-matching passwords 145 password2.typeText("passwereertegrs"); 146 password1.waitState(new ComponentChooser() { 147 public boolean checkComponent(Component comp) { 148 return password1.getBackground().equals(Color.white) && 149 password2.getBackground().equals(Color.white); 150 } 151 public String getDescription() { 152 return "Passwords not to match"; 153 } 154 }); 155 } 156 157 } |