|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| WhileTagHandlerT.java | - | 100% | 100% | 100% |
|
||||||||||||||
| 1 |
package junit.extensions.xml.elements;
|
|
| 2 |
|
|
| 3 |
import org.w3c.dom.Element;
|
|
| 4 |
import junit.extensions.xml.IXMLTestCase;
|
|
| 5 |
import junit.extensions.xml.XMLException;
|
|
| 6 |
import junit.framework.TestCase;
|
|
| 7 |
import junit.extensions.xml.XMLTagResourceBundle;
|
|
| 8 |
|
|
| 9 |
/**
|
|
| 10 |
* <p>Title: WhileTagHandler Test Case.</p>
|
|
| 11 |
* <p>Copyright: Copyright (c) 2003</p>
|
|
| 12 |
* <p>Company: JFCUnit OpenSource Project</p>
|
|
| 13 |
* @author Kevin Wilson
|
|
| 14 |
* @version 1.0
|
|
| 15 |
*/
|
|
| 16 |
public class WhileTagHandlerT |
|
| 17 |
extends TestCase {
|
|
| 18 |
/**
|
|
| 19 |
* Tag handler.
|
|
| 20 |
*/
|
|
| 21 |
private WhileTagHandler m_whileTagHandler = null; |
|
| 22 |
|
|
| 23 |
/**
|
|
| 24 |
* Test fixture.
|
|
| 25 |
*/
|
|
| 26 |
private ElementFixture m_fixture;
|
|
| 27 |
|
|
| 28 |
/**
|
|
| 29 |
* test case.
|
|
| 30 |
*/
|
|
| 31 |
private IXMLTestCase m_testCase;
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
/**
|
|
| 35 |
* Constructor.
|
|
| 36 |
* @param name Name of the test case.
|
|
| 37 |
*/
|
|
| 38 | 3 |
public WhileTagHandlerT(final String name) {
|
| 39 | 3 |
super(name);
|
| 40 |
} |
|
| 41 |
|
|
| 42 |
/**
|
|
| 43 |
* Setup the test case.
|
|
| 44 |
* @throws Exception may be thrown.
|
|
| 45 |
*/
|
|
| 46 | 3 |
protected void setUp() throws Exception { |
| 47 | 3 |
super.setUp();
|
| 48 | 3 |
m_fixture = new ElementFixture(this); |
| 49 | 3 |
m_fixture.setUp(); |
| 50 | 3 |
m_testCase = m_fixture.getTestCase(); |
| 51 |
|
|
| 52 |
} |
|
| 53 |
|
|
| 54 |
/**
|
|
| 55 |
* Tear down the test case.
|
|
| 56 |
* @throws Exception may be thrown.
|
|
| 57 |
*/
|
|
| 58 | 3 |
protected void tearDown() throws Exception { |
| 59 | 3 |
m_whileTagHandler = null;
|
| 60 | 3 |
m_fixture.tearDown(); |
| 61 | 3 |
m_fixture = null;
|
| 62 | 3 |
super.tearDown();
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
/**
|
|
| 66 |
* Test validate element.
|
|
| 67 |
* @throws XMLException may be thrown.
|
|
| 68 |
*/
|
|
| 69 | 1 |
public void testValidateElement() throws XMLException { |
| 70 | 1 |
Element e = m_fixture.newElement("while", new String[] { |
| 71 |
"test", "assertNull", |
|
| 72 |
"actualrefid", "testValue" |
|
| 73 |
}); |
|
| 74 | 1 |
Element prop = m_fixture.newElement("property", new String[] { |
| 75 |
"name", "testValue", |
|
| 76 |
"value", "1" |
|
| 77 |
}); |
|
| 78 | 1 |
e.appendChild(prop); |
| 79 |
|
|
| 80 | 1 |
m_whileTagHandler = new WhileTagHandler(e, m_testCase);
|
| 81 |
|
|
| 82 |
// Should not throw an exception
|
|
| 83 | 1 |
m_whileTagHandler.validateElement(); |
| 84 |
|
|
| 85 | 1 |
e = m_fixture.newElement("white", new String[] { |
| 86 |
"test", "assertNull", |
|
| 87 |
"actualrefid", "testValue" |
|
| 88 |
}); |
|
| 89 | 1 |
prop = m_fixture.newElement("property", new String[] { |
| 90 |
"name", "testValue", |
|
| 91 |
"value", "1" |
|
| 92 |
}); |
|
| 93 | 1 |
e.appendChild(prop); |
| 94 |
|
|
| 95 | 1 |
m_whileTagHandler = new WhileTagHandler(e, m_testCase);
|
| 96 |
|
|
| 97 | 1 |
XMLException exception = null;
|
| 98 | 1 |
try {
|
| 99 | 1 |
m_whileTagHandler.validateElement(); |
| 100 |
} catch (XMLException ex) {
|
|
| 101 | 1 |
exception = ex; |
| 102 |
} |
|
| 103 | 1 |
assertNotNull(exception); |
| 104 |
} |
|
| 105 |
|
|
| 106 |
/**
|
|
| 107 |
* Test process element.
|
|
| 108 |
* @throws XMLException may be thrown.
|
|
| 109 |
*/
|
|
| 110 | 1 |
public void testProcessElement() throws XMLException { |
| 111 | 1 |
Element e = m_fixture.newElement("while", new String[] { |
| 112 |
"test", "assertNull", |
|
| 113 |
"actualrefid", "testValue" |
|
| 114 |
}); |
|
| 115 |
|
|
| 116 | 1 |
Element prop = m_fixture.newElement("property", new String[] { |
| 117 |
"name", "testValue", |
|
| 118 |
"value", "1" |
|
| 119 |
}); |
|
| 120 | 1 |
e.appendChild(prop); |
| 121 |
|
|
| 122 | 1 |
m_whileTagHandler = new WhileTagHandler(e, m_testCase);
|
| 123 | 1 |
m_whileTagHandler.processElement(); |
| 124 |
|
|
| 125 |
// Invalid ID
|
|
| 126 | 1 |
e = m_fixture.newElement("while", new String[] { |
| 127 |
"test", "assertnull", |
|
| 128 |
"actualefid", "testValue" |
|
| 129 |
}); |
|
| 130 |
|
|
| 131 | 1 |
prop = m_fixture.newElement("property", new String[] { |
| 132 |
"name", "testValue", |
|
| 133 |
"value", "1" |
|
| 134 |
}); |
|
| 135 | 1 |
e.appendChild(prop); |
| 136 |
|
|
| 137 | 1 |
m_testCase.addProperty("debug", "true"); |
| 138 | 1 |
m_whileTagHandler = new WhileTagHandler(e, m_testCase);
|
| 139 | 1 |
XMLException exception = null;
|
| 140 | 1 |
try {
|
| 141 | 1 |
m_whileTagHandler.processElement(); |
| 142 |
} catch (XMLException ex) {
|
|
| 143 | 1 |
exception = ex; |
| 144 |
} |
|
| 145 | 1 |
assertNotNull("Exception expected", exception);
|
| 146 |
|
|
| 147 |
} |
|
| 148 |
|
|
| 149 |
/**
|
|
| 150 |
* Test with the Tag lookup.
|
|
| 151 |
*/
|
|
| 152 | 1 |
public void testGetHandler() { |
| 153 | 1 |
Element e = m_fixture.newElement("while", new String[] { |
| 154 |
"test", "assertNull", |
|
| 155 |
"actualrefid", "testValue" |
|
| 156 |
}); |
|
| 157 |
|
|
| 158 | 1 |
Element prop = m_fixture.newElement("property", new String[] { |
| 159 |
"name", "testValue", |
|
| 160 |
"value", "1" |
|
| 161 |
}); |
|
| 162 | 1 |
e.appendChild(prop); |
| 163 |
|
|
| 164 | 1 |
Object x = XMLTagResourceBundle.getTagHandler(e, m_fixture.getTestCase(), "while");
|
| 165 | 1 |
assertNotNull("Tag handler should be found", x);
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
} |
|
| 171 |
|
|
| 172 |
} |
|
| 173 |
|
|
||||||||||