|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AWTEventQueueTagHandler.java | 42.9% | 56.5% | 75% | 53.7% |
|
||||||||||||||
| 1 |
package junit.extensions.jfcunit.xml;
|
|
| 2 |
|
|
| 3 |
import junit.extensions.jfcunit.JFCTestCase;
|
|
| 4 |
|
|
| 5 |
import junit.extensions.xml.IXMLTestCase;
|
|
| 6 |
import junit.extensions.xml.XMLException;
|
|
| 7 |
import junit.extensions.xml.elements.AbstractTagHandler;
|
|
| 8 |
|
|
| 9 |
import org.w3c.dom.Element;
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
/**
|
|
| 13 |
* This class controls the AWTEventQueue. The queue may be
|
|
| 14 |
* paused, resumed or flushed.
|
|
| 15 |
*
|
|
| 16 |
* <H3>Tag Name</H3>
|
|
| 17 |
* awteventqueue
|
|
| 18 |
*
|
|
| 19 |
* <H3>Required Attributes</H3>
|
|
| 20 |
* <pre>
|
|
| 21 |
* action - pause|resume|flush
|
|
| 22 |
* pause is used to suspend the AWT Event queue
|
|
| 23 |
* to allow for the processing of GUI components.
|
|
| 24 |
* resume action should be used after a pause. To
|
|
| 25 |
* allow the AWTEventQueue to continue processing.
|
|
| 26 |
* flush action will insure that each of the current
|
|
| 27 |
* events on the event queue are processed.
|
|
| 28 |
*
|
|
| 29 |
* </pre>
|
|
| 30 |
* <H3>Examples</H3>
|
|
| 31 |
* Pause the queue.
|
|
| 32 |
* <pre>
|
|
| 33 |
* <awteventqueue action="pause"/>
|
|
| 34 |
* </pre>
|
|
| 35 |
* Resume the queue.
|
|
| 36 |
* <pre>
|
|
| 37 |
* <awteventqueue action="resume"/>
|
|
| 38 |
* </pre>
|
|
| 39 |
* Flush the queue.
|
|
| 40 |
* <pre>
|
|
| 41 |
* <awteventqueue action="flush"/>
|
|
| 42 |
* </pre>
|
|
| 43 |
*
|
|
| 44 |
* @author <a href="mailto:kwilson227@users.sourceforge.net">Kevin L Wilson</a>
|
|
| 45 |
*/
|
|
| 46 |
public class AWTEventQueueTagHandler extends AbstractTagHandler |
|
| 47 |
implements JFCXMLConstants {
|
|
| 48 |
/**
|
|
| 49 |
* Constructor for AWTThreadTagHandler.
|
|
| 50 |
*
|
|
| 51 |
* @param element The element to be processed
|
|
| 52 |
* @param testCase The IXMLTestCase that uses this element
|
|
| 53 |
*/
|
|
| 54 | 4 |
public AWTEventQueueTagHandler(final Element element,
|
| 55 |
final IXMLTestCase testCase) {
|
|
| 56 | 4 |
super(element, testCase);
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
/**
|
|
| 60 |
* @see junit.extensions.xml.elements.AbstractTagHandler#processElement()
|
|
| 61 |
*/
|
|
| 62 | 3 |
public void processElement() throws XMLException { |
| 63 | 3 |
validateElement(); |
| 64 |
|
|
| 65 | 3 |
String action = getString(ACTION); |
| 66 |
|
|
| 67 | 3 |
if (FLUSH.equals(action)) {
|
| 68 | 1 |
((JFCTestCase) getTestCase()).flushAWT(); |
| 69 | 2 |
} else if (PAUSE.equals(action)) { |
| 70 | 1 |
((JFCTestCase) getTestCase()).pauseAWT(); |
| 71 | 1 |
} else if (RESUME.equals(action)) { |
| 72 | 1 |
((JFCTestCase) getTestCase()).resumeAWT(); |
| 73 | 0 |
} else if (SLEEP.equals(action)) { |
| 74 | 0 |
long sleep = getSleepTime();
|
| 75 |
|
|
| 76 | 0 |
if (sleep > 0) {
|
| 77 | 0 |
((JFCTestCase) getTestCase()).sleep(sleep); |
| 78 |
} else {
|
|
| 79 | 0 |
for (;;) {
|
| 80 | 0 |
((JFCTestCase) getTestCase()).sleep(10000); |
| 81 |
} |
|
| 82 |
} |
|
| 83 |
} |
|
| 84 |
} |
|
| 85 |
|
|
| 86 |
/**
|
|
| 87 |
* @see junit.extensions.xml.elements.AbstractTagHandler#validateElement()
|
|
| 88 |
*/
|
|
| 89 | 3 |
public void validateElement() throws XMLException { |
| 90 |
// do the default validations from the super class
|
|
| 91 | 3 |
super.validateElement();
|
| 92 |
|
|
| 93 |
// check the element tag name
|
|
| 94 | 3 |
checkElementTagName(AWTTHREAD); |
| 95 |
|
|
| 96 |
// reqd attribute: action
|
|
| 97 | 3 |
checkRequiredAttribute(ACTION); |
| 98 |
|
|
| 99 | 3 |
if (SLEEP.equals(getString(ACTION))) {
|
| 100 | 0 |
checkRequiredAttribute(DURATION); |
| 101 |
} |
|
| 102 |
} |
|
| 103 |
|
|
| 104 |
/**
|
|
| 105 |
* Returns the value of the SLEEPTIME attribute for this element, DEFAULT_SLEEPTIME if nothing
|
|
| 106 |
* was specified.
|
|
| 107 |
* @return long The sleepTime for this element.
|
|
| 108 |
*/
|
|
| 109 | 0 |
protected long getSleepTime() { |
| 110 | 0 |
if ("forever".equals(getString(DURATION))) { |
| 111 | 0 |
return -1;
|
| 112 |
} |
|
| 113 |
|
|
| 114 | 0 |
return getLong(DURATION, DEFAULT_SLEEPTIME);
|
| 115 |
} |
|
| 116 |
} |
|
| 117 |
|
|
||||||||||