|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TestTagHandler.java | 100% | 93.3% | 100% | 95.2% |
|
1 |
package junit.extensions.jfcunit.xml;
|
|
2 |
|
|
3 |
import junit.extensions.jfcunit.JFCTestHelper;
|
|
4 |
import junit.extensions.jfcunit.RobotTestHelper;
|
|
5 |
|
|
6 |
import junit.extensions.xml.IXMLTestSuite;
|
|
7 |
import junit.extensions.xml.XMLException;
|
|
8 |
import junit.extensions.xml.XMLUtil;
|
|
9 |
|
|
10 |
import junit.framework.Test;
|
|
11 |
|
|
12 |
import org.w3c.dom.Element;
|
|
13 |
|
|
14 |
import java.awt.AWTException;
|
|
15 |
|
|
16 |
|
|
17 |
/**
|
|
18 |
* This class will handle the processing of <test> nodes.
|
|
19 |
*
|
|
20 |
* <h3>Description</h3>
|
|
21 |
* <p>
|
|
22 |
* This tag handler invokes the test case given.
|
|
23 |
* </p>
|
|
24 |
*
|
|
25 |
* <h3>Attributes</h3>
|
|
26 |
* <table border="1" cellpadding="2" cellspacing="0">
|
|
27 |
* <tr>
|
|
28 |
* <td valign="top"><b>Attribute</b></td>
|
|
29 |
* <td valign="top"><b>Description</b></td>
|
|
30 |
* <td align="center" valign="top"><b>Required</b></td>
|
|
31 |
* <td valign="top"><b>Default</b></td>
|
|
32 |
* <td valign="top"><b>Values</b></td>
|
|
33 |
* </tr>
|
|
34 |
* <tr>
|
|
35 |
* <td valign="top">name</td>
|
|
36 |
* <td valign="top">name of the test case</td>
|
|
37 |
* <td valign="top" align="center">Yes</td>
|
|
38 |
* <td valign="top">N/A</td>
|
|
39 |
* <td valign="top">Alpha Numeric Name</td>
|
|
40 |
* </tr>
|
|
41 |
* <tr>
|
|
42 |
* <td valign="top">robot</td>
|
|
43 |
* <td valign="top">Use a robot or send events directly to AWT Event queue.</td>
|
|
44 |
* <td valign="top" align="center">No</td>
|
|
45 |
* <td valign="top">false</td>
|
|
46 |
* <td valign="top">true if events are to be sent via the Robot</td>
|
|
47 |
* </tr>
|
|
48 |
* <tr>
|
|
49 |
* <td valign="top">assertexit</td>
|
|
50 |
* <td valign="top">
|
|
51 |
* Assert the System.exit() command, ExitException will be thrown
|
|
52 |
* by the security manager and the application will not exit.
|
|
53 |
* </td>
|
|
54 |
* <td valign="top" align="center">No</td>
|
|
55 |
* <td valign="top">false</td>
|
|
56 |
* <td valign="top">true if the system exist should be asserted.</td>
|
|
57 |
* </tr>
|
|
58 |
* </table>
|
|
59 |
* <h3>Example</h3>
|
|
60 |
* <pre>
|
|
61 |
* <test name="Login">
|
|
62 |
* ...
|
|
63 |
* </test>
|
|
64 |
* <test name="Logout" assertexit="true">
|
|
65 |
* ...
|
|
66 |
* </test>
|
|
67 |
* </pre>
|
|
68 |
* <p>
|
|
69 |
* The above runs the defined testcase.
|
|
70 |
* </p>
|
|
71 |
* @author Kevin Wilson
|
|
72 |
*/
|
|
73 |
public class TestTagHandler extends junit.extensions.xml.elements.TestTagHandler |
|
74 |
implements JFCXMLConstants {
|
|
75 |
/**
|
|
76 |
* Constructor for TestTagHandler.
|
|
77 |
*
|
|
78 |
* @param element The element to be processed
|
|
79 |
* @param testSuite The IXMLTestCase that uses this element
|
|
80 |
*/
|
|
81 | 598 |
public TestTagHandler(final Element element, final IXMLTestSuite testSuite) {
|
82 | 598 |
super(element, testSuite);
|
83 |
} |
|
84 |
|
|
85 |
/**
|
|
86 |
* Get the current test as a JFCXMLTestCase.
|
|
87 |
* @return JFCXMLTestCase Test Case.
|
|
88 |
*/
|
|
89 | 598 |
public final JFCXMLTestCase getJFCTest() {
|
90 | 598 |
return (JFCXMLTestCase) m_testCase;
|
91 |
} |
|
92 |
|
|
93 |
/**
|
|
94 |
* @see junit.extensions.xml.elements.AbstractTagHandler#processElement()
|
|
95 |
* @throws XMLException upon validation error.
|
|
96 |
*/
|
|
97 | 598 |
public void processElement() throws XMLException { |
98 | 598 |
validateElement(); |
99 |
|
|
100 |
// for each test, the found objects map on the test case has to be reset
|
|
101 | 598 |
Element element = getElement(); |
102 | 598 |
JFCXMLTestCase tc = getJFCTest(); |
103 |
|
|
104 |
/** @todo: Need to support a helperClass attribute which might use a totally new sub-class of TestHelper...*/
|
|
105 | 598 |
boolean robot = XMLUtil.getBooleanAttributeValue(element, ROBOT);
|
106 |
|
|
107 | 598 |
if (robot) {
|
108 | 9 |
try {
|
109 | 9 |
tc.setHelper(new RobotTestHelper());
|
110 |
} catch (AWTException ex) {
|
|
111 | 0 |
tc.setHelper(new JFCTestHelper());
|
112 |
} |
|
113 |
} else {
|
|
114 | 589 |
tc.setHelper(new JFCTestHelper());
|
115 |
} |
|
116 |
|
|
117 | 598 |
boolean assertExit = XMLUtil.getBooleanAttributeValue(element,
|
118 |
ASSERTEXIT); |
|
119 | 598 |
tc.setAssertExit(assertExit); |
120 | 598 |
super.processElement();
|
121 |
} |
|
122 |
|
|
123 |
/**
|
|
124 |
* Create a JFCXmlTestCase.
|
|
125 |
* @return Test new instance.
|
|
126 |
*/
|
|
127 | 598 |
protected Test createTest() {
|
128 | 598 |
return new JFCXMLTestCase( |
129 |
getName(), |
|
130 |
getElement()); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|