|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
EvaluateTagHandler.java | - | 94.7% | 100% | 95.5% |
|
1 |
package junit.extensions.xml.elements;
|
|
2 |
|
|
3 |
import junit.extensions.xml.IXMLTestCase;
|
|
4 |
import junit.extensions.xml.XMLException;
|
|
5 |
|
|
6 |
import junit.framework.Assert;
|
|
7 |
|
|
8 |
import org.w3c.dom.Element;
|
|
9 |
|
|
10 |
import java.lang.reflect.Method;
|
|
11 |
|
|
12 |
|
|
13 |
/**
|
|
14 |
* Provide a mechanism for sending debug messages to the
|
|
15 |
* test case developer.
|
|
16 |
* <H3>Tag Name:</H3>
|
|
17 |
* evaluate
|
|
18 |
* <H3>Attributes:</H3>
|
|
19 |
* id - Id of the result object.
|
|
20 |
* refid - Id of the object to invoke the method.
|
|
21 |
* method - Null parameter method. Ex JComboBox.getSelectedObject();
|
|
22 |
* <H3>Examples:</H3>
|
|
23 |
* <evaluate id="Text" refid="JTextField1" method="getTest"/>
|
|
24 |
* @author Kevin Wilson
|
|
25 |
*/
|
|
26 |
public class EvaluateTagHandler extends AbstractTagHandler { |
|
27 |
/**
|
|
28 |
* Constructor.
|
|
29 |
* @param element Element to be processed by the tag handler.
|
|
30 |
* @param testcase parent test case.
|
|
31 |
*/
|
|
32 | 6 |
public EvaluateTagHandler(final Element element, final IXMLTestCase testcase) {
|
33 | 6 |
super(element, testcase);
|
34 |
} |
|
35 |
|
|
36 |
/**
|
|
37 |
* Handle the XML processing of the tag 'echo'.
|
|
38 |
* @throws XMLException is thrown if the element cannot be understood.
|
|
39 |
*/
|
|
40 | 5 |
public void processElement() throws XMLException { |
41 | 5 |
validateElement(); |
42 |
|
|
43 | 5 |
String id = getString(ID); |
44 | 5 |
String refid = getString(REFID); |
45 | 5 |
String method = getString(METHOD); |
46 |
|
|
47 | 5 |
Object obj = getXMLTestCase().getProperty(refid); |
48 | 5 |
Assert.assertNotNull("Refid not found:" + refid, obj);
|
49 |
|
|
50 | 4 |
try {
|
51 | 4 |
Class clz = obj.getClass(); |
52 | 4 |
Method m = clz.getMethod( |
53 |
method, |
|
54 |
new Class[0]);
|
|
55 | 3 |
Object result = m.invoke( |
56 |
obj, |
|
57 |
new Object[0]);
|
|
58 | 3 |
getXMLTestCase().addProperty(id, result); |
59 |
} catch (XMLException xe) {
|
|
60 | 0 |
throw xe;
|
61 |
} catch (Exception ex) {
|
|
62 | 1 |
throw new XMLException("Could not execute method:" + method, ex, |
63 |
getElement(), |
|
64 |
getXMLTestCase().getPropertyCache()); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
/**
|
|
69 |
* Make sure the appropriate tag and attributes are used.
|
|
70 |
* @throws XMLException when validation fails.
|
|
71 |
*/
|
|
72 | 5 |
public void validateElement() throws XMLException { |
73 | 5 |
super.validateElement();
|
74 |
|
|
75 |
// check the element tag name
|
|
76 | 5 |
checkElementTagName(EVALUATE); |
77 |
|
|
78 |
// message is a required attribute
|
|
79 | 5 |
checkRequiredAttribute(ID); |
80 | 5 |
checkRequiredAttribute(REFID); |
81 | 5 |
checkRequiredAttribute(METHOD); |
82 |
} |
|
83 |
} |
|
84 |
|
|