|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AbstractAssertTagHandler.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 org.w3c.dom.Element;
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
/**
|
|
| 10 |
* This tag handler provides the basics for the
|
|
| 11 |
* assert tag handers to be derived. The methods
|
|
| 12 |
* provide a consistent way to validate and read
|
|
| 13 |
* the attributes of the commands.
|
|
| 14 |
* @author Kevin Wilson
|
|
| 15 |
*/
|
|
| 16 |
public abstract class AbstractAssertTagHandler extends AbstractTagHandler { |
|
| 17 |
/**
|
|
| 18 |
* Constructor for AssertNotNullTagHandler.
|
|
| 19 |
*
|
|
| 20 |
* @param element The element to be processed
|
|
| 21 |
* @param testCase The IXMLTestCase that uses this element
|
|
| 22 |
*/
|
|
| 23 | 76 |
public AbstractAssertTagHandler(final Element element,
|
| 24 |
final IXMLTestCase testCase) {
|
|
| 25 | 76 |
super(element, testCase);
|
| 26 |
} |
|
| 27 |
|
|
| 28 |
/**
|
|
| 29 |
* Returns the value of the ACTUALOBJ attribute for this element.
|
|
| 30 |
* If the element contains an actual ref id attribute and that object
|
|
| 31 |
* was found previously, then that object is returned.
|
|
| 32 |
* @return String The value of the ACTUALOBJ attribute. (If an actual ref id
|
|
| 33 |
* object was found and was not null, then that value is returned.
|
|
| 34 |
*/
|
|
| 35 | 42 |
protected Object getActualObject() {
|
| 36 | 42 |
if (getActualRefId() != null) { |
| 37 | 23 |
return getXMLTestCase().getProperty(getActualRefId());
|
| 38 |
} else {
|
|
| 39 | 19 |
return getString(ACTUALOBJ);
|
| 40 |
} |
|
| 41 |
} |
|
| 42 |
|
|
| 43 |
/**
|
|
| 44 |
* Returns the value of the EXPECTEDOBJ attribute for this element.
|
|
| 45 |
* If the element contains an expected ref id attribute and that object
|
|
| 46 |
* was found previously, then that object is returned.
|
|
| 47 |
* @return String The value of the EXPECTEDOBJ attribute. (If an expected ref id
|
|
| 48 |
* object was found and was not null, then that value is returned.
|
|
| 49 |
*/
|
|
| 50 | 31 |
protected Object getExpectedObject() {
|
| 51 | 31 |
if (getExpectedRefId() != null) { |
| 52 | 19 |
return getXMLTestCase().getProperty(getExpectedRefId());
|
| 53 |
} else {
|
|
| 54 | 12 |
return getString(EXPECTEDOBJ);
|
| 55 |
} |
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
/**
|
|
| 59 |
* Returns the value of the MESSAGE attribute for this element.
|
|
| 60 |
* @return String The value of the MESSAGE attribute.
|
|
| 61 |
*/
|
|
| 62 | 61 |
protected String getMessage() {
|
| 63 | 61 |
return getString(MESSAGE);
|
| 64 |
} |
|
| 65 |
|
|
| 66 |
/**
|
|
| 67 |
* Returns the value of the REFID attribute for this element.
|
|
| 68 |
* @return String The value of the REFID attribute.
|
|
| 69 |
*/
|
|
| 70 | 11 |
protected String getRefId() {
|
| 71 | 11 |
return getString(REFID);
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/**
|
|
| 75 |
* Check that either a actualobj or actualrefid is specified.
|
|
| 76 |
* @throws XMLException thrown if one of the above is not present.
|
|
| 77 |
* Or if both are present.
|
|
| 78 |
*/
|
|
| 79 | 44 |
protected void checkActual() throws XMLException { |
| 80 | 44 |
super.checkAtLeastOneRequiredAttribute(
|
| 81 |
new String[] {ACTUALOBJ, ACTUALREFID});
|
|
| 82 |
} |
|
| 83 |
|
|
| 84 |
/**
|
|
| 85 |
* Check that either a expectedobj or expectedrefid is specified.
|
|
| 86 |
* @throws XMLException thrown if one of the above is not present.
|
|
| 87 |
* Or if both are present.
|
|
| 88 |
*/
|
|
| 89 | 33 |
protected void checkExpected() throws XMLException { |
| 90 | 33 |
super.checkAtLeastOneRequiredAttribute(
|
| 91 |
new String[] {EXPECTEDOBJ, EXPECTEDREFID});
|
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
/**
|
|
| 95 |
* Returns the value of the ACTUALREFID attribute for this element.
|
|
| 96 |
* @return String The value of the ACTUALREFID attribute.
|
|
| 97 |
*/
|
|
| 98 | 65 |
private String getActualRefId() {
|
| 99 | 65 |
return getString(ACTUALREFID);
|
| 100 |
} |
|
| 101 |
|
|
| 102 |
/**
|
|
| 103 |
* Returns the value of the EXPECTEDREFID attribute for this element.
|
|
| 104 |
* @return String The value of the EXPECTEDREFID attribute.
|
|
| 105 |
*/
|
|
| 106 | 50 |
private String getExpectedRefId() {
|
| 107 | 50 |
return getString(EXPECTEDREFID);
|
| 108 |
} |
|
| 109 |
} |
|
| 110 |
|
|
||||||||||