|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ProcedureTagHandler.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 |
import junit.extensions.xml.XMLProcedure;
|
|
| 13 |
|
|
| 14 |
import org.w3c.dom.Element;
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
/**
|
|
| 18 |
* Provide a mechanism for executing repetative tasks with
|
|
| 19 |
* different context.
|
|
| 20 |
*
|
|
| 21 |
* <H3>Tag Name</H3>
|
|
| 22 |
* procedure
|
|
| 23 |
* <H3>Attributes</H3>
|
|
| 24 |
* <pre>
|
|
| 25 |
* name - the name of the procedure to be added [required]
|
|
| 26 |
* call - the name of the procedure to be called
|
|
| 27 |
* </pre>
|
|
| 28 |
* All other attributes will be passed as properties to the
|
|
| 29 |
* procedure.
|
|
| 30 |
*
|
|
| 31 |
* <H3>Examples</H3>
|
|
| 32 |
* <pre>
|
|
| 33 |
* <procedure name="login" />
|
|
| 34 |
* <key string="${username}"/>
|
|
| 35 |
* <key string="${password}"/>
|
|
| 36 |
* </procedure>
|
|
| 37 |
*
|
|
| 38 |
* <procedure call="login" username="me" password="letmein" /> * @author JFCUnit contributor
|
|
| 39 |
* </pre>
|
|
| 40 |
*/
|
|
| 41 |
public class ProcedureTagHandler extends AbstractTagHandler { |
|
| 42 |
/**
|
|
| 43 |
* Constructor.
|
|
| 44 |
* @param element Element to be processed by the tag handler.
|
|
| 45 |
* @param testCase parent test case.
|
|
| 46 |
*/
|
|
| 47 | 2 |
public ProcedureTagHandler(final Element element,
|
| 48 |
final IXMLTestCase testCase) {
|
|
| 49 | 2 |
super(element, testCase);
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
/**
|
|
| 53 |
* Constructor.
|
|
| 54 |
* @param element Element to be processed by the tag handler.
|
|
| 55 |
* @param testSuite parent test suite
|
|
| 56 |
*/
|
|
| 57 | 3 |
public ProcedureTagHandler(final Element element,
|
| 58 |
final IXMLTestSuite testSuite) {
|
|
| 59 | 3 |
super(element, testSuite);
|
| 60 |
} |
|
| 61 |
|
|
| 62 |
/**
|
|
| 63 |
* Handle the XML processing of the tag 'procedure'.
|
|
| 64 |
* @throws XMLException upon failure of processing.
|
|
| 65 |
*/
|
|
| 66 | 4 |
public void processElement() throws XMLException { |
| 67 | 4 |
validateElement(); |
| 68 |
|
|
| 69 | 4 |
String name = getString(CALL); |
| 70 |
|
|
| 71 | 4 |
if (name != null) { |
| 72 | 1 |
getXMLTestCase().callProcedure( |
| 73 |
name, |
|
| 74 |
getElement()); |
|
| 75 |
|
|
| 76 | 1 |
return;
|
| 77 |
} |
|
| 78 |
|
|
| 79 | 3 |
name = getString(NAME); |
| 80 | 3 |
getTest().addProcedure(new XMLProcedure(getElement()));
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/**
|
|
| 84 |
* Make sure the appropriate tag and attributes are used.
|
|
| 85 |
* @throws XMLException when validation fails.
|
|
| 86 |
*/
|
|
| 87 | 4 |
public void validateElement() throws XMLException { |
| 88 | 4 |
super.validateElement();
|
| 89 |
|
|
| 90 |
// check the element tag name
|
|
| 91 | 4 |
if (this.getXMLTestCase() != null) { |
| 92 | 1 |
checkOneRequiredAttribute(new String[] {CALL, NAME});
|
| 93 |
} else {
|
|
| 94 | 3 |
this.checkRequiredAttribute(NAME);
|
| 95 |
} |
|
| 96 |
} |
|
| 97 |
} |
|
| 98 |
|
|
||||||||||