author | mrkam |
Wed, 27 Apr 2016 17:47:17 -0700 | |
changeset 37677 | 9774eca96b01 |
parent 36744 | a00905527ec2 |
child 39006 | fd8c3312d043 |
permissions | -rw-r--r-- |
36744 | 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 |
||
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
24 |
import org.jtregext.GuiTestListener; |
36744 | 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; |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
45 |
import org.testng.annotations.Listeners; |
36744 | 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 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
54 |
* @library /sanity/client/lib/Extensions/src |
36744 | 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 |
*/ |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
60 |
@Listeners(GuiTestListener.class) |
36744 | 61 |
public class TextFieldDemoTest { |
62 |
||
63 |
@Test |
|
64 |
public void test() throws Exception { |
|
65 |
||
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
66 |
new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication(); |
36744 | 67 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
68 |
JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
69 |
|
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
70 |
historyTextField(frame); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
71 |
dateTextField(frame); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
72 |
passwordField(frame); |
36744 | 73 |
} |
74 |
||
75 |
private void historyTextField(JFrameOperator jfo) throws Exception { |
|
76 |
JTextFieldOperator jtfo = new JTextFieldOperator(jfo, new ByClassChooser(JHistoryTextField.class)); |
|
77 |
jtfo.typeText("cat"); |
|
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 |
} |