1
|
|
package junit.extensions.xml.elements;
|
2
|
|
|
3
|
|
import java.util.Vector;
|
4
|
|
|
5
|
|
import java.awt.Component;
|
6
|
|
import javax.swing.BoxLayout;
|
7
|
|
import javax.swing.JButton;
|
8
|
|
import javax.swing.JFrame;
|
9
|
|
import javax.swing.JLabel;
|
10
|
|
|
11
|
|
import org.w3c.dom.Element;
|
12
|
|
import junit.extensions.xml.IXMLTestCase;
|
13
|
|
import junit.extensions.xml.XMLException;
|
14
|
|
import junit.framework.TestCase;
|
15
|
|
import junit.extensions.xml.XMLTagResourceBundle;
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
|
23
|
|
|
24
|
|
public class AssertEnabledTagHandlerT
|
25
|
|
extends TestCase {
|
26
|
|
|
27
|
|
|
28
|
|
|
29
|
|
private AssertEnabledTagHandler m_tagHandler = null;
|
30
|
|
|
31
|
|
|
32
|
|
|
33
|
|
|
34
|
|
private ElementFixture m_fixture;
|
35
|
|
|
36
|
|
|
37
|
|
|
38
|
|
|
39
|
|
private JFrame m_frame = null;
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
6
|
protected void setUp() throws Exception {
|
46
|
6
|
super.setUp();
|
47
|
6
|
m_fixture = new ElementFixture(this);
|
48
|
|
|
49
|
6
|
m_fixture.setUp();
|
50
|
|
}
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
6
|
protected void tearDown() throws Exception {
|
57
|
6
|
if (m_frame != null) {
|
58
|
5
|
m_frame.setVisible(false);
|
59
|
5
|
m_frame.dispose();
|
60
|
5
|
m_frame = null;
|
61
|
|
}
|
62
|
6
|
m_tagHandler = null;
|
63
|
6
|
m_fixture.tearDown();
|
64
|
|
|
65
|
6
|
m_fixture = null;
|
66
|
6
|
super.tearDown();
|
67
|
|
}
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
|
|
73
|
1
|
public void testProcessElement() throws XMLException {
|
74
|
|
|
75
|
1
|
Element hasFocus = m_fixture.newElement("assertenabled",
|
76
|
|
new String[] {
|
77
|
|
"refid", "test"
|
78
|
|
});
|
79
|
1
|
IXMLTestCase tc = m_fixture.getTestCase();
|
80
|
1
|
Component comp = getComponent(0);
|
81
|
1
|
tc.addProperty("test", comp);
|
82
|
1
|
m_tagHandler = new AssertEnabledTagHandler(hasFocus, tc);
|
83
|
|
|
84
|
1
|
Throwable ex = null;
|
85
|
1
|
m_tagHandler.processElement();
|
86
|
|
}
|
87
|
|
|
88
|
|
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
1
|
public void testProcessElement1() throws XMLException {
|
93
|
|
|
94
|
1
|
Element hasFocus = m_fixture.newElement("assertenabled",
|
95
|
|
new String[] {
|
96
|
|
"refid", "test"
|
97
|
|
});
|
98
|
1
|
IXMLTestCase tc = m_fixture.getTestCase();
|
99
|
1
|
Component comp = getComponent(1);
|
100
|
1
|
tc.addProperty("test", comp);
|
101
|
1
|
m_tagHandler = new AssertEnabledTagHandler(hasFocus, tc);
|
102
|
1
|
m_tagHandler.processElement();
|
103
|
|
|
104
|
|
}
|
105
|
|
|
106
|
|
|
107
|
|
|
108
|
|
|
109
|
|
|
110
|
1
|
public void testProcessElement2() throws XMLException {
|
111
|
|
|
112
|
1
|
Element hasFocus = m_fixture.newElement("assertenabled",
|
113
|
|
new String[] {
|
114
|
|
"refid", "test"
|
115
|
|
});
|
116
|
1
|
IXMLTestCase tc = m_fixture.getTestCase();
|
117
|
1
|
Component comp = getComponent(2);
|
118
|
1
|
tc.addProperty("test", comp);
|
119
|
1
|
m_tagHandler = new AssertEnabledTagHandler(hasFocus, tc);
|
120
|
1
|
m_tagHandler.processElement();
|
121
|
|
}
|
122
|
|
|
123
|
|
|
124
|
|
|
125
|
|
|
126
|
|
|
127
|
1
|
public void testProcessElement3() throws XMLException {
|
128
|
|
|
129
|
1
|
Element hasFocus = m_fixture.newElement("assertenabled",
|
130
|
|
new String[] {
|
131
|
|
"refid", "test"
|
132
|
|
});
|
133
|
1
|
IXMLTestCase tc = m_fixture.getTestCase();
|
134
|
1
|
Component comp = getComponent(3);
|
135
|
1
|
tc.addProperty("test", comp);
|
136
|
1
|
m_tagHandler = new AssertEnabledTagHandler(hasFocus, tc);
|
137
|
|
|
138
|
1
|
Throwable ex = null;
|
139
|
1
|
try {
|
140
|
1
|
m_tagHandler.processElement();
|
141
|
|
} catch (Throwable e) {
|
142
|
1
|
ex = e;
|
143
|
|
}
|
144
|
1
|
assertNotNull("Throwable expected", ex);
|
145
|
|
}
|
146
|
|
|
147
|
|
|
148
|
|
|
149
|
|
|
150
|
|
|
151
|
1
|
public void testProcessNonComponent() throws XMLException {
|
152
|
|
|
153
|
1
|
Element hasFocus = m_fixture.newElement("assertenabled",
|
154
|
|
new String[] {
|
155
|
|
"refid", "test"
|
156
|
|
});
|
157
|
1
|
IXMLTestCase tc = m_fixture.getTestCase();
|
158
|
1
|
Vector v = new Vector();
|
159
|
1
|
tc.addProperty("test", v);
|
160
|
1
|
m_tagHandler = new AssertEnabledTagHandler(hasFocus, tc);
|
161
|
|
|
162
|
1
|
Throwable ex = null;
|
163
|
1
|
try {
|
164
|
1
|
m_tagHandler.processElement();
|
165
|
|
} catch (Throwable e) {
|
166
|
1
|
ex = e;
|
167
|
|
}
|
168
|
1
|
assertNotNull("Throwable expected", ex);
|
169
|
|
}
|
170
|
|
|
171
|
|
|
172
|
|
|
173
|
1
|
public void testLookup() {
|
174
|
|
|
175
|
1
|
Element hasFocus = m_fixture.newElement("assertenabled",
|
176
|
|
new String[] {
|
177
|
|
"refid", "test"
|
178
|
|
});
|
179
|
1
|
IXMLTestCase tc = m_fixture.getTestCase();
|
180
|
1
|
Component comp = getComponent(1);
|
181
|
1
|
tc.addProperty("test", comp);
|
182
|
1
|
Object x = XMLTagResourceBundle.getTagHandler(hasFocus, tc, "assertenabled");
|
183
|
|
|
184
|
1
|
assertNotNull(x);
|
185
|
|
}
|
186
|
|
|
187
|
|
|
188
|
|
|
189
|
|
|
190
|
|
|
191
|
|
|
192
|
5
|
public Component getComponent(final int comp) {
|
193
|
5
|
int item = comp % 4;
|
194
|
5
|
m_frame = new JFrame();
|
195
|
5
|
m_frame.getContentPane().setLayout(new BoxLayout(m_frame.getContentPane(),
|
196
|
|
BoxLayout.Y_AXIS));
|
197
|
5
|
JLabel label = new JLabel("TEST");
|
198
|
5
|
JButton button1 = new JButton("B1");
|
199
|
5
|
JButton button2 = new JButton("B2");
|
200
|
5
|
m_frame.getContentPane().add(label);
|
201
|
5
|
m_frame.getContentPane().add(button1);
|
202
|
5
|
m_frame.getContentPane().add(button2);
|
203
|
5
|
m_frame.pack();
|
204
|
5
|
m_frame.show();
|
205
|
5
|
button2.setEnabled(false);
|
206
|
5
|
try {
|
207
|
5
|
Thread.sleep(1000);
|
208
|
|
} catch (InterruptedException ex) {
|
209
|
|
}
|
210
|
5
|
switch (item) {
|
211
|
2
|
case 1:
|
212
|
2
|
return label;
|
213
|
1
|
case 2:
|
214
|
1
|
return button1;
|
215
|
1
|
case 3:
|
216
|
1
|
return button2;
|
217
|
1
|
default:
|
218
|
1
|
return m_frame;
|
219
|
|
}
|
220
|
|
}
|
221
|
|
|
222
|
|
}
|
223
|
|
|