|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
EvaluateTagHandlerT.java | - | 100% | 100% | 100% |
|
1 |
package junit.extensions.xml.elements;
|
|
2 |
|
|
3 |
import java.awt.Point;
|
|
4 |
|
|
5 |
import org.w3c.dom.Element;
|
|
6 |
import junit.extensions.xml.IXMLTestCase;
|
|
7 |
import junit.extensions.xml.XMLException;
|
|
8 |
import junit.framework.TestCase;
|
|
9 |
import junit.extensions.xml.XMLTagResourceBundle;
|
|
10 |
|
|
11 |
/**
|
|
12 |
* <p>Title: EvaluateTagHandler TestCase.</p>
|
|
13 |
* <p>Copyright: Copyright (c) 2003</p>
|
|
14 |
* <p>Company: JFCUnit OpenSource Project</p>
|
|
15 |
* @author Kevin Wilson
|
|
16 |
* @version 1.0
|
|
17 |
*/
|
|
18 |
public class EvaluateTagHandlerT extends TestCase { |
|
19 |
|
|
20 |
/**
|
|
21 |
* tag handler.
|
|
22 |
*/
|
|
23 |
private EvaluateTagHandler m_evaluateTagHandler = null; |
|
24 |
|
|
25 |
/**
|
|
26 |
* element fixture.
|
|
27 |
*/
|
|
28 |
private ElementFixture m_elementFixture;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* Set up the test.
|
|
32 |
* @throws Exception may be thrown.
|
|
33 |
*/
|
|
34 | 6 |
protected void setUp() throws Exception { |
35 | 6 |
super.setUp();
|
36 | 6 |
m_elementFixture = new ElementFixture(this); |
37 | 6 |
m_elementFixture.setUp(); |
38 |
} |
|
39 |
|
|
40 |
/**
|
|
41 |
* Tear down the test.
|
|
42 |
* @throws Exception may be thrown.
|
|
43 |
*/
|
|
44 | 6 |
protected void tearDown() throws Exception { |
45 | 6 |
m_evaluateTagHandler = null;
|
46 | 6 |
m_elementFixture.tearDown(); |
47 |
|
|
48 | 6 |
m_elementFixture = null;
|
49 | 6 |
super.tearDown();
|
50 |
} |
|
51 |
|
|
52 |
/**
|
|
53 |
* A dummy class to be tested.
|
|
54 |
*/
|
|
55 |
public class TestObject { |
|
56 |
/**
|
|
57 |
* Data to be returned.
|
|
58 |
*/
|
|
59 |
private Object m_data;
|
|
60 |
/**
|
|
61 |
* Constructor.
|
|
62 |
* @param data Object to be tested.
|
|
63 |
*/
|
|
64 | 5 |
public TestObject(final Object data) {
|
65 | 5 |
m_data = data; |
66 |
} |
|
67 |
|
|
68 |
/**
|
|
69 |
* Get the test data object.
|
|
70 |
* @return data object from constructor.
|
|
71 |
*/
|
|
72 | 1 |
public Object getData() {
|
73 | 1 |
return m_data;
|
74 |
} |
|
75 |
|
|
76 |
/**
|
|
77 |
* Test returning a point.
|
|
78 |
* @return Point instance returned.
|
|
79 |
*/
|
|
80 | 1 |
public Point getPoint() {
|
81 | 1 |
return new Point(5, 5); |
82 |
} |
|
83 |
|
|
84 |
/**
|
|
85 |
* Test primitive instance returned.
|
|
86 |
* @return int primitive.
|
|
87 |
*/
|
|
88 | 1 |
public int getPrimitive() { |
89 | 1 |
return 1;
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/**
|
|
94 |
* Test processElement.
|
|
95 |
* @throws XMLException may be thrown.
|
|
96 |
*/
|
|
97 | 1 |
public void testProcessElement() throws XMLException { |
98 |
|
|
99 | 1 |
Element eval = m_elementFixture.newElement("evaluate", new String[] { |
100 |
"id", "result", |
|
101 |
"refid", "testObject", |
|
102 |
"method", "getData" |
|
103 |
}); |
|
104 |
|
|
105 | 1 |
IXMLTestCase tc = m_elementFixture.getTestCase(); |
106 | 1 |
TestObject obj = new TestObject("ABC"); |
107 | 1 |
tc.addProperty("testObject", obj);
|
108 |
|
|
109 | 1 |
m_evaluateTagHandler = new EvaluateTagHandler(eval, tc);
|
110 | 1 |
m_evaluateTagHandler.processElement(); |
111 |
|
|
112 | 1 |
Object result = tc.getProperty("result");
|
113 | 1 |
assertEquals("ABC", result);
|
114 |
} |
|
115 |
|
|
116 |
/**
|
|
117 |
* Test processElement with a invalid object.
|
|
118 |
* @throws XMLException may be thrown.
|
|
119 |
*/
|
|
120 | 1 |
public void testProcessElementInvalidObj() throws XMLException { |
121 |
|
|
122 | 1 |
Element eval = m_elementFixture.newElement("evaluate", new String[] { |
123 |
"id", "result", |
|
124 |
"refid", "testObjectA", |
|
125 |
"method", "getData" |
|
126 |
}); |
|
127 |
|
|
128 | 1 |
IXMLTestCase tc = m_elementFixture.getTestCase(); |
129 | 1 |
TestObject obj = new TestObject("ABC"); |
130 | 1 |
tc.addProperty("testObject", obj);
|
131 |
|
|
132 | 1 |
m_evaluateTagHandler = new EvaluateTagHandler(eval, tc);
|
133 | 1 |
Error ex = null;
|
134 | 1 |
try {
|
135 | 1 |
m_evaluateTagHandler.processElement(); |
136 |
} catch (final Error e) {
|
|
137 | 1 |
ex = e; |
138 |
} |
|
139 | 1 |
assertNotNull("Exception should be thrown", ex);
|
140 |
} |
|
141 |
|
|
142 |
/**
|
|
143 |
* Test processElement with a invalid method.
|
|
144 |
* @throws XMLException may be thrown.
|
|
145 |
*/
|
|
146 | 1 |
public void testProcessElementInvalidMethod() throws XMLException { |
147 |
|
|
148 | 1 |
Element eval = m_elementFixture.newElement("evaluate", new String[] { |
149 |
"id", "result", |
|
150 |
"refid", "testObject", |
|
151 |
"method", "getDatax" |
|
152 |
}); |
|
153 |
|
|
154 | 1 |
IXMLTestCase tc = m_elementFixture.getTestCase(); |
155 | 1 |
TestObject obj = new TestObject("ABC"); |
156 | 1 |
tc.addProperty("testObject", obj);
|
157 |
|
|
158 | 1 |
m_evaluateTagHandler = new EvaluateTagHandler(eval, tc);
|
159 | 1 |
XMLException ex = null;
|
160 | 1 |
try {
|
161 | 1 |
m_evaluateTagHandler.processElement(); |
162 |
} catch (XMLException e) {
|
|
163 | 1 |
ex = e; |
164 |
} |
|
165 | 1 |
assertNotNull("Exception expected:", ex);
|
166 |
} |
|
167 |
|
|
168 |
/**
|
|
169 |
* Test processElement receiving a Object.
|
|
170 |
* @throws XMLException may be thrown.
|
|
171 |
*/
|
|
172 | 1 |
public void testProcessElementPointMethod() throws XMLException { |
173 |
|
|
174 | 1 |
Element eval = m_elementFixture.newElement("evaluate", new String[] { |
175 |
"id", "result", |
|
176 |
"refid", "testObject", |
|
177 |
"method", "getPoint" |
|
178 |
}); |
|
179 |
|
|
180 | 1 |
IXMLTestCase tc = m_elementFixture.getTestCase(); |
181 | 1 |
TestObject obj = new TestObject("ABC"); |
182 | 1 |
tc.addProperty("testObject", obj);
|
183 |
|
|
184 | 1 |
m_evaluateTagHandler = new EvaluateTagHandler(eval, tc);
|
185 | 1 |
m_evaluateTagHandler.processElement(); |
186 |
|
|
187 | 1 |
Object result = tc.getProperty("result");
|
188 |
} |
|
189 |
|
|
190 |
/**
|
|
191 |
* Test process element retrieving a primitive.
|
|
192 |
* @throws XMLException may be thrown.
|
|
193 |
*/
|
|
194 | 1 |
public void testProcessElementPrimative() throws XMLException { |
195 |
|
|
196 | 1 |
Element eval = m_elementFixture.newElement("evaluate", new String[] { |
197 |
"id", "result", |
|
198 |
"refid", "testObject", |
|
199 |
"method", "getPrimitive" |
|
200 |
}); |
|
201 |
|
|
202 | 1 |
IXMLTestCase tc = m_elementFixture.getTestCase(); |
203 | 1 |
TestObject obj = new TestObject("ABC"); |
204 | 1 |
tc.addProperty("testObject", obj);
|
205 |
|
|
206 | 1 |
m_evaluateTagHandler = new EvaluateTagHandler(eval, tc);
|
207 | 1 |
m_evaluateTagHandler.processElement(); |
208 |
|
|
209 | 1 |
Object result = tc.getProperty("result");
|
210 |
} |
|
211 |
|
|
212 |
/**
|
|
213 |
* Test with the Tag lookup.
|
|
214 |
*/
|
|
215 | 1 |
public void testLookup() { |
216 | 1 |
Element eval = m_elementFixture.newElement("evaluate", new String[] { |
217 |
"id", "result", |
|
218 |
"refid", "testObject", |
|
219 |
"method", "getPrimitive" |
|
220 |
}); |
|
221 |
|
|
222 | 1 |
IXMLTestCase tc = m_elementFixture.getTestCase(); |
223 | 1 |
Object o = XMLTagResourceBundle.getTagHandler(eval, tc, "evaluate");
|
224 | 1 |
assertNotNull(o); |
225 |
} |
|
226 |
} |
|
227 |
|
|