1
|
|
package junit.extensions.xml.elements;
|
2
|
|
|
3
|
|
|
4
|
|
import java.awt.Point;
|
5
|
|
|
6
|
|
import org.w3c.dom.Element;
|
7
|
|
import junit.extensions.xml.IXMLTestCase;
|
8
|
|
import junit.extensions.xml.XMLException;
|
9
|
|
import junit.framework.AssertionFailedError;
|
10
|
|
import junit.framework.TestCase;
|
11
|
|
import junit.extensions.xml.XMLTagResourceBundle;
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
public class AssertEqualsTagHandlerT extends TestCase {
|
21
|
|
|
22
|
|
|
23
|
|
|
24
|
|
private AssertEqualsTagHandler m_tagHandler = null;
|
25
|
|
|
26
|
|
|
27
|
|
|
28
|
|
private ElementFixture m_fixture;
|
29
|
|
|
30
|
|
|
31
|
|
|
32
|
|
|
33
|
|
|
34
|
11
|
protected void setUp() throws Exception {
|
35
|
11
|
super.setUp();
|
36
|
11
|
m_fixture = new ElementFixture(this);
|
37
|
11
|
m_fixture.setUp();
|
38
|
|
}
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
11
|
protected void tearDown() throws Exception {
|
45
|
11
|
m_tagHandler = null;
|
46
|
11
|
m_fixture.tearDown();
|
47
|
|
|
48
|
11
|
m_fixture = null;
|
49
|
11
|
super.tearDown();
|
50
|
|
}
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
1
|
public void testAssertEqualsTagHandler() throws XMLException {
|
57
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
58
|
|
"actualrefid", "data1",
|
59
|
|
"expectedrefid", "data2"});
|
60
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
61
|
1
|
testCase.addProperty("data1", "abc");
|
62
|
1
|
testCase.addProperty("data2", "abc");
|
63
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
64
|
|
|
65
|
1
|
m_tagHandler.processElement();
|
66
|
|
}
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
1
|
public void testAssertEqualsTagHandler4() throws XMLException {
|
73
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
74
|
|
"actualrefid", "data1",
|
75
|
|
"expectedrefid", "data2"});
|
76
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
77
|
1
|
testCase.addProperty("data1", new Point(1, 1));
|
78
|
1
|
testCase.addProperty("data2", new Point(1, 1));
|
79
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
80
|
|
|
81
|
1
|
m_tagHandler.processElement();
|
82
|
|
}
|
83
|
|
|
84
|
|
|
85
|
|
|
86
|
|
|
87
|
|
|
88
|
1
|
public void testAssertEqualsTagHandler2() throws XMLException {
|
89
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
90
|
|
"actualobj", "abc",
|
91
|
|
"expectedrefid", "data2"});
|
92
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
93
|
1
|
testCase.addProperty("data2", "abc");
|
94
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
95
|
|
|
96
|
1
|
m_tagHandler.processElement();
|
97
|
|
}
|
98
|
|
|
99
|
|
|
100
|
|
|
101
|
|
|
102
|
|
|
103
|
1
|
public void testAssertEqualsTagHandler3() throws XMLException {
|
104
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
105
|
|
"actualobj", "abc",
|
106
|
|
"expectedobj", "abc"});
|
107
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
108
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
109
|
|
|
110
|
1
|
m_tagHandler.processElement();
|
111
|
|
}
|
112
|
|
|
113
|
|
|
114
|
|
|
115
|
|
|
116
|
|
|
117
|
1
|
public void testAssertEqualsTagHandlerFail() throws XMLException {
|
118
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
119
|
|
"message", "FAIL",
|
120
|
|
"actualobj", "abc",
|
121
|
|
"expectedobj", "def"});
|
122
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
123
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
124
|
|
|
125
|
1
|
AssertionFailedError err = null;
|
126
|
1
|
try {
|
127
|
1
|
m_tagHandler.processElement();
|
128
|
|
} catch (AssertionFailedError afe) {
|
129
|
1
|
err = afe;
|
130
|
|
}
|
131
|
|
|
132
|
1
|
String exp = "junit.framework.AssertionFailedError: FAIL expected:<def> but was:<abc>";
|
133
|
1
|
assertNotNull("Exception not thrown", err);
|
134
|
1
|
assertEquals("Validate error text", exp, err.toString());
|
135
|
|
}
|
136
|
|
|
137
|
|
|
138
|
|
|
139
|
|
|
140
|
|
|
141
|
1
|
public void testAssertEqualsTagHandlerFail2() throws XMLException {
|
142
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
143
|
|
"message", "FAIL",
|
144
|
|
"actualrefid", "data1",
|
145
|
|
"expectedobj", "def"});
|
146
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
147
|
1
|
testCase.addProperty("data1", "abc");
|
148
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
149
|
|
|
150
|
1
|
AssertionFailedError err = null;
|
151
|
1
|
try {
|
152
|
1
|
m_tagHandler.processElement();
|
153
|
|
} catch (AssertionFailedError afe) {
|
154
|
1
|
err = afe;
|
155
|
|
}
|
156
|
|
|
157
|
1
|
String exp = "junit.framework.AssertionFailedError: FAIL expected:<def> but was:<abc>";
|
158
|
1
|
assertNotNull("Exception not thrown", err);
|
159
|
1
|
assertEquals("Validate error text", exp, err.toString());
|
160
|
|
}
|
161
|
|
|
162
|
|
|
163
|
|
|
164
|
|
|
165
|
|
|
166
|
1
|
public void testAssertEqualsTagHandlerFail3() throws XMLException {
|
167
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
168
|
|
"message", "FAIL",
|
169
|
|
"actualrefid", "data1",
|
170
|
|
"expectedrefid", "data2"});
|
171
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
172
|
1
|
testCase.addProperty("data1", "abc");
|
173
|
1
|
testCase.addProperty("data2", "def");
|
174
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
175
|
|
|
176
|
1
|
AssertionFailedError err = null;
|
177
|
1
|
try {
|
178
|
1
|
m_tagHandler.processElement();
|
179
|
|
} catch (AssertionFailedError afe) {
|
180
|
1
|
err = afe;
|
181
|
|
}
|
182
|
|
|
183
|
1
|
String exp = "junit.framework.AssertionFailedError: FAIL expected:<def> but was:<abc>";
|
184
|
1
|
assertNotNull("Exception not thrown", err);
|
185
|
1
|
assertEquals("Validate error text", exp, err.toString());
|
186
|
|
|
187
|
|
}
|
188
|
|
|
189
|
|
|
190
|
|
|
191
|
|
|
192
|
|
|
193
|
1
|
public void testAssertEqualsTagHandlerFail4() throws XMLException {
|
194
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
195
|
|
"actualrefid", "data1",
|
196
|
|
"expectedrefid", "data2"});
|
197
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
198
|
1
|
testCase.addProperty("data1", new Point(1, 1));
|
199
|
1
|
testCase.addProperty("data2", new Point(1, 2));
|
200
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
201
|
|
|
202
|
1
|
AssertionFailedError err = null;
|
203
|
1
|
try {
|
204
|
1
|
m_tagHandler.processElement();
|
205
|
|
} catch (AssertionFailedError afe) {
|
206
|
1
|
err = afe;
|
207
|
|
}
|
208
|
|
|
209
|
1
|
String exp = "junit.framework.AssertionFailedError: "
|
210
|
|
+ "expected:<java.awt.Point[x=1,y=2]> "
|
211
|
|
+ "but was:<java.awt.Point[x=1,y=1]>";
|
212
|
1
|
String act = err.toString();
|
213
|
1
|
assertNotNull("Exception not thrown", err);
|
214
|
1
|
assertEquals("Validate error text", exp, act);
|
215
|
|
}
|
216
|
|
|
217
|
|
|
218
|
|
|
219
|
|
|
220
|
|
|
221
|
1
|
public void testAssertEqualsTagHandlerNull1() throws XMLException {
|
222
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
223
|
|
"actualrefid", "data1",
|
224
|
|
"expectedrefid", "data2"});
|
225
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
226
|
1
|
testCase.addProperty("data1", null);
|
227
|
1
|
testCase.addProperty("data2", "ABC");
|
228
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
229
|
|
|
230
|
1
|
AssertionFailedError err = null;
|
231
|
1
|
try {
|
232
|
1
|
m_tagHandler.processElement();
|
233
|
|
} catch (AssertionFailedError afe) {
|
234
|
1
|
err = afe;
|
235
|
|
}
|
236
|
|
|
237
|
1
|
String exp = "junit.framework.AssertionFailedError: expected:<ABC> but was:<null>";
|
238
|
1
|
String act = err.toString();
|
239
|
1
|
assertNotNull("Exception not thrown", err);
|
240
|
1
|
assertEquals("Validate error text", exp, act);
|
241
|
|
}
|
242
|
|
|
243
|
|
|
244
|
|
|
245
|
|
|
246
|
|
|
247
|
1
|
public void testAssertEqualsTagHandlerNull2() throws XMLException {
|
248
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
249
|
|
"actualrefid", "data1",
|
250
|
|
"expectedrefid", "data2"});
|
251
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
252
|
1
|
testCase.addProperty("data1", "ABC");
|
253
|
1
|
testCase.addProperty("data2", null);
|
254
|
1
|
m_tagHandler = new AssertEqualsTagHandler(element, testCase);
|
255
|
|
|
256
|
1
|
AssertionFailedError err = null;
|
257
|
1
|
try {
|
258
|
1
|
m_tagHandler.processElement();
|
259
|
|
} catch (AssertionFailedError afe) {
|
260
|
1
|
err = afe;
|
261
|
|
}
|
262
|
|
|
263
|
1
|
String exp = "junit.framework.AssertionFailedError: expected:<null> but was:<ABC>";
|
264
|
|
|
265
|
1
|
String act = err.toString();
|
266
|
1
|
assertNotNull("Exception not thrown", err);
|
267
|
1
|
assertEquals("Validate error text", exp, act);
|
268
|
|
}
|
269
|
|
|
270
|
|
|
271
|
|
|
272
|
|
|
273
|
1
|
public void testLookup() {
|
274
|
1
|
Element element = m_fixture.newElement("assertequals", new String[] {
|
275
|
|
"actualrefid", "data1",
|
276
|
|
"expectedrefid", "data2"});
|
277
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
278
|
1
|
Object o = XMLTagResourceBundle.getTagHandler(element, testCase, "assertequals");
|
279
|
1
|
assertNotNull(o);
|
280
|
|
}
|
281
|
|
|
282
|
|
}
|
283
|
|
|