|
1
|
|
package abbot.editor.editors;
|
|
2
|
|
|
|
3
|
|
import java.awt.event.*;
|
|
4
|
|
import javax.swing.*;
|
|
5
|
|
|
|
6
|
|
import junit.extensions.abbot.*;
|
|
7
|
|
import abbot.Log;
|
|
8
|
|
import abbot.finder.matchers.*;
|
|
9
|
|
import abbot.script.*;
|
|
10
|
|
import abbot.tester.*;
|
|
11
|
|
|
|
12
|
|
|
|
13
|
|
|
|
14
|
|
public class StepEditorTest extends ComponentTestFixture {
|
|
15
|
|
|
|
16
|
|
private Step step;
|
|
17
|
|
private DefaultStepEditor editor;
|
|
18
|
|
private String description = "default value";
|
|
19
|
|
private JTextComponentTester tester = new JTextComponentTester();
|
|
20
|
|
private JTextField textField;
|
|
21
|
|
|
|
22
|
|
private class DefaultStepEditor extends StepEditor {
|
|
23
|
|
JTextField text;
|
|
24
|
5
|
public DefaultStepEditor(Step s) {
|
|
25
|
5
|
super(s);
|
|
26
|
5
|
text = addTextField("dummy field", "empty");
|
|
27
|
|
}
|
|
28
|
43
|
public void actionPerformed(ActionEvent e) {
|
|
29
|
43
|
if (e.getSource() == text) {
|
|
30
|
6
|
StepEditorTest.this.description = text.getText();
|
|
31
|
|
|
|
32
|
6
|
fireStepChanged();
|
|
33
|
|
}
|
|
34
|
|
else {
|
|
35
|
37
|
super.actionPerformed(e);
|
|
36
|
|
}
|
|
37
|
|
}
|
|
38
|
1
|
public void descriptionChanged() {
|
|
39
|
1
|
fireStepChanged();
|
|
40
|
|
}
|
|
41
|
|
}
|
|
42
|
|
|
|
43
|
5
|
protected void setUp() throws Exception {
|
|
44
|
5
|
step = new Step(getResolver(), (String)null) {
|
|
45
|
54
|
public String getDefaultDescription() {
|
|
46
|
54
|
return description;
|
|
47
|
|
}
|
|
48
|
5
|
public String getUsage() { return null; }
|
|
49
|
5
|
public String getXMLTag() { return "step"; }
|
|
50
|
0
|
public void runStep() { }
|
|
51
|
|
};
|
|
52
|
5
|
editor = new DefaultStepEditor(step);
|
|
53
|
5
|
textField = (JTextField)getFinder().
|
|
54
|
|
find(editor, new ClassMatcher(JTextField.class));
|
|
55
|
|
}
|
|
56
|
|
|
|
57
|
1
|
public void testInit() {
|
|
58
|
1
|
showFrame(editor);
|
|
59
|
1
|
assertEquals("Step should match text field",
|
|
60
|
|
step.getDescription(), textField.getText());
|
|
61
|
|
}
|
|
62
|
|
|
|
63
|
1
|
public void testRevertDescription() {
|
|
64
|
1
|
showFrame(editor);
|
|
65
|
1
|
textField.setText("");
|
|
66
|
1
|
String text = step.getDescription();
|
|
67
|
1
|
tester.actionEnterText(textField, "dummy");
|
|
68
|
1
|
tester.actionKeyStroke(textField, KeyEvent.VK_ESCAPE);
|
|
69
|
1
|
assertEquals("Text not reverted", text, textField.getText());
|
|
70
|
1
|
assertEquals("Description not reverted", text, step.getDescription());
|
|
71
|
|
}
|
|
72
|
|
|
|
73
|
1
|
public void testSetDescription() {
|
|
74
|
1
|
showFrame(editor);
|
|
75
|
1
|
assertEquals("Wrong initial description",
|
|
76
|
|
description, textField.getText());
|
|
77
|
1
|
textField.setText("");
|
|
78
|
1
|
tester.actionEnterText(textField, "hello");
|
|
79
|
1
|
assertEquals("Text entry did not change step data",
|
|
80
|
|
"hello", step.getDescription());
|
|
81
|
|
|
|
82
|
|
|
|
83
|
1
|
description = "default";
|
|
84
|
1
|
textField.setText("");
|
|
85
|
1
|
tester.actionKeyStroke(textField, KeyEvent.VK_ENTER);
|
|
86
|
1
|
assertEquals("Step should revert to default when cleared",
|
|
87
|
|
description, step.getDescription());
|
|
88
|
1
|
assertEquals("Text field should revert to default when cleared",
|
|
89
|
|
description, textField.getText());
|
|
90
|
|
|
|
91
|
|
|
|
92
|
1
|
tester.actionSetCaretPosition(textField, textField.getText().length());
|
|
93
|
1
|
tester.actionKeyStroke(textField, KeyEvent.VK_BACK_SPACE);
|
|
94
|
1
|
assertEquals("Step should be properly edited",
|
|
95
|
|
description.substring(0, description.length()-1),
|
|
96
|
|
textField.getText());
|
|
97
|
|
}
|
|
98
|
|
|
|
99
|
1
|
public void testClearDescription() {
|
|
100
|
|
|
|
101
|
1
|
showFrame(editor);
|
|
102
|
1
|
tester.actionSelectText(textField,
|
|
103
|
|
0, step.getDescription().length());
|
|
104
|
1
|
tester.actionKeyStroke(textField, KeyEvent.VK_BACK_SPACE);
|
|
105
|
1
|
tester.actionKeyStroke(textField, KeyEvent.VK_ENTER);
|
|
106
|
1
|
assertEquals("Step should revert to default description",
|
|
107
|
|
step.getDefaultDescription(), step.getDescription());
|
|
108
|
1
|
assertEquals("Text field should revert to default description",
|
|
109
|
|
step.getDefaultDescription(),
|
|
110
|
|
textField.getText());
|
|
111
|
|
}
|
|
112
|
|
|
|
113
|
1
|
public void testUpdateDefaultDescription() throws Throwable {
|
|
114
|
1
|
showFrame(editor);
|
|
115
|
|
|
|
116
|
1
|
description = "something else";
|
|
117
|
1
|
editor.descriptionChanged();
|
|
118
|
1
|
assertEquals("Editor didn't pick up underlying data change",
|
|
119
|
|
description, textField.getText());
|
|
120
|
|
|
|
121
|
|
|
|
122
|
|
|
|
123
|
1
|
tester.actionKeyString(editor.text, "hello");
|
|
124
|
1
|
assertEquals("Description didn't change in response to step data",
|
|
125
|
|
description, textField.getText());
|
|
126
|
|
|
|
127
|
1
|
textField.setText("");
|
|
128
|
1
|
tester.actionKeyStroke(editor.text, KeyEvent.VK_ENTER);
|
|
129
|
1
|
assertEquals("Description should revert to default when removed",
|
|
130
|
|
description, textField.getText());
|
|
131
|
|
}
|
|
132
|
|
|
|
133
|
|
|
|
134
|
5
|
public StepEditorTest(String name) {
|
|
135
|
5
|
super(name);
|
|
136
|
|
}
|
|
137
|
|
|
|
138
|
|
|
|
139
|
0
|
public static void main(String[] args) {
|
|
140
|
0
|
TestHelper.runTests(args, StepEditorTest.class);
|
|
141
|
|
}
|
|
142
|
|
}
|
|
143
|
|
|