1
|
|
package junit.extensions.xml.elements;
|
2
|
|
|
3
|
|
import java.io.IOException;
|
4
|
|
import java.io.PipedInputStream;
|
5
|
|
import java.io.PipedOutputStream;
|
6
|
|
import java.io.PrintStream;
|
7
|
|
import java.util.List;
|
8
|
|
|
9
|
|
import javax.swing.JButton;
|
10
|
|
import javax.swing.JDialog;
|
11
|
|
|
12
|
|
import org.w3c.dom.Element;
|
13
|
|
import junit.extensions.jfcunit.JFCTestCase;
|
14
|
|
import junit.extensions.jfcunit.JFCTestHelper;
|
15
|
|
import junit.extensions.jfcunit.eventdata.MouseEventData;
|
16
|
|
import junit.extensions.jfcunit.finder.AbstractButtonFinder;
|
17
|
|
import junit.extensions.xml.IXMLTestCase;
|
18
|
|
import junit.extensions.xml.XMLException;
|
19
|
|
import junit.extensions.xml.XMLTagResourceBundle;
|
20
|
|
import junit.extensions.jfcunit.finder.DialogFinder;
|
21
|
|
|
22
|
|
|
23
|
|
|
24
|
|
|
25
|
|
|
26
|
|
|
27
|
|
|
28
|
|
|
29
|
|
|
30
|
|
public class EchoTagHandlerT extends JFCTestCase {
|
31
|
|
|
32
|
|
|
33
|
|
|
34
|
|
|
35
|
|
private EchoTagHandler m_echoTagHandler = null;
|
36
|
|
|
37
|
|
|
38
|
|
|
39
|
|
|
40
|
|
private ElementFixture m_elementFixture;
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
|
private Throwable m_lastException = null;
|
46
|
|
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
|
private volatile boolean m_started = false;
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
private volatile boolean m_normalExit = false;
|
56
|
|
|
57
|
|
|
58
|
|
|
59
|
|
|
60
|
|
|
61
|
10
|
protected void setUp() throws Exception {
|
62
|
10
|
super.setUp();
|
63
|
10
|
m_started = false;
|
64
|
10
|
m_elementFixture = new ElementFixture(this);
|
65
|
10
|
m_elementFixture.setUp();
|
66
|
|
}
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
10
|
protected void tearDown() throws Exception {
|
73
|
10
|
m_echoTagHandler = null;
|
74
|
10
|
m_elementFixture.tearDown();
|
75
|
|
|
76
|
10
|
m_elementFixture = null;
|
77
|
10
|
super.tearDown();
|
78
|
|
}
|
79
|
|
|
80
|
|
|
81
|
|
|
82
|
|
|
83
|
|
|
84
|
|
|
85
|
1
|
public void testStdout() throws XMLException, IOException {
|
86
|
|
|
87
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
88
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
89
|
|
"message", "TEST"
|
90
|
|
});
|
91
|
1
|
m_echoTagHandler = new EchoTagHandler(e, tc);
|
92
|
|
|
93
|
1
|
PrintStream origerr = System.out;
|
94
|
|
|
95
|
1
|
java.io.PipedOutputStream pos = new PipedOutputStream();
|
96
|
1
|
PipedInputStream pis = new PipedInputStream(pos);
|
97
|
1
|
PrintStream ps = new PrintStream(pos);
|
98
|
1
|
System.setOut(ps);
|
99
|
|
|
100
|
1
|
try {
|
101
|
1
|
m_echoTagHandler.processElement();
|
102
|
|
} finally {
|
103
|
1
|
System.out.close();
|
104
|
1
|
System.setOut(origerr);
|
105
|
|
}
|
106
|
1
|
byte[] data = new byte[512];
|
107
|
1
|
int len = pis.read(data);
|
108
|
1
|
String s = new String(data, 0, len);
|
109
|
1
|
assertEquals("[echo] TEST\r\n", s);
|
110
|
|
|
111
|
|
}
|
112
|
|
|
113
|
|
|
114
|
|
|
115
|
|
|
116
|
|
|
117
|
|
|
118
|
1
|
public void testStderr() throws XMLException, IOException {
|
119
|
|
|
120
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
121
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
122
|
|
"message", "TEST",
|
123
|
|
"mode", "stderr"
|
124
|
|
});
|
125
|
1
|
m_echoTagHandler = new EchoTagHandler(e, tc);
|
126
|
|
|
127
|
1
|
PrintStream origerr = System.err;
|
128
|
|
|
129
|
1
|
java.io.PipedOutputStream pos = new PipedOutputStream();
|
130
|
1
|
PipedInputStream pis = new PipedInputStream(pos);
|
131
|
1
|
PrintStream ps = new PrintStream(pos);
|
132
|
1
|
System.setErr(ps);
|
133
|
|
|
134
|
1
|
try {
|
135
|
1
|
m_echoTagHandler.processElement();
|
136
|
|
} finally {
|
137
|
1
|
System.err.close();
|
138
|
1
|
System.setOut(origerr);
|
139
|
|
}
|
140
|
1
|
byte[] data = new byte[512];
|
141
|
1
|
int len = pis.read(data);
|
142
|
1
|
String s = new String(data, 0, len);
|
143
|
1
|
assertEquals("[echo] TEST\r\n", s);
|
144
|
|
}
|
145
|
|
|
146
|
|
|
147
|
|
|
148
|
|
|
149
|
|
|
150
|
1
|
public void testConfirmationTrueBlocking() throws InterruptedException {
|
151
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
152
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
153
|
|
"message", "TEST",
|
154
|
|
"mode", "confirm"
|
155
|
|
});
|
156
|
1
|
m_echoTagHandler = new EchoTagHandler(e, tc);
|
157
|
1
|
setHelper(new JFCTestHelper());
|
158
|
|
|
159
|
|
|
160
|
1
|
m_lastException = null;
|
161
|
1
|
Thread modalThread = new Thread(new Runnable() {
|
162
|
1
|
public void run() {
|
163
|
1
|
try {
|
164
|
1
|
m_lastException = null;
|
165
|
1
|
m_started = true;
|
166
|
1
|
m_echoTagHandler.processElement();
|
167
|
1
|
m_normalExit = true;
|
168
|
|
} catch (Exception e) {
|
169
|
0
|
m_lastException = e;
|
170
|
|
}
|
171
|
|
}
|
172
|
|
}, "ModalThread");
|
173
|
1
|
modalThread.start();
|
174
|
1
|
Thread.currentThread().yield();
|
175
|
|
|
176
|
|
|
177
|
1
|
while (!m_started) {
|
178
|
0
|
Thread.currentThread().yield();
|
179
|
0
|
sleep(500);
|
180
|
|
}
|
181
|
|
|
182
|
|
|
183
|
|
|
184
|
|
|
185
|
|
|
186
|
|
|
187
|
|
|
188
|
1
|
sleep(100);
|
189
|
1
|
for (int i = 0; i < 12; i++) {
|
190
|
12
|
flushAWT();
|
191
|
|
}
|
192
|
|
|
193
|
1
|
DialogFinder finder = new DialogFinder(null);
|
194
|
1
|
finder.setWait(0);
|
195
|
1
|
List l = finder.findAll();
|
196
|
1
|
JDialog dlg = (JDialog) l.get(0);
|
197
|
1
|
JButton btn = (JButton) new AbstractButtonFinder("Yes").find(dlg, 0);
|
198
|
1
|
getHelper().enterClickAndLeave(new MouseEventData(this, btn));
|
199
|
|
|
200
|
1
|
flushAWT();
|
201
|
1
|
assertNull("Exception should not be thrown", m_lastException);
|
202
|
|
}
|
203
|
|
|
204
|
|
|
205
|
|
|
206
|
|
|
207
|
|
|
208
|
1
|
public void testConfirmationFalseBlocking() throws InterruptedException {
|
209
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
210
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
211
|
|
"message", "TEST",
|
212
|
|
"mode", "confirm"
|
213
|
|
});
|
214
|
1
|
m_echoTagHandler = new EchoTagHandler(e, tc);
|
215
|
|
|
216
|
1
|
setHelper(new JFCTestHelper());
|
217
|
|
|
218
|
|
|
219
|
1
|
m_lastException = null;
|
220
|
1
|
Thread modalThread = new Thread(new Runnable() {
|
221
|
1
|
public void run() {
|
222
|
1
|
try {
|
223
|
1
|
m_lastException = null;
|
224
|
1
|
m_started = true;
|
225
|
1
|
m_echoTagHandler.processElement();
|
226
|
0
|
m_normalExit = true;
|
227
|
|
} catch (Throwable e) {
|
228
|
1
|
m_lastException = e;
|
229
|
|
}
|
230
|
|
}
|
231
|
|
}, "ModalThread");
|
232
|
1
|
modalThread.start();
|
233
|
1
|
Thread.currentThread().yield();
|
234
|
|
|
235
|
|
|
236
|
1
|
while (!m_started) {
|
237
|
0
|
Thread.currentThread().sleep(500);
|
238
|
|
}
|
239
|
1
|
flushAWT();
|
240
|
|
|
241
|
|
|
242
|
1
|
Thread.currentThread().sleep(500);
|
243
|
1
|
flushAWT();
|
244
|
|
|
245
|
1
|
DialogFinder finder = new DialogFinder(null);
|
246
|
1
|
finder.setWait(0);
|
247
|
1
|
List l = finder.findAll();
|
248
|
1
|
JDialog dlg = (JDialog) l.get(0);
|
249
|
1
|
JButton btn = (JButton) new AbstractButtonFinder("No").find(dlg, 0);
|
250
|
1
|
getHelper().enterClickAndLeave(new MouseEventData(this, btn));
|
251
|
|
|
252
|
1
|
flushAWT();
|
253
|
1
|
assertNotNull("Exception should be thrown", m_lastException);
|
254
|
|
}
|
255
|
|
|
256
|
|
|
257
|
|
|
258
|
|
|
259
|
|
|
260
|
1
|
public void testConfirmationTrueNonBlocking() throws InterruptedException {
|
261
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
262
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
263
|
|
"message", "TEST",
|
264
|
|
"mode", "confirm",
|
265
|
|
"block", "false"
|
266
|
|
});
|
267
|
1
|
m_echoTagHandler = new EchoTagHandler(e, tc);
|
268
|
|
|
269
|
1
|
setHelper(new JFCTestHelper());
|
270
|
|
|
271
|
|
|
272
|
1
|
m_lastException = null;
|
273
|
1
|
Thread modalThread = new Thread(new Runnable() {
|
274
|
1
|
public void run() {
|
275
|
1
|
try {
|
276
|
1
|
m_lastException = null;
|
277
|
1
|
m_started = true;
|
278
|
1
|
m_echoTagHandler.processElement();
|
279
|
1
|
m_normalExit = true;
|
280
|
|
} catch (Exception e) {
|
281
|
0
|
m_lastException = e;
|
282
|
|
}
|
283
|
|
}
|
284
|
|
}, "ModalThread");
|
285
|
1
|
modalThread.start();
|
286
|
1
|
Thread.currentThread().yield();
|
287
|
|
|
288
|
|
|
289
|
1
|
while (!m_started) {
|
290
|
0
|
Thread.currentThread().sleep(50);
|
291
|
|
}
|
292
|
|
|
293
|
|
|
294
|
1
|
Thread.currentThread().sleep(500);
|
295
|
1
|
flushAWT();
|
296
|
|
|
297
|
1
|
DialogFinder finder = new DialogFinder(null);
|
298
|
1
|
finder.setWait(0);
|
299
|
1
|
List l = finder.findAll();
|
300
|
1
|
JDialog dlg = (JDialog) l.get(0);
|
301
|
1
|
JButton btn = (JButton) new AbstractButtonFinder("Yes").find(dlg, 0);
|
302
|
1
|
getHelper().enterClickAndLeave(new MouseEventData(this, btn));
|
303
|
|
|
304
|
1
|
flushAWT();
|
305
|
1
|
assertNull("Exception should not be thrown", m_lastException);
|
306
|
|
|
307
|
|
}
|
308
|
|
|
309
|
|
|
310
|
|
|
311
|
|
|
312
|
|
|
313
|
1
|
public void testConfirmationFalseNonBlocking() throws InterruptedException {
|
314
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
315
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
316
|
|
"message", "TEST",
|
317
|
|
"mode", "confirm",
|
318
|
|
"block", "false"
|
319
|
|
});
|
320
|
1
|
m_echoTagHandler = new EchoTagHandler(e, tc);
|
321
|
|
|
322
|
1
|
setHelper(new JFCTestHelper());
|
323
|
|
|
324
|
|
|
325
|
1
|
m_lastException = null;
|
326
|
1
|
Thread modalThread = new Thread(new Runnable() {
|
327
|
1
|
public void run() {
|
328
|
1
|
try {
|
329
|
1
|
m_lastException = null;
|
330
|
1
|
m_started = true;
|
331
|
1
|
m_echoTagHandler.processElement();
|
332
|
0
|
m_normalExit = true;
|
333
|
|
} catch (Throwable e) {
|
334
|
1
|
m_lastException = e;
|
335
|
|
}
|
336
|
|
}
|
337
|
|
}, "ModalThread");
|
338
|
1
|
modalThread.start();
|
339
|
1
|
Thread.currentThread().yield();
|
340
|
|
|
341
|
|
|
342
|
1
|
while (!m_started) {
|
343
|
0
|
Thread.currentThread().sleep(50);
|
344
|
|
}
|
345
|
|
|
346
|
|
|
347
|
1
|
Thread.currentThread().sleep(1200);
|
348
|
1
|
flushAWT();
|
349
|
|
|
350
|
1
|
DialogFinder finder = new DialogFinder(null);
|
351
|
1
|
finder.setWait(0);
|
352
|
1
|
List l = finder.findAll();
|
353
|
1
|
JDialog dlg = (JDialog) l.get(0);
|
354
|
1
|
JButton btn = (JButton) new AbstractButtonFinder("No").find(dlg, 0);
|
355
|
1
|
getHelper().enterClickAndLeave(new MouseEventData(this, btn));
|
356
|
|
|
357
|
1
|
modalThread.join();
|
358
|
1
|
assertNotNull("Exception should be thrown", m_lastException);
|
359
|
|
|
360
|
|
}
|
361
|
|
|
362
|
|
|
363
|
|
|
364
|
|
|
365
|
|
|
366
|
1
|
public void testDialogBlocking() throws InterruptedException {
|
367
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
368
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
369
|
|
"message", "TEST",
|
370
|
|
"mode", "dialog"
|
371
|
|
});
|
372
|
1
|
m_echoTagHandler = new EchoTagHandler(e, tc);
|
373
|
|
|
374
|
1
|
setHelper(new JFCTestHelper());
|
375
|
|
|
376
|
|
|
377
|
1
|
m_lastException = null;
|
378
|
1
|
Thread modalThread = new Thread(new Runnable() {
|
379
|
1
|
public void run() {
|
380
|
1
|
try {
|
381
|
1
|
m_lastException = null;
|
382
|
1
|
m_started = true;
|
383
|
1
|
m_echoTagHandler.processElement();
|
384
|
1
|
m_normalExit = true;
|
385
|
|
} catch (Throwable e) {
|
386
|
0
|
m_lastException = e;
|
387
|
|
}
|
388
|
|
}
|
389
|
|
}, "ModalThread");
|
390
|
1
|
modalThread.start();
|
391
|
1
|
Thread.currentThread().yield();
|
392
|
|
|
393
|
|
|
394
|
1
|
while (!m_started) {
|
395
|
0
|
Thread.currentThread().sleep(50);
|
396
|
|
}
|
397
|
|
|
398
|
|
|
399
|
1
|
Thread.currentThread().sleep(500);
|
400
|
1
|
flushAWT();
|
401
|
|
|
402
|
1
|
DialogFinder finder = new DialogFinder(null);
|
403
|
1
|
finder.setWait(0);
|
404
|
1
|
List l = finder.findAll();
|
405
|
|
|
406
|
1
|
JDialog dlg = (JDialog) l.get(0);
|
407
|
1
|
JButton btn = (JButton) new AbstractButtonFinder("OK").find(dlg, 0);
|
408
|
1
|
getHelper().enterClickAndLeave(new MouseEventData(this, btn));
|
409
|
|
|
410
|
1
|
flushAWT();
|
411
|
1
|
assertNull("Exception should not be thrown", m_lastException);
|
412
|
|
|
413
|
|
}
|
414
|
|
|
415
|
|
|
416
|
|
|
417
|
|
|
418
|
|
|
419
|
1
|
public void testDialogNonBlocking() throws InterruptedException {
|
420
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
421
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
422
|
|
"message", "TEST",
|
423
|
|
"mode", "dialog",
|
424
|
|
"block", "false"
|
425
|
|
});
|
426
|
1
|
m_echoTagHandler = new EchoTagHandler(e, tc);
|
427
|
|
|
428
|
1
|
setHelper(new JFCTestHelper());
|
429
|
|
|
430
|
|
|
431
|
1
|
m_lastException = null;
|
432
|
1
|
Thread modalThread = new Thread(new Runnable() {
|
433
|
1
|
public void run() {
|
434
|
1
|
try {
|
435
|
1
|
m_lastException = null;
|
436
|
1
|
m_started = true;
|
437
|
1
|
m_echoTagHandler.processElement();
|
438
|
1
|
m_normalExit = true;
|
439
|
|
} catch (Throwable e) {
|
440
|
0
|
m_lastException = e;
|
441
|
|
}
|
442
|
|
}
|
443
|
|
}, "ModalThread");
|
444
|
1
|
modalThread.start();
|
445
|
1
|
Thread.currentThread().yield();
|
446
|
|
|
447
|
|
|
448
|
1
|
while (!m_started) {
|
449
|
0
|
Thread.currentThread().sleep(50);
|
450
|
|
}
|
451
|
|
|
452
|
|
|
453
|
1
|
Thread.currentThread().sleep(500);
|
454
|
1
|
flushAWT();
|
455
|
|
|
456
|
1
|
DialogFinder finder = new DialogFinder(null);
|
457
|
1
|
finder.setWait(0);
|
458
|
1
|
List l = finder.findAll();
|
459
|
|
|
460
|
1
|
JDialog dlg = (JDialog) l.get(0);
|
461
|
1
|
JButton btn = (JButton) new AbstractButtonFinder("OK").find(dlg, 0);
|
462
|
1
|
getHelper().enterClickAndLeave(new MouseEventData(this, btn));
|
463
|
|
|
464
|
1
|
flushAWT();
|
465
|
1
|
assertNull("Exception should not be thrown", m_lastException);
|
466
|
|
|
467
|
|
}
|
468
|
|
|
469
|
|
|
470
|
|
|
471
|
|
|
472
|
1
|
public void testInvalidMode() {
|
473
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
474
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
475
|
|
"message", "TEST",
|
476
|
|
"mode", "test"
|
477
|
|
});
|
478
|
1
|
m_echoTagHandler = new EchoTagHandler(e, tc);
|
479
|
1
|
XMLException ex = null;
|
480
|
1
|
try {
|
481
|
1
|
m_echoTagHandler.processElement();
|
482
|
|
} catch (XMLException xmle) {
|
483
|
1
|
ex = xmle;
|
484
|
|
}
|
485
|
1
|
assertNotNull("Exception was not thrown", ex);
|
486
|
|
}
|
487
|
|
|
488
|
|
|
489
|
|
|
490
|
|
|
491
|
1
|
public void testLookup() {
|
492
|
1
|
IXMLTestCase tc = m_elementFixture.getTestCase();
|
493
|
1
|
Element e = m_elementFixture.newElement("echo", new String[] {
|
494
|
|
"message", "TEST",
|
495
|
|
"mode", "test"
|
496
|
|
});
|
497
|
1
|
Object o = XMLTagResourceBundle.getTagHandler(e, tc, "echo");
|
498
|
1
|
assertNotNull(o);
|
499
|
|
}
|
500
|
|
}
|
501
|
|
|