|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DumpTagHandlerT.java | - | 100% | 100% | 100% |
|
||||||||||||||
| 1 |
package junit.extensions.xml.elements;
|
|
| 2 |
|
|
| 3 |
import java.awt.Component;
|
|
| 4 |
import javax.swing.JFrame;
|
|
| 5 |
import javax.swing.JLabel;
|
|
| 6 |
import javax.swing.JTextField;
|
|
| 7 |
|
|
| 8 |
import org.w3c.dom.Element;
|
|
| 9 |
import junit.extensions.xml.IXMLTestCase;
|
|
| 10 |
import junit.extensions.xml.XMLException;
|
|
| 11 |
import junit.framework.TestCase;
|
|
| 12 |
import junit.extensions.xml.XMLTagResourceBundle;
|
|
| 13 |
|
|
| 14 |
/**
|
|
| 15 |
* <p>Title: DumpTagHandler Test Case.</p>
|
|
| 16 |
* <p>Copyright: Copyright (c) 2003</p>
|
|
| 17 |
* <p>Company: JFCUnit OpenSource Project</p>
|
|
| 18 |
* @author Kevin Wilson
|
|
| 19 |
* @version 1.0
|
|
| 20 |
*/
|
|
| 21 |
public class DumpTagHandlerT extends TestCase { |
|
| 22 |
|
|
| 23 |
/**
|
|
| 24 |
* tag handler.
|
|
| 25 |
*/
|
|
| 26 |
private DumpTagHandler m_dumpTagHandler = null; |
|
| 27 |
|
|
| 28 |
/**
|
|
| 29 |
* Test fixture.
|
|
| 30 |
*/
|
|
| 31 |
private ElementFixture m_fixture;
|
|
| 32 |
|
|
| 33 |
/**
|
|
| 34 |
* Setup the test.
|
|
| 35 |
* @throws Exception may be thrown.
|
|
| 36 |
*/
|
|
| 37 | 7 |
protected void setUp() throws Exception { |
| 38 | 7 |
super.setUp();
|
| 39 | 7 |
m_fixture = new ElementFixture(this); |
| 40 | 7 |
m_fixture.setUp(); |
| 41 |
} |
|
| 42 |
|
|
| 43 |
/**
|
|
| 44 |
* Tear down the test.
|
|
| 45 |
* @throws Exception may be thrown.
|
|
| 46 |
*/
|
|
| 47 | 7 |
protected void tearDown() throws Exception { |
| 48 | 7 |
m_dumpTagHandler = null;
|
| 49 | 7 |
m_fixture.tearDown(); |
| 50 |
|
|
| 51 | 7 |
m_fixture = null;
|
| 52 | 7 |
super.tearDown();
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
/**
|
|
| 56 |
* Test process element recursive false.
|
|
| 57 |
* @throws XMLException may be thrown.
|
|
| 58 |
*/
|
|
| 59 | 1 |
public void testProcessElement() throws XMLException { |
| 60 | 1 |
Element dump = m_fixture.newElement("dump",
|
| 61 |
new String[] {
|
|
| 62 |
"refid", "test", |
|
| 63 |
"recursive", "false" |
|
| 64 |
}); |
|
| 65 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
| 66 | 1 |
tc.addProperty("test", prepComponent(0));
|
| 67 | 1 |
m_dumpTagHandler = new DumpTagHandler(dump, tc);
|
| 68 | 1 |
m_dumpTagHandler.processElement(); |
| 69 |
} |
|
| 70 |
|
|
| 71 |
/**
|
|
| 72 |
* Test process field recursive true.
|
|
| 73 |
* @throws XMLException may be thrown.
|
|
| 74 |
*/
|
|
| 75 | 1 |
public void testProcessRecursive() throws XMLException { |
| 76 | 1 |
Element dump = m_fixture.newElement("dump",
|
| 77 |
new String[] {
|
|
| 78 |
"refid", "test", |
|
| 79 |
"recursive", "true" |
|
| 80 |
}); |
|
| 81 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
| 82 | 1 |
m_dumpTagHandler = new DumpTagHandler(dump, tc);
|
| 83 | 1 |
tc.addProperty("test", prepComponent(0));
|
| 84 | 1 |
m_dumpTagHandler.processElement(); |
| 85 |
} |
|
| 86 |
|
|
| 87 |
/**
|
|
| 88 |
* Test process label recursive false.
|
|
| 89 |
* @throws XMLException may be thrown.
|
|
| 90 |
*/
|
|
| 91 | 1 |
public void testProcessElement1() throws XMLException { |
| 92 | 1 |
Element dump = m_fixture.newElement("dump",
|
| 93 |
new String[] {
|
|
| 94 |
"refid", "test", |
|
| 95 |
"recursive", "false" |
|
| 96 |
}); |
|
| 97 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
| 98 | 1 |
tc.addProperty("test", prepComponent(1));
|
| 99 | 1 |
m_dumpTagHandler = new DumpTagHandler(dump, tc);
|
| 100 | 1 |
m_dumpTagHandler.processElement(); |
| 101 |
} |
|
| 102 |
|
|
| 103 |
/**
|
|
| 104 |
* Test process label recursive true.
|
|
| 105 |
* @throws XMLException may be thrown.
|
|
| 106 |
*/
|
|
| 107 | 1 |
public void testProcessRecursive1() throws XMLException { |
| 108 | 1 |
Element dump = m_fixture.newElement("dump",
|
| 109 |
new String[] {
|
|
| 110 |
"refid", "test", |
|
| 111 |
"recursive", "true" |
|
| 112 |
}); |
|
| 113 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
| 114 | 1 |
m_dumpTagHandler = new DumpTagHandler(dump, tc);
|
| 115 | 1 |
tc.addProperty("test", prepComponent(1));
|
| 116 | 1 |
m_dumpTagHandler.processElement(); |
| 117 |
} |
|
| 118 |
|
|
| 119 |
/**
|
|
| 120 |
* Test Process frame recursive is false.
|
|
| 121 |
* @throws XMLException may be thrown.
|
|
| 122 |
*/
|
|
| 123 | 1 |
public void testProcessElement2() throws XMLException { |
| 124 | 1 |
Element dump = m_fixture.newElement("dump",
|
| 125 |
new String[] {
|
|
| 126 |
"refid", "test", |
|
| 127 |
"recursive", "false" |
|
| 128 |
}); |
|
| 129 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
| 130 | 1 |
tc.addProperty("test", prepComponent(2));
|
| 131 | 1 |
m_dumpTagHandler = new DumpTagHandler(dump, tc);
|
| 132 | 1 |
m_dumpTagHandler.processElement(); |
| 133 |
} |
|
| 134 |
|
|
| 135 |
/**
|
|
| 136 |
* Test the recursive.
|
|
| 137 |
* @throws XMLException may be thrown.
|
|
| 138 |
*/
|
|
| 139 | 1 |
public void testProcessRecursive2() throws XMLException { |
| 140 | 1 |
Element dump = m_fixture.newElement("dump",
|
| 141 |
new String[] {
|
|
| 142 |
"refid", "test", |
|
| 143 |
"recursive", "true" |
|
| 144 |
}); |
|
| 145 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
| 146 | 1 |
m_dumpTagHandler = new DumpTagHandler(dump, tc);
|
| 147 | 1 |
tc.addProperty("test", prepComponent(2));
|
| 148 | 1 |
m_dumpTagHandler.processElement(); |
| 149 |
} |
|
| 150 |
|
|
| 151 |
/**
|
|
| 152 |
* Test with the Tag lookup.
|
|
| 153 |
*/
|
|
| 154 | 1 |
public void testLookup() { |
| 155 | 1 |
Element dump = m_fixture.newElement("dump",
|
| 156 |
new String[] {
|
|
| 157 |
"refid", "test", |
|
| 158 |
"recursive", "true" |
|
| 159 |
}); |
|
| 160 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
| 161 | 1 |
Object o = XMLTagResourceBundle.getTagHandler(dump, tc, "dump");
|
| 162 | 1 |
assertNotNull(o); |
| 163 |
} |
|
| 164 |
|
|
| 165 |
|
|
| 166 |
/**
|
|
| 167 |
* Prepare the component for testing.
|
|
| 168 |
* @param requestedComponent int Component to 0 - field, 1 - label, 2 - frame.
|
|
| 169 |
* @return Component component to be tested.
|
|
| 170 |
*/
|
|
| 171 | 6 |
private Component prepComponent(final int requestedComponent) { |
| 172 | 6 |
int item = requestedComponent % 3;
|
| 173 | 6 |
JFrame frame = new JFrame();
|
| 174 | 6 |
JLabel label = new JLabel("TEST"); |
| 175 | 6 |
frame.getContentPane().add(label); |
| 176 | 6 |
JTextField field = new JTextField();
|
| 177 | 6 |
label.setLabelFor(field); |
| 178 | 6 |
frame.getContentPane().add(field); |
| 179 | 6 |
switch(item) {
|
| 180 | 2 |
case 0:
|
| 181 | 2 |
return field;
|
| 182 | 2 |
case 1:
|
| 183 | 2 |
return label;
|
| 184 | 2 |
default:
|
| 185 | 2 |
return frame;
|
| 186 |
} |
|
| 187 |
} |
|
| 188 |
|
|
| 189 |
} |
|
| 190 |
|
|
||||||||||