|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ClickTagHandler.java | 6.2% | 30.3% | 66.7% | 27.3% |
|
1 |
package junit.extensions.jfcunit.eventdata;
|
|
2 |
|
|
3 |
import junit.extensions.jfcunit.JFCTestHelper;
|
|
4 |
import junit.extensions.jfcunit.RobotTestHelper;
|
|
5 |
import junit.extensions.jfcunit.TestHelper;
|
|
6 |
import junit.extensions.jfcunit.xml.JFCXMLConstants;
|
|
7 |
import junit.extensions.jfcunit.xml.JFCXMLTestCase;
|
|
8 |
|
|
9 |
import junit.extensions.xml.IXMLTestCase;
|
|
10 |
import junit.extensions.xml.XMLException;
|
|
11 |
import junit.extensions.xml.XMLTagResourceBundle;
|
|
12 |
import junit.extensions.xml.elements.AbstractTagHandler;
|
|
13 |
|
|
14 |
import org.w3c.dom.Element;
|
|
15 |
|
|
16 |
import java.awt.AWTException;
|
|
17 |
|
|
18 |
|
|
19 |
/**
|
|
20 |
* This class will handle the processing of <click> nodes.
|
|
21 |
*
|
|
22 |
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
|
|
23 |
*/
|
|
24 |
public class ClickTagHandler extends AbstractTagHandler |
|
25 |
implements JFCXMLConstants {
|
|
26 |
/**
|
|
27 |
* Robot test helper used to submit events.
|
|
28 |
*/
|
|
29 |
private static TestHelper s_robotTestHelper; |
|
30 |
|
|
31 |
/**
|
|
32 |
* JFCTEst Helper used to submit events.
|
|
33 |
*/
|
|
34 |
private static TestHelper s_jfcTestHelper; |
|
35 |
|
|
36 |
/**
|
|
37 |
* Constructor for ClickTagHandler.
|
|
38 |
*
|
|
39 |
* @param element The element to be processed.
|
|
40 |
* @param testCase The IXMLTestCase that uses this element.
|
|
41 |
*/
|
|
42 | 408 |
public ClickTagHandler(final Element element, final IXMLTestCase testCase) {
|
43 | 408 |
super(element, testCase);
|
44 |
} |
|
45 |
|
|
46 |
/**
|
|
47 |
* @see junit.extensions.xml.elements.AbstractTagHandler#processElement().
|
|
48 |
*/
|
|
49 | 408 |
public void processElement() throws XMLException { |
50 | 408 |
validateElement(); |
51 |
|
|
52 | 408 |
BaseEventDataTagHandler th = (BaseEventDataTagHandler) XMLTagResourceBundle |
53 |
.getTagHandler( |
|
54 |
getElement(), |
|
55 |
getXMLTestCase(), |
|
56 |
getType()); |
|
57 |
|
|
58 | 408 |
Object robot = getXMLTestCase().getProperty(ROBOT); |
59 |
|
|
60 | 408 |
if (robot == null) { |
61 | 408 |
((JFCXMLTestCase) getTestCase()).getHelper().enterClickAndLeave( |
62 |
th.getEventData()); |
|
63 |
|
|
64 | 408 |
return;
|
65 |
} |
|
66 |
|
|
67 | 0 |
if (robot instanceof String) { |
68 | 0 |
robot = Boolean.valueOf((String) robot); |
69 |
} |
|
70 |
|
|
71 | 0 |
Object sstep = getXMLTestCase().getProperty("step");
|
72 |
|
|
73 | 0 |
int step = -1;
|
74 |
|
|
75 | 0 |
if (sstep instanceof String) { |
76 | 0 |
step = Integer.parseInt((String) sstep); |
77 |
} |
|
78 |
|
|
79 | 0 |
if (((Boolean) robot).equals(Boolean.TRUE)) {
|
80 | 0 |
if (step != -1) {
|
81 | 0 |
getRobotTestHelper().setStep(step); |
82 |
} |
|
83 |
|
|
84 | 0 |
getRobotTestHelper().enterClickAndLeave(th.getEventData()); |
85 |
} else {
|
|
86 | 0 |
if (step != -1) {
|
87 | 0 |
getJFCTestHelper().setStep(step); |
88 |
} |
|
89 |
|
|
90 | 0 |
getJFCTestHelper().enterClickAndLeave(th.getEventData()); |
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
/**
|
|
95 |
* @see junit.extensions.xml.elements.AbstractTagHandler#validateElement().
|
|
96 |
*/
|
|
97 | 408 |
public void validateElement() throws XMLException { |
98 |
// do the default validations from the super class
|
|
99 | 408 |
super.validateElement();
|
100 |
|
|
101 |
// Only one of the following is required.
|
|
102 | 408 |
checkRequiredAttribute(TYPE); |
103 |
} |
|
104 |
|
|
105 |
/**
|
|
106 |
* Returns the value of the TYPE attribute for this element.
|
|
107 |
* @return String The value of the TYPE attribute.
|
|
108 |
*/
|
|
109 | 408 |
protected String getType() {
|
110 | 408 |
return getString(TYPE);
|
111 |
} |
|
112 |
|
|
113 |
/**
|
|
114 |
* Get a JFCTestHelper.
|
|
115 |
* @return jfcTestHelper
|
|
116 |
*/
|
|
117 | 0 |
private TestHelper getJFCTestHelper() {
|
118 | 0 |
if (s_jfcTestHelper == null) { |
119 | 0 |
s_jfcTestHelper = new JFCTestHelper();
|
120 |
} |
|
121 |
|
|
122 | 0 |
return s_jfcTestHelper;
|
123 |
} |
|
124 |
|
|
125 |
/**
|
|
126 |
* Get a RobotTestHelper instance if possible.
|
|
127 |
* @return robot test helper. If the robot test
|
|
128 |
* helper cannot be instanciated then the jfctesthelper is
|
|
129 |
* returned.
|
|
130 |
*/
|
|
131 | 0 |
private TestHelper getRobotTestHelper() {
|
132 | 0 |
if (s_robotTestHelper == null) { |
133 | 0 |
try {
|
134 | 0 |
s_robotTestHelper = new RobotTestHelper();
|
135 |
} catch (AWTException ex) {
|
|
136 | 0 |
ex.printStackTrace(); |
137 | 0 |
System.err.println("Error creating Robot using JFCTestHelper");
|
138 | 0 |
s_robotTestHelper = getJFCTestHelper(); |
139 |
} |
|
140 |
} |
|
141 |
|
|
142 | 0 |
return s_robotTestHelper;
|
143 |
} |
|
144 |
} |
|
145 |
|
|