|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
PropertyTagHandler.java | 100% | 100% | 100% | 100% |
|
1 |
/*
|
|
2 |
* Created on Oct 24, 2003
|
|
3 |
*
|
|
4 |
* To change the template for this generated file go to
|
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
6 |
*/
|
|
7 |
package junit.extensions.xml.elements;
|
|
8 |
|
|
9 |
import junit.extensions.xml.IXMLTestCase;
|
|
10 |
import junit.extensions.xml.IXMLTestSuite;
|
|
11 |
import junit.extensions.xml.XMLException;
|
|
12 |
|
|
13 |
import org.w3c.dom.Element;
|
|
14 |
|
|
15 |
|
|
16 |
/**
|
|
17 |
* Create a property by the name given name.
|
|
18 |
*
|
|
19 |
* <H3>Tag Name</H3>
|
|
20 |
* property
|
|
21 |
* <H3>Attributes</H3>
|
|
22 |
* name - name of the property<p>
|
|
23 |
* value - value of the property<p>
|
|
24 |
* <H3>Examples</H3>
|
|
25 |
* Create a property in the current scope.
|
|
26 |
* <pre>
|
|
27 |
* <property name="Myproperty" value="true"/>
|
|
28 |
* </pre>
|
|
29 |
*
|
|
30 |
* Create a property in the parent scope.
|
|
31 |
* <pre>
|
|
32 |
* <property name="../Myproperty" value="true"/>
|
|
33 |
* </pre>
|
|
34 |
* @author JFCUnit contributor
|
|
35 |
*/
|
|
36 |
public class PropertyTagHandler extends AbstractTagHandler { |
|
37 |
/**
|
|
38 |
* Constructor.
|
|
39 |
* @param element Element to be processed by the tag handler.
|
|
40 |
* @param testcase parent test case.
|
|
41 |
*/
|
|
42 | 8 |
public PropertyTagHandler(final Element element, final IXMLTestCase testcase) {
|
43 | 8 |
super(element, testcase);
|
44 |
} |
|
45 |
|
|
46 |
/**
|
|
47 |
* Constructor.
|
|
48 |
* @param element Element to be processed by the tag handler.
|
|
49 |
* @param suite parent test case.
|
|
50 |
*/
|
|
51 | 3 |
public PropertyTagHandler(final Element element, final IXMLTestSuite suite) {
|
52 | 3 |
super(element, suite);
|
53 |
} |
|
54 |
|
|
55 |
/**
|
|
56 |
* Handle the XML processing of the tag 'property'.
|
|
57 |
* @throws XMLException is thrown if the element cannot be understood.
|
|
58 |
*/
|
|
59 | 8 |
public void processElement() throws XMLException { |
60 | 8 |
validateElement(); |
61 |
|
|
62 | 8 |
String name = getString(NAME); |
63 | 8 |
String value = getString(VALUE); |
64 |
|
|
65 | 8 |
if (getXMLTestCase() != null) { |
66 | 7 |
getXMLTestCase().addProperty(name, value); |
67 |
} else {
|
|
68 | 1 |
getXMLTestSuite().addProperty(name, value); |
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
/**
|
|
73 |
* Make sure the appropriate tag and attributes are used.
|
|
74 |
* @throws XMLException when validation fails.
|
|
75 |
*/
|
|
76 | 8 |
public void validateElement() throws XMLException { |
77 | 8 |
super.validateElement();
|
78 |
|
|
79 |
// message is a required attribute
|
|
80 | 8 |
checkRequiredAttribute(NAME); |
81 | 8 |
checkRequiredAttribute(VALUE); |
82 |
} |
|
83 |
} |
|
84 |
|
|