|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AssertEnabledTagHandler.java | 100% | 100% | 100% | 100% |
|
||||||||||||||
| 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 |
|
|
| 11 |
/**
|
|
| 12 |
* This class will handle the processing of <assertenabled> nodes.
|
|
| 13 |
*
|
|
| 14 |
* <H3>Mandatory attributes</H3>
|
|
| 15 |
* refid Id of the property to be compared.
|
|
| 16 |
*
|
|
| 17 |
* <H3>Optional attributes (default value)</H3>
|
|
| 18 |
* message Message to be displayed when assertion fails.<br>
|
|
| 19 |
* enabled true or false. Default value is true.
|
|
| 20 |
*
|
|
| 21 |
* <H3>Examples:</H3>
|
|
| 22 |
* <assertenabled refid="MyComponent"
|
|
| 23 |
* message="Component is not enabled"
|
|
| 24 |
* enabled="true"/><br>
|
|
| 25 |
* <assertenabled refid="MyComponent"
|
|
| 26 |
* message="Component is enabled"
|
|
| 27 |
* enabled="false"/><br>
|
|
| 28 |
* <assertenabled refid="MyComponent"
|
|
| 29 |
* message="Component is not enabled"/><br>
|
|
| 30 |
*
|
|
| 31 |
* @author <a href="mailto:baylward@nexagent.com">Bruce Aylward : Nexagent Ltd.</a>
|
|
| 32 |
*/
|
|
| 33 |
public class AssertEnabledTagHandler extends AbstractAssertTagHandler { |
|
| 34 |
/**
|
|
| 35 |
* Constructor for AssertEnabledTagHandler.
|
|
| 36 |
*
|
|
| 37 |
* @param element The element to be processed
|
|
| 38 |
* @param testCase The IXMLTestCase that uses this element
|
|
| 39 |
*/
|
|
| 40 | 6 |
public AssertEnabledTagHandler(final Element element,
|
| 41 |
final IXMLTestCase testCase) {
|
|
| 42 | 6 |
super(element, testCase);
|
| 43 |
} |
|
| 44 |
|
|
| 45 |
/**
|
|
| 46 |
* This method obtains the refid which is assumed to
|
|
| 47 |
* be a java.awt.Component. The enabled method is tested
|
|
| 48 |
* and compared with test enabed attribute if specified.
|
|
| 49 |
* If enabled is not specified it is assumed to be true.
|
|
| 50 |
*
|
|
| 51 |
* @throws XMLException may be thrown.
|
|
| 52 |
*/
|
|
| 53 | 5 |
public void processElement() throws XMLException { |
| 54 | 5 |
validateElement(); |
| 55 |
|
|
| 56 | 5 |
boolean result = false; |
| 57 | 5 |
Object object = getXMLTestCase().getProperty(getRefId()); |
| 58 | 5 |
Assert.assertNotNull( |
| 59 |
getMessage(), |
|
| 60 |
object); |
|
| 61 |
|
|
| 62 | 5 |
if (object instanceof java.awt.Component) { |
| 63 | 4 |
result = ((java.awt.Component) object).isEnabled(); |
| 64 |
} |
|
| 65 |
|
|
| 66 | 5 |
Assert.assertTrue( |
| 67 |
getMessage(), |
|
| 68 |
result == getEnabled()); |
|
| 69 |
} |
|
| 70 |
|
|
| 71 |
/**
|
|
| 72 |
* Validate the element has a refid.
|
|
| 73 |
* @throws XMLException when the refid is not specified.
|
|
| 74 |
*/
|
|
| 75 | 5 |
public void validateElement() throws XMLException { |
| 76 |
// do the default validations from the super class
|
|
| 77 | 5 |
super.validateElement();
|
| 78 |
|
|
| 79 |
// reqd attribute: refid
|
|
| 80 | 5 |
checkRequiredAttribute(REFID); |
| 81 |
} |
|
| 82 |
|
|
| 83 |
/**
|
|
| 84 |
* Returns the value of the ENABLED attribute for this element.
|
|
| 85 |
* @return String The value of the ENABLED attribute.
|
|
| 86 |
*/
|
|
| 87 | 5 |
private boolean getEnabled() { |
| 88 | 5 |
return getBoolean(ENABLED, true); |
| 89 |
} |
|
| 90 |
} |
|
| 91 |
|
|
||||||||||