1
|
|
package junit.extensions.xml.elements;
|
2
|
|
|
3
|
|
import org.w3c.dom.Comment;
|
4
|
|
import org.w3c.dom.Element;
|
5
|
|
import junit.extensions.xml.IXMLTestCase;
|
6
|
|
import junit.extensions.xml.XMLException;
|
7
|
|
import junit.framework.TestCase;
|
8
|
|
import junit.extensions.xml.XMLTagResourceBundle;
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
public class ChooseTagHandlerT
|
18
|
|
extends TestCase {
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
|
23
|
|
private ChooseTagHandler m_tagHandler = null;
|
24
|
|
|
25
|
|
|
26
|
|
|
27
|
|
|
28
|
|
private ElementFixture m_fixture;
|
29
|
|
|
30
|
|
|
31
|
|
|
32
|
|
|
33
|
|
|
34
|
6
|
protected void setUp() throws Exception {
|
35
|
6
|
super.setUp();
|
36
|
6
|
m_fixture = new ElementFixture(this);
|
37
|
6
|
m_fixture.setUp();
|
38
|
|
}
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
6
|
protected void tearDown() throws Exception {
|
45
|
6
|
m_tagHandler = null;
|
46
|
6
|
m_fixture.tearDown();
|
47
|
|
|
48
|
6
|
m_fixture = null;
|
49
|
6
|
super.tearDown();
|
50
|
|
}
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
1
|
public void testChooseTagHandler() {
|
56
|
1
|
Element choose = m_fixture.newElement("choose",
|
57
|
|
new String[0]);
|
58
|
1
|
Element when = m_fixture.newChild(choose, "when", new String[] {
|
59
|
|
"test", "assertequals",
|
60
|
|
"expectedobj", "test",
|
61
|
|
"actualobj", "test"
|
62
|
|
});
|
63
|
1
|
Element whenprop = m_fixture.newChild(when, "property", new String[] {
|
64
|
|
"name", "branch",
|
65
|
|
"value", "when"
|
66
|
|
});
|
67
|
1
|
Element otherwise = m_fixture.newChild(choose, "otherwise",
|
68
|
|
new String[0]);
|
69
|
1
|
Element otherprop = m_fixture.newChild(otherwise, "property",
|
70
|
|
new String[] {
|
71
|
|
"name", "branch",
|
72
|
|
"value", "otherwise"
|
73
|
|
});
|
74
|
|
|
75
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
76
|
1
|
m_tagHandler = new ChooseTagHandler(choose, testCase);
|
77
|
|
|
78
|
1
|
XMLException exp = null;
|
79
|
1
|
try {
|
80
|
1
|
m_tagHandler.processElement();
|
81
|
|
} catch (XMLException e) {
|
82
|
0
|
exp = e;
|
83
|
|
}
|
84
|
1
|
assertNull(exp);
|
85
|
1
|
Object val = testCase.getProperty("branch");
|
86
|
1
|
assertEquals("branch taken", "when", val);
|
87
|
|
}
|
88
|
|
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
1
|
public void testChooseTagHandlerOther() {
|
93
|
1
|
Element choose = m_fixture.newElement("choose",
|
94
|
|
new String[0]);
|
95
|
1
|
Element when = m_fixture.newChild(choose, "when", new String[] {
|
96
|
|
"test", "assertequals",
|
97
|
|
"expectedobj", "test",
|
98
|
|
"actualobj", "test1"
|
99
|
|
});
|
100
|
1
|
Element whenprop = m_fixture.newChild(when, "property", new String[] {
|
101
|
|
"name", "branch",
|
102
|
|
"value", "when"
|
103
|
|
});
|
104
|
1
|
Element otherwise = m_fixture.newChild(choose, "otherwise",
|
105
|
|
new String[0]);
|
106
|
1
|
Element otherprop = m_fixture.newChild(otherwise, "property",
|
107
|
|
new String[] {
|
108
|
|
"name", "branch",
|
109
|
|
"value", "otherwise"
|
110
|
|
});
|
111
|
|
|
112
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
113
|
1
|
m_tagHandler = new ChooseTagHandler(choose, testCase);
|
114
|
|
|
115
|
1
|
XMLException exp = null;
|
116
|
1
|
try {
|
117
|
1
|
m_tagHandler.processElement();
|
118
|
|
} catch (XMLException e) {
|
119
|
0
|
exp = e;
|
120
|
|
}
|
121
|
1
|
assertNull(exp);
|
122
|
1
|
Object val = testCase.getProperty("branch");
|
123
|
1
|
assertEquals("branch taken", "otherwise", val);
|
124
|
|
}
|
125
|
|
|
126
|
|
|
127
|
|
|
128
|
|
|
129
|
1
|
public void testChooseTagHandlerWhen2() {
|
130
|
1
|
Element choose = m_fixture.newElement("choose",
|
131
|
|
new String[0]);
|
132
|
1
|
Element otherwise = m_fixture.newChild(choose, "otherwise",
|
133
|
|
new String[0]);
|
134
|
1
|
Element otherprop = m_fixture.newChild(otherwise, "property",
|
135
|
|
new String[] {
|
136
|
|
"name", "branch",
|
137
|
|
"value", "otherwise"
|
138
|
|
});
|
139
|
1
|
Element when = m_fixture.newChild(choose, "when", new String[] {
|
140
|
|
"test", "assertequals",
|
141
|
|
"expectedobj", "test",
|
142
|
|
"actualobj", "test1"
|
143
|
|
});
|
144
|
1
|
Element whenprop = m_fixture.newChild(when, "property", new String[] {
|
145
|
|
"name", "branch",
|
146
|
|
"value", "when"
|
147
|
|
});
|
148
|
1
|
Element when2 = m_fixture.newChild(choose, "when", new String[] {
|
149
|
|
"test", "assertequals",
|
150
|
|
"expectedobj", "test",
|
151
|
|
"actualobj", "test"
|
152
|
|
});
|
153
|
1
|
Element whenprop2 = m_fixture.newChild(when2, "property", new String[] {
|
154
|
|
"name", "branch",
|
155
|
|
"value", "when2"
|
156
|
|
});
|
157
|
|
|
158
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
159
|
1
|
m_tagHandler = new ChooseTagHandler(choose, testCase);
|
160
|
|
|
161
|
1
|
XMLException exp = null;
|
162
|
1
|
try {
|
163
|
1
|
m_tagHandler.processElement();
|
164
|
|
} catch (XMLException e) {
|
165
|
0
|
exp = e;
|
166
|
|
}
|
167
|
1
|
assertNull(exp);
|
168
|
1
|
Object val = testCase.getProperty("branch");
|
169
|
1
|
assertEquals("branch taken", "when2", val);
|
170
|
|
}
|
171
|
|
|
172
|
|
|
173
|
|
|
174
|
|
|
175
|
1
|
public void testNoOtherwise() {
|
176
|
1
|
Element choose = m_fixture.newElement("choose",
|
177
|
|
new String[0]);
|
178
|
1
|
Comment c = choose.getOwnerDocument().createComment("TEST");
|
179
|
1
|
choose.appendChild(c);
|
180
|
1
|
Element when = m_fixture.newChild(choose, "when", new String[] {
|
181
|
|
"test", "assertequals",
|
182
|
|
"expectedobj", "test",
|
183
|
|
"actualobj", "test1"
|
184
|
|
});
|
185
|
1
|
Element whenprop = m_fixture.newChild(when, "property", new String[] {
|
186
|
|
"name", "branch",
|
187
|
|
"value", "when"
|
188
|
|
});
|
189
|
|
|
190
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
191
|
1
|
m_tagHandler = new ChooseTagHandler(choose, testCase);
|
192
|
|
|
193
|
1
|
XMLException exp = null;
|
194
|
1
|
try {
|
195
|
1
|
m_tagHandler.processElement();
|
196
|
|
} catch (XMLException e) {
|
197
|
0
|
exp = e;
|
198
|
|
}
|
199
|
1
|
assertNull(exp);
|
200
|
1
|
Object val = testCase.getProperty("branch");
|
201
|
1
|
assertNull("branch taken", val);
|
202
|
|
}
|
203
|
|
|
204
|
|
|
205
|
|
|
206
|
|
|
207
|
1
|
public void testInvalidTest() {
|
208
|
1
|
Element choose = m_fixture.newElement("choose",
|
209
|
|
new String[0]);
|
210
|
1
|
Comment c = choose.getOwnerDocument().createComment("TEST");
|
211
|
1
|
choose.appendChild(c);
|
212
|
1
|
Element when = m_fixture.newChild(choose, "when", new String[] {
|
213
|
|
"test", "assertequals",
|
214
|
|
"expected", "test",
|
215
|
|
"actual", "test1"
|
216
|
|
});
|
217
|
1
|
Element whenprop = m_fixture.newChild(when, "property", new String[] {
|
218
|
|
"name", "branch",
|
219
|
|
"value", "when"
|
220
|
|
});
|
221
|
|
|
222
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
223
|
1
|
m_tagHandler = new ChooseTagHandler(choose, testCase);
|
224
|
|
|
225
|
1
|
XMLException exp = null;
|
226
|
1
|
try {
|
227
|
1
|
m_tagHandler.processElement();
|
228
|
|
} catch (XMLException e) {
|
229
|
1
|
exp = e;
|
230
|
|
}
|
231
|
1
|
assertNotNull("Exception expected", exp);
|
232
|
|
}
|
233
|
|
|
234
|
|
|
235
|
|
|
236
|
|
|
237
|
1
|
public void testLookup() {
|
238
|
1
|
Element choose = m_fixture.newElement("choose",
|
239
|
|
new String[0]);
|
240
|
1
|
IXMLTestCase testCase = m_fixture.getTestCase();
|
241
|
1
|
Object o = XMLTagResourceBundle.getTagHandler(choose, testCase, "choose");
|
242
|
1
|
assertNotNull(o);
|
243
|
|
}
|
244
|
|
}
|
245
|
|
|