author | ascarpino |
Wed, 26 Apr 2017 10:34:32 -0700 | |
changeset 45988 | 6b7aa871e786 |
parent 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 |
||
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.*; |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
27 |
|
36744 | 28 |
import java.awt.Color; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
29 |
import java.awt.Component; |
36744 | 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; |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
35 |
|
36744 | 36 |
import static org.jemmy2ext.JemmyExt.*; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
37 |
|
36744 | 38 |
import org.netbeans.jemmy.ClassReference; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
39 |
import org.netbeans.jemmy.ComponentChooser; |
36744 | 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; |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
47 |
|
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
48 |
import org.jtregext.GuiTestListener; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
49 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
50 |
import org.testng.annotations.Listeners; |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
51 |
import org.testng.annotations.Test; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
52 |
import static org.testng.AssertJUnit.*; |
36744 | 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 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
61 |
* @library /sanity/client/lib/Extensions/src |
36744 | 62 |
* @library /sanity/client/lib/SwingSet3/src |
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
63 |
* @modules java.desktop |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
64 |
* java.logging |
36744 | 65 |
* @build org.jemmy2ext.JemmyExt |
66 |
* @build com.sun.swingset3.demos.textfield.TextFieldDemo |
|
67 |
* @run testng TextFieldDemoTest |
|
68 |
*/ |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
69 |
@Listeners(GuiTestListener.class) |
36744 | 70 |
public class TextFieldDemoTest { |
71 |
||
72 |
@Test |
|
73 |
public void test() throws Exception { |
|
74 |
||
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
75 |
new ClassReference(TextFieldDemo.class.getCanonicalName()).startApplication(); |
36744 | 76 |
|
37677
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
77 |
JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
78 |
|
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
79 |
historyTextField(frame); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
80 |
dateTextField(frame); |
9774eca96b01
8154381: SwingSet tests are not auto closed in jtreg
mrkam
parents:
36744
diff
changeset
|
81 |
passwordField(frame); |
36744 | 82 |
} |
83 |
||
84 |
private void historyTextField(JFrameOperator jfo) throws Exception { |
|
85 |
JTextFieldOperator jtfo = new JTextFieldOperator(jfo, new ByClassChooser(JHistoryTextField.class)); |
|
86 |
jtfo.typeText("cat"); |
|
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(); |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
107 |
dowLabel.waitText(calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH)); |
36744 | 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(); |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
124 |
dowLabel.waitText("Thursday"); |
36744 | 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 |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
135 |
password1.waitState(new ComponentChooser() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
136 |
public boolean checkComponent(Component comp) { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
137 |
return password1.getBackground().equals(Color.green) && |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
138 |
password2.getBackground().equals(Color.green); |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
139 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
140 |
public String getDescription() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
141 |
return "Passwords to match"; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
142 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
143 |
}); |
36744 | 144 |
|
145 |
// Check non-matching passwords |
|
146 |
password2.typeText("passwereertegrs"); |
|
39006
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
147 |
password1.waitState(new ComponentChooser() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
148 |
public boolean checkComponent(Component comp) { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
149 |
return password1.getBackground().equals(Color.white) && |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
150 |
password2.getBackground().equals(Color.white); |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
151 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
152 |
public String getDescription() { |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
153 |
return "Passwords not to match"; |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
154 |
} |
fd8c3312d043
8157339: Further stabilization for the SwingSet client sanity tests
prr
parents:
37677
diff
changeset
|
155 |
}); |
36744 | 156 |
} |
157 |
||
158 |
} |