|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
StopWatchTagHandlerT.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: Test StopWatchTagHandler.</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 StopWatchTagHandlerT extends TestCase { |
|
17 |
|
|
18 |
/**
|
|
19 |
* Test tag handler.
|
|
20 |
*/
|
|
21 |
private StopWatchTagHandler m_tagHandler = null; |
|
22 |
|
|
23 |
/**
|
|
24 |
* Test fixture.
|
|
25 |
*/
|
|
26 |
private ElementFixture m_fixture;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* Setup the test.
|
|
30 |
* @throws Exception may be thrown.
|
|
31 |
*/
|
|
32 | 5 |
protected void setUp() throws Exception { |
33 | 5 |
super.setUp();
|
34 | 5 |
m_fixture = new ElementFixture(this); |
35 | 5 |
m_fixture.setUp(); |
36 |
} |
|
37 |
|
|
38 |
/**
|
|
39 |
* Tear down the test.
|
|
40 |
* @throws Exception may be thrown.
|
|
41 |
*/
|
|
42 | 5 |
protected void tearDown() throws Exception { |
43 | 5 |
m_tagHandler = null;
|
44 | 5 |
m_fixture.tearDown(); |
45 | 5 |
m_fixture = null;
|
46 | 5 |
super.tearDown();
|
47 |
} |
|
48 |
|
|
49 |
/**
|
|
50 |
* Test a success duration less than the value.
|
|
51 |
* @throws XMLException may be thrown.
|
|
52 |
*/
|
|
53 | 1 |
public void testProcessLessthan() throws XMLException { |
54 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
55 | 1 |
Element mark = m_fixture.newElement("stopwatch",
|
56 |
new String[] {
|
|
57 |
"action", "mark", |
|
58 |
"id", "test" |
|
59 |
}); |
|
60 | 1 |
m_tagHandler = new StopWatchTagHandler(mark, tc);
|
61 | 1 |
m_tagHandler.processElement(); |
62 |
|
|
63 | 1 |
try {
|
64 | 1 |
Thread.currentThread().sleep(1000); |
65 |
} catch (Exception ex) {
|
|
66 |
} |
|
67 |
|
|
68 | 1 |
Element end = m_fixture.newElement("stopwatch",
|
69 |
new String[] {
|
|
70 |
"action", "lessthan", |
|
71 |
"refid", "test", |
|
72 |
"value", "5000" |
|
73 |
}); |
|
74 | 1 |
m_tagHandler = new StopWatchTagHandler(end, tc);
|
75 | 1 |
m_tagHandler.processElement(); |
76 |
} |
|
77 |
|
|
78 |
/**
|
|
79 |
* Test a failure duration greater than value.
|
|
80 |
* @throws XMLException may be thrown.
|
|
81 |
*/
|
|
82 | 1 |
public void testProcessGreaterthan() throws XMLException { |
83 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
84 | 1 |
Element mark = m_fixture.newElement("stopwatch",
|
85 |
new String[] {
|
|
86 |
"action", "mark", |
|
87 |
"id", "test" |
|
88 |
}); |
|
89 | 1 |
m_tagHandler = new StopWatchTagHandler(mark, tc);
|
90 | 1 |
m_tagHandler.processElement(); |
91 |
|
|
92 | 1 |
try {
|
93 | 1 |
Thread.currentThread().sleep(1000); |
94 |
} catch (Exception ex) {
|
|
95 |
} |
|
96 |
|
|
97 | 1 |
Element end = m_fixture.newElement("stopwatch",
|
98 |
new String[] {
|
|
99 |
"action", "lessthan", |
|
100 |
"refid", "test", |
|
101 |
"value", "500" |
|
102 |
}); |
|
103 | 1 |
m_tagHandler = new StopWatchTagHandler(end, tc);
|
104 | 1 |
Error ex = null;
|
105 | 1 |
try {
|
106 | 1 |
m_tagHandler.processElement(); |
107 |
} catch (Error e) {
|
|
108 | 1 |
ex = e; |
109 |
} |
|
110 | 1 |
assertNotNull("Exception expected:", ex);
|
111 |
} |
|
112 |
|
|
113 |
/**
|
|
114 |
* Test a log action.
|
|
115 |
* @throws XMLException may be thrown.
|
|
116 |
*/
|
|
117 | 1 |
public void testProcessLog() throws XMLException { |
118 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
119 | 1 |
Element mark = m_fixture.newElement("stopwatch",
|
120 |
new String[] {
|
|
121 |
"action", "mark", |
|
122 |
"id", "test" |
|
123 |
}); |
|
124 | 1 |
m_tagHandler = new StopWatchTagHandler(mark, tc);
|
125 | 1 |
m_tagHandler.processElement(); |
126 |
|
|
127 | 1 |
try {
|
128 | 1 |
Thread.currentThread().sleep(500); |
129 |
} catch (Exception ex) {
|
|
130 |
} |
|
131 |
|
|
132 | 1 |
Element end = m_fixture.newElement("stopwatch",
|
133 |
new String[] {
|
|
134 |
"action", "log", |
|
135 |
"refid", "test" |
|
136 |
}); |
|
137 | 1 |
m_tagHandler = new StopWatchTagHandler(end, tc);
|
138 | 1 |
m_tagHandler.processElement(); |
139 |
} |
|
140 |
|
|
141 |
/**
|
|
142 |
* Test a invalid action.
|
|
143 |
* @throws XMLException may be thrown.
|
|
144 |
*/
|
|
145 | 1 |
public void testProcessInvalid() throws XMLException { |
146 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
147 | 1 |
Element mark = m_fixture.newElement("stopwatch",
|
148 |
new String[] {
|
|
149 |
"action", "read", |
|
150 |
"id", "test" |
|
151 |
}); |
|
152 | 1 |
m_tagHandler = new StopWatchTagHandler(mark, tc);
|
153 | 1 |
XMLException ex = null;
|
154 | 1 |
try {
|
155 | 1 |
m_tagHandler.processElement(); |
156 |
} catch (XMLException e) {
|
|
157 | 1 |
ex = e; |
158 |
} |
|
159 | 1 |
assertNotNull("Exception expected", ex);
|
160 |
} |
|
161 |
|
|
162 |
/**
|
|
163 |
* Test the Tag lookup.
|
|
164 |
*/
|
|
165 | 1 |
public void testLookup() { |
166 | 1 |
IXMLTestCase tc = m_fixture.getTestCase(); |
167 | 1 |
Element mark = m_fixture.newElement("stopwatch",
|
168 |
new String[] {
|
|
169 |
"action", "mark", |
|
170 |
"id", "test" |
|
171 |
}); |
|
172 | 1 |
Object o = XMLTagResourceBundle.getTagHandler(mark, tc, "stopwatch");
|
173 | 1 |
assertNotNull(o); |
174 |
} |
|
175 |
|
|
176 |
} |
|
177 |
|
|