|
1
|
|
package abbot.editor.editors;
|
|
2
|
|
|
|
3
|
|
import java.util.ArrayList;
|
|
4
|
|
|
|
5
|
|
import java.awt.Component;
|
|
6
|
|
import java.awt.Frame;
|
|
7
|
|
import java.awt.event.KeyEvent;
|
|
8
|
|
import javax.swing.*;
|
|
9
|
|
|
|
10
|
|
import junit.extensions.abbot.*;
|
|
11
|
|
import abbot.finder.matchers.*;
|
|
12
|
|
import abbot.script.*;
|
|
13
|
|
import abbot.tester.*;
|
|
14
|
|
|
|
15
|
|
|
|
16
|
|
|
|
17
|
|
public class AssertEditorTest
|
|
18
|
|
extends ComponentTestFixture implements XMLConstants {
|
|
19
|
|
|
|
20
|
|
private Assert step;
|
|
21
|
|
private AssertEditor editor;
|
|
22
|
|
private JComponentTester tester;
|
|
23
|
|
|
|
24
|
5
|
public void setUp() {
|
|
25
|
5
|
step = new Assert(getResolver(), getName(),
|
|
26
|
|
ComponentTester.class.getName(),
|
|
27
|
|
"assertFrameShowing", new String[0],
|
|
28
|
|
"true", false);
|
|
29
|
5
|
editor = new AssertEditor(step);
|
|
30
|
5
|
tester = new JComponentTester();
|
|
31
|
|
}
|
|
32
|
|
|
|
33
|
1
|
public void testWaitOptions() throws Exception {
|
|
34
|
1
|
showFrame(editor);
|
|
35
|
1
|
JCheckBox waitBox = (JCheckBox)getFinder().
|
|
36
|
|
find(editor, new NameMatcher(TAG_WAIT));
|
|
37
|
|
|
|
38
|
1
|
int count = editor.getComponentCount();
|
|
39
|
1
|
tester.actionClick(waitBox);
|
|
40
|
1
|
assertTrue("No components were added",
|
|
41
|
|
count < editor.getComponentCount());
|
|
42
|
|
|
|
43
|
1
|
tester.actionClick(waitBox);
|
|
44
|
1
|
assertEquals("Wait option components not properly removed",
|
|
45
|
|
count, editor.getComponentCount());
|
|
46
|
|
}
|
|
47
|
|
|
|
48
|
1
|
public void testClearTimeout() throws Exception {
|
|
49
|
|
|
|
50
|
|
|
|
51
|
1
|
showFrame(editor);
|
|
52
|
1
|
JCheckBox wait = (JCheckBox)getFinder().
|
|
53
|
|
find(editor, new NameMatcher(TAG_WAIT));
|
|
54
|
1
|
tester.actionClick(wait);
|
|
55
|
|
|
|
56
|
1
|
JTextField timeout = (JTextField)getFinder().
|
|
57
|
|
find(editor, new NameMatcher(TAG_TIMEOUT));
|
|
58
|
1
|
tester.actionActionMap(timeout, "select-all");
|
|
59
|
1
|
tester.actionKeyStroke(timeout, KeyEvent.VK_DELETE);
|
|
60
|
1
|
tester.waitForIdle();
|
|
61
|
1
|
assertEquals("Text field should be empty on delete contents",
|
|
62
|
|
"", timeout.getText());
|
|
63
|
1
|
tester.actionKeyStroke(timeout, KeyEvent.VK_ENTER);
|
|
64
|
1
|
assertEquals("Text field should hold default value after Enter",
|
|
65
|
|
String.valueOf(step.getTimeout()), timeout.getText());
|
|
66
|
|
}
|
|
67
|
|
|
|
68
|
|
|
|
69
|
1
|
public void testTesterMethodList() throws Throwable {
|
|
70
|
1
|
showFrame(editor);
|
|
71
|
|
|
|
72
|
1
|
JComboBox cb = editor.method;
|
|
73
|
1
|
String[] expected = {
|
|
74
|
|
"assertComponentShowing",
|
|
75
|
|
"assertFrameShowing",
|
|
76
|
|
"assertImage",
|
|
77
|
|
};
|
|
78
|
1
|
assertTrue("Too few methods in combo box: " + cb.getItemCount(),
|
|
79
|
|
cb.getItemCount() >= expected.length);
|
|
80
|
1
|
for (int i=0;i < cb.getItemCount();i++) {
|
|
81
|
3
|
assertTrue("Too many combo box items (next is "
|
|
82
|
|
+ cb.getItemAt(i) + ")", i < expected.length);
|
|
83
|
3
|
assertEquals("Wrong method in combo list",
|
|
84
|
|
expected[i], cb.getItemAt(i));
|
|
85
|
|
}
|
|
86
|
1
|
assertEquals("Wrong number of combo box items",
|
|
87
|
|
expected.length, cb.getItemCount());
|
|
88
|
|
}
|
|
89
|
|
|
|
90
|
1
|
public void testComponentMethodList() throws Throwable {
|
|
91
|
1
|
JComboBox methodChooser = (JComboBox)getFinder().
|
|
92
|
|
find(editor, new NameMatcher(TAG_METHOD));
|
|
93
|
|
|
|
94
|
1
|
showFrame(editor);
|
|
95
|
|
|
|
96
|
1
|
ComponentReference cr = step.getResolver().addComponent(methodChooser);
|
|
97
|
|
|
|
98
|
1
|
JComboBoxTester tester = new JComboBoxTester();
|
|
99
|
1
|
JComboBox refChooser = (JComboBox)getFinder().
|
|
100
|
|
find(editor, new NameMatcher(TAG_COMPONENT));
|
|
101
|
|
|
|
102
|
|
|
|
103
|
1
|
tester.actionSelectItem(refChooser, cr.getID());
|
|
104
|
1
|
tester.actionSelectItem(methodChooser, "getItemCount");
|
|
105
|
1
|
assertEquals("Wrong method selected",
|
|
106
|
|
"getItemCount", editor.method.getSelectedItem());
|
|
107
|
|
|
|
108
|
1
|
ArrayList list = new ArrayList();
|
|
109
|
1
|
for (int i=0;i < methodChooser.getItemCount();i++) {
|
|
110
|
115
|
list.add(methodChooser.getItemAt(i));
|
|
111
|
|
}
|
|
112
|
1
|
assertEquals("Wrong target class",
|
|
113
|
|
JComboBox.class, step.getTargetClass());
|
|
114
|
1
|
assertTrue("No items in the list", methodChooser.getItemCount() > 0);
|
|
115
|
1
|
String[] expected = {
|
|
116
|
|
"getParent",
|
|
117
|
|
"isOpaque",
|
|
118
|
|
"hasFocus",
|
|
119
|
|
|
|
120
|
|
"getContents",
|
|
121
|
|
};
|
|
122
|
1
|
for (int i=0;i < expected.length;i++) {
|
|
123
|
4
|
assertTrue(expected[i] + " method missing",
|
|
124
|
|
list.contains(expected[i]));
|
|
125
|
|
}
|
|
126
|
|
}
|
|
127
|
|
|
|
128
|
1
|
public void testSwitchFromTesterToComponentMethod() throws Exception {
|
|
129
|
1
|
JPanel panel = new JPanel();
|
|
130
|
1
|
JTabbedPane tabs = new JTabbedPane();
|
|
131
|
1
|
panel.add(tabs);
|
|
132
|
1
|
Frame f = showFrame(panel);
|
|
133
|
1
|
ComponentReference cr = step.getResolver().addComponent(tabs);
|
|
134
|
|
|
|
135
|
1
|
step = new Assert(getResolver(), getName(),
|
|
136
|
|
JTabbedPaneTester.class.getName(),
|
|
137
|
|
"getTabs", new String[] { cr.getID() },
|
|
138
|
|
"[one,two,three]", false);
|
|
139
|
1
|
editor = new AssertEditor(step);
|
|
140
|
1
|
panel.add(editor);
|
|
141
|
1
|
panel.revalidate();
|
|
142
|
1
|
panel.repaint();
|
|
143
|
1
|
f.setSize(f.getPreferredSize());
|
|
144
|
1
|
tester.actionWaitForIdle();
|
|
145
|
|
|
|
146
|
1
|
JComboBox methodChooser = (JComboBox)getFinder().
|
|
147
|
|
find(editor, new NameMatcher(TAG_METHOD));
|
|
148
|
|
|
|
149
|
1
|
JComboBoxTester tester = new JComboBoxTester();
|
|
150
|
|
|
|
151
|
1
|
tester.actionSelectItem(methodChooser, "getToolkit");
|
|
152
|
1
|
assertEquals("Wrong method selected",
|
|
153
|
|
"getToolkit", editor.method.getSelectedItem());
|
|
154
|
|
}
|
|
155
|
|
|
|
156
|
|
|
|
157
|
5
|
public AssertEditorTest(String name) {
|
|
158
|
5
|
super(name);
|
|
159
|
|
}
|
|
160
|
|
|
|
161
|
|
|
|
162
|
0
|
public static void main(String[] args) {
|
|
163
|
0
|
TestHelper.runTests(args, AssertEditorTest.class);
|
|
164
|
|
}
|
|
165
|
|
}
|
|
166
|
|
|