|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| package nu.xom.tests; |
|
23 |
| |
|
24 |
| import java.io.File; |
|
25 |
| import java.io.IOException; |
|
26 |
| |
|
27 |
| import nu.xom.Builder; |
|
28 |
| import nu.xom.Comment; |
|
29 |
| import nu.xom.DocType; |
|
30 |
| import nu.xom.Document; |
|
31 |
| import nu.xom.Element; |
|
32 |
| import nu.xom.IllegalAddException; |
|
33 |
| import nu.xom.MultipleParentException; |
|
34 |
| import nu.xom.NoSuchChildException; |
|
35 |
| import nu.xom.ParsingException; |
|
36 |
| import nu.xom.ProcessingInstruction; |
|
37 |
| import nu.xom.Text; |
|
38 |
| import nu.xom.WellformednessException; |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| public class DocumentTest extends XOMTestCase { |
|
51 |
| |
|
52 |
23
| public DocumentTest(String name) {
|
|
53 |
23
| super(name);
|
|
54 |
| } |
|
55 |
| |
|
56 |
| private Element root; |
|
57 |
| private Document doc; |
|
58 |
| |
|
59 |
23
| protected void setUp() {
|
|
60 |
23
| root = new Element("root");
|
|
61 |
23
| doc = new Document(root);
|
|
62 |
| } |
|
63 |
| |
|
64 |
| |
|
65 |
1
| public void testToString() {
|
|
66 |
1
| assertEquals("[nu.xom.Document: root]", doc.toString());
|
|
67 |
| } |
|
68 |
| |
|
69 |
| |
|
70 |
1
| public void testDocTypeInsertion() {
|
|
71 |
| |
|
72 |
1
| DocType type1 = new DocType("root");
|
|
73 |
| |
|
74 |
1
| try {
|
|
75 |
1
| doc.insertChild(type1, 1);
|
|
76 |
0
| fail("inserted doctype after root element");
|
|
77 |
| } |
|
78 |
| catch (IllegalAddException success) { |
|
79 |
1
| assertNotNull(success.getMessage());
|
|
80 |
| } |
|
81 |
| |
|
82 |
1
| doc.insertChild(type1, 0);
|
|
83 |
1
| assertEquals(type1, doc.getDocType());
|
|
84 |
| |
|
85 |
1
| DocType type2 = new DocType("test");
|
|
86 |
1
| try {
|
|
87 |
1
| doc.insertChild(type2, 1);
|
|
88 |
0
| fail("Inserted 2nd DocType");
|
|
89 |
| } |
|
90 |
| catch (IllegalAddException success) { |
|
91 |
1
| assertNotNull(success.getMessage());
|
|
92 |
| } |
|
93 |
1
| assertEquals(type1, doc.getDocType());
|
|
94 |
1
| assertNull(type2.getParent());
|
|
95 |
1
| assertEquals(type1, doc.getChild(0));
|
|
96 |
| |
|
97 |
1
| doc.setDocType(type2);
|
|
98 |
1
| assertEquals(doc.getDocType(), type2);
|
|
99 |
1
| assertNull(type1.getParent());
|
|
100 |
1
| assertEquals(type2, doc.getChild(0));
|
|
101 |
| |
|
102 |
| } |
|
103 |
| |
|
104 |
| |
|
105 |
1
| public void testSetDocType() {
|
|
106 |
| |
|
107 |
1
| DocType type1 = new DocType("root");
|
|
108 |
1
| doc.setDocType(type1);
|
|
109 |
1
| assertEquals(type1, doc.getDocType());
|
|
110 |
| |
|
111 |
1
| doc.insertChild(new Comment("test"), 0);
|
|
112 |
| |
|
113 |
1
| DocType type2 = new DocType("root", "http://www.example.com/");
|
|
114 |
1
| doc.setDocType(type2);
|
|
115 |
1
| assertEquals(type2, doc.getDocType());
|
|
116 |
1
| assertEquals(1, doc.indexOf(type2));
|
|
117 |
1
| assertNull(type1.getParent());
|
|
118 |
1
| assertEquals(doc, type2.getParent());
|
|
119 |
| |
|
120 |
| |
|
121 |
1
| doc.setDocType(type2);
|
|
122 |
1
| assertEquals(type2, doc.getDocType());
|
|
123 |
1
| assertEquals(1, doc.indexOf(type2));
|
|
124 |
1
| assertEquals(doc, type2.getParent());
|
|
125 |
| |
|
126 |
1
| try {
|
|
127 |
1
| doc.setDocType(null);
|
|
128 |
0
| fail("Allowed null doctype");
|
|
129 |
| } |
|
130 |
| catch (NullPointerException success) { |
|
131 |
1
| assertNotNull(success.getMessage());
|
|
132 |
1
| assertEquals(type2, doc.getDocType());
|
|
133 |
| } |
|
134 |
| |
|
135 |
1
| try {
|
|
136 |
1
| Document doc2 = new Document(new Element("root"));
|
|
137 |
1
| doc2.setDocType(type2);
|
|
138 |
0
| fail("Allowed multiple parents for doctype");
|
|
139 |
| } |
|
140 |
| catch (MultipleParentException success) { |
|
141 |
1
| assertNotNull(success.getMessage());
|
|
142 |
| } |
|
143 |
| |
|
144 |
| } |
|
145 |
| |
|
146 |
| |
|
147 |
1
| public void testBaseURI() {
|
|
148 |
| |
|
149 |
1
| assertEquals("", doc.getBaseURI());
|
|
150 |
1
| doc.setBaseURI("http://www.example.com/index.xml");
|
|
151 |
1
| assertEquals(
|
|
152 |
| "http://www.example.com/index.xml", |
|
153 |
| doc.getBaseURI() |
|
154 |
| ); |
|
155 |
1
| doc.setBaseURI("file:///home/elharo/XOM/data/test.xml");
|
|
156 |
1
| assertEquals(
|
|
157 |
| "file:///home/elharo/XOM/data/test.xml", |
|
158 |
| doc.getBaseURI() |
|
159 |
| ); |
|
160 |
1
| doc.setBaseURI("file:///home/elharo/XO%4D/data/test.xml");
|
|
161 |
1
| assertEquals(
|
|
162 |
| "file:///home/elharo/XO%4D/data/test.xml", |
|
163 |
| doc.getBaseURI() |
|
164 |
| ); |
|
165 |
| |
|
166 |
| } |
|
167 |
| |
|
168 |
| |
|
169 |
1
| public void testSecondRoot() {
|
|
170 |
| |
|
171 |
1
| try {
|
|
172 |
1
| doc.insertChild(new Element("test"), 0);
|
|
173 |
0
| fail("Added second root element");
|
|
174 |
| } |
|
175 |
| catch (IllegalAddException success) { |
|
176 |
1
| assertNotNull(success.getMessage());
|
|
177 |
| } |
|
178 |
| |
|
179 |
| } |
|
180 |
| |
|
181 |
| |
|
182 |
1
| public void testSetRoot() {
|
|
183 |
| |
|
184 |
1
| Element newRoot = new Element("newroot");
|
|
185 |
1
| doc.setRootElement(newRoot);
|
|
186 |
| |
|
187 |
1
| assertEquals(newRoot, doc.getRootElement());
|
|
188 |
1
| assertNull(root.getParent());
|
|
189 |
| |
|
190 |
1
| try {
|
|
191 |
1
| doc.setRootElement(null);
|
|
192 |
| } |
|
193 |
| catch (NullPointerException success) { |
|
194 |
1
| assertNotNull(success.getMessage());
|
|
195 |
| } |
|
196 |
| |
|
197 |
1
| Element top = new Element("top");
|
|
198 |
1
| Element child = new Element("child");
|
|
199 |
1
| top.appendChild(child);
|
|
200 |
1
| try {
|
|
201 |
1
| doc.setRootElement(child);
|
|
202 |
0
| fail("Allowed element with two parents");
|
|
203 |
| } |
|
204 |
| catch (MultipleParentException success) { |
|
205 |
1
| assertNotNull(success.getMessage());
|
|
206 |
| } |
|
207 |
| |
|
208 |
| } |
|
209 |
| |
|
210 |
| |
|
211 |
1
| public void testReplaceRootWithItself() {
|
|
212 |
1
| Element root = doc.getRootElement();
|
|
213 |
1
| doc.setRootElement(root);
|
|
214 |
1
| assertEquals(root, doc.getRootElement());
|
|
215 |
| } |
|
216 |
| |
|
217 |
| |
|
218 |
1
| public void testReplaceRootElementWithDifferentElementUsingReplaceChild() {
|
|
219 |
| |
|
220 |
1
| Element newRoot = new Element("newRoot");
|
|
221 |
1
| Element oldRoot = doc.getRootElement();
|
|
222 |
1
| doc.replaceChild(oldRoot, newRoot);
|
|
223 |
1
| assertEquals(newRoot, doc.getRootElement());
|
|
224 |
1
| assertNull(oldRoot.getParent());
|
|
225 |
1
| assertEquals(doc, newRoot.getParent());
|
|
226 |
| |
|
227 |
| } |
|
228 |
| |
|
229 |
| |
|
230 |
1
| public void testInsertionAllowed() {
|
|
231 |
| |
|
232 |
1
| Document doc = new Document(new Element("root"));
|
|
233 |
1
| Comment original = new Comment("original");
|
|
234 |
1
| doc.insertChild(original, 0);
|
|
235 |
| |
|
236 |
1
| Element temp = new Element("temp");
|
|
237 |
1
| Comment c2 = new Comment("new comment");
|
|
238 |
1
| temp.appendChild(c2);
|
|
239 |
| |
|
240 |
1
| try {
|
|
241 |
1
| doc.replaceChild(original, c2);
|
|
242 |
0
| fail("Missed multiple parent exception");
|
|
243 |
| } |
|
244 |
| catch (MultipleParentException success) { |
|
245 |
1
| assertEquals(2, doc.getChildCount());
|
|
246 |
| } |
|
247 |
| |
|
248 |
| } |
|
249 |
| |
|
250 |
| |
|
251 |
1
| public void testReplaceDocTypeWithDifferentDocTypeUsingReplaceChild() {
|
|
252 |
| |
|
253 |
1
| DocType newDocType = new DocType("new");
|
|
254 |
1
| DocType oldDocType = new DocType("old");
|
|
255 |
1
| doc.setDocType(oldDocType);
|
|
256 |
1
| doc.replaceChild(oldDocType, newDocType);
|
|
257 |
1
| assertEquals(newDocType, doc.getDocType());
|
|
258 |
1
| assertNull(oldDocType.getParent());
|
|
259 |
1
| assertEquals(doc, newDocType.getParent());
|
|
260 |
| |
|
261 |
| } |
|
262 |
| |
|
263 |
| |
|
264 |
1
| public void testReplaceDocTypeWithParentedDocTypeUsingReplaceChild() {
|
|
265 |
| |
|
266 |
1
| DocType newDocType = new DocType("new");
|
|
267 |
1
| DocType oldDocType = new DocType("old");
|
|
268 |
1
| Document temp = new Document(new Element("root"));
|
|
269 |
1
| temp.setDocType(newDocType);
|
|
270 |
| |
|
271 |
1
| doc.setDocType(oldDocType);
|
|
272 |
1
| try {
|
|
273 |
1
| doc.replaceChild(oldDocType, newDocType);
|
|
274 |
0
| fail("Missed MultipleParentException");
|
|
275 |
| } |
|
276 |
| catch (MultipleParentException success) { |
|
277 |
1
| assertEquals(2, doc.getChildCount());
|
|
278 |
1
| assertEquals(2, temp.getChildCount());
|
|
279 |
| } |
|
280 |
| |
|
281 |
1
| assertEquals(oldDocType, doc.getDocType());
|
|
282 |
1
| assertNotNull(oldDocType.getParent());
|
|
283 |
1
| assertEquals(doc, oldDocType.getParent());
|
|
284 |
1
| assertEquals(newDocType, temp.getDocType());
|
|
285 |
1
| assertNotNull(oldDocType.getParent());
|
|
286 |
1
| assertEquals(temp, newDocType.getParent());
|
|
287 |
| |
|
288 |
| } |
|
289 |
| |
|
290 |
| |
|
291 |
1
| public void testReplaceRootElementWithParentedElementUsingReplaceChild() {
|
|
292 |
| |
|
293 |
1
| Element oldRoot = new Element("oldRoot");
|
|
294 |
1
| Element newRoot = new Element("newRoot");
|
|
295 |
1
| Document doc = new Document(oldRoot);
|
|
296 |
1
| Element temp = new Element("temp");
|
|
297 |
1
| temp.appendChild(newRoot);
|
|
298 |
| |
|
299 |
1
| try {
|
|
300 |
1
| doc.replaceChild(oldRoot, newRoot);
|
|
301 |
0
| fail("Missed MultipleParentException");
|
|
302 |
| } |
|
303 |
| catch (MultipleParentException success) { |
|
304 |
1
| assertEquals(1, doc.getChildCount());
|
|
305 |
1
| assertEquals(1, temp.getChildCount());
|
|
306 |
| } |
|
307 |
| |
|
308 |
1
| assertEquals(oldRoot, doc.getRootElement());
|
|
309 |
1
| assertEquals(newRoot, temp.getChild(0));
|
|
310 |
1
| assertNotNull(oldRoot.getParent());
|
|
311 |
1
| assertEquals(temp, newRoot.getParent());
|
|
312 |
| |
|
313 |
| } |
|
314 |
| |
|
315 |
| |
|
316 |
1
| public void testReplaceRootElementWithComment() {
|
|
317 |
| |
|
318 |
1
| Element oldRoot = new Element("oldRoot");
|
|
319 |
1
| Document doc = new Document(oldRoot);
|
|
320 |
| |
|
321 |
1
| try {
|
|
322 |
1
| doc.replaceChild(oldRoot, new Comment("c"));
|
|
323 |
0
| fail("Replaced root with comment");
|
|
324 |
| } |
|
325 |
| catch (WellformednessException success) { |
|
326 |
1
| assertNotNull(success.getMessage());
|
|
327 |
| } |
|
328 |
| |
|
329 |
1
| assertEquals(oldRoot, doc.getRootElement());
|
|
330 |
1
| assertEquals(doc, oldRoot.getParent());
|
|
331 |
| |
|
332 |
| } |
|
333 |
| |
|
334 |
| |
|
335 |
1
| public void testReplaceNonDocTypeWithDocTypeUsingReplaceChild() {
|
|
336 |
| |
|
337 |
1
| Comment c = new Comment("Not a doctype");
|
|
338 |
1
| DocType newDocType = new DocType("new");
|
|
339 |
1
| doc.insertChild(c, 0);
|
|
340 |
1
| doc.replaceChild(c, newDocType);
|
|
341 |
1
| assertEquals(newDocType, doc.getDocType());
|
|
342 |
1
| assertNull(c.getParent());
|
|
343 |
1
| assertEquals(doc, newDocType.getParent());
|
|
344 |
| |
|
345 |
| } |
|
346 |
| |
|
347 |
| |
|
348 |
1
| public void testDetach() {
|
|
349 |
1
| Comment comment
|
|
350 |
| = new Comment("This will be attached then detached"); |
|
351 |
1
| doc.appendChild(comment);
|
|
352 |
1
| assertEquals(doc, comment.getParent());
|
|
353 |
1
| comment.detach();
|
|
354 |
1
| assertNull(comment.getParent());
|
|
355 |
| } |
|
356 |
| |
|
357 |
| |
|
358 |
1
| public void testGetDocument() {
|
|
359 |
1
| assertEquals(doc, doc.getDocument());
|
|
360 |
| } |
|
361 |
| |
|
362 |
| |
|
363 |
1
| public void testConstructor() {
|
|
364 |
| |
|
365 |
1
| assertEquals(root, doc.getRootElement());
|
|
366 |
1
| assertEquals(1, doc.getChildCount());
|
|
367 |
| |
|
368 |
1
| Element newRoot = new Element("newRoot");
|
|
369 |
1
| doc.setRootElement(newRoot);
|
|
370 |
1
| assertEquals(newRoot, doc.getRootElement());
|
|
371 |
1
| assertEquals(1, doc.getChildCount());
|
|
372 |
| |
|
373 |
1
| doc.appendChild(new Comment("test"));
|
|
374 |
1
| assertEquals(2, doc.getChildCount());
|
|
375 |
| |
|
376 |
1
| doc.insertChild(new Comment("prolog comment"), 0);
|
|
377 |
1
| assertEquals(3, doc.getChildCount());
|
|
378 |
1
| assertTrue(doc.getChild(0) instanceof Comment);
|
|
379 |
1
| assertTrue(doc.getChild(1) instanceof Element);
|
|
380 |
1
| assertTrue(doc.getChild(2) instanceof Comment);
|
|
381 |
| |
|
382 |
1
| doc.insertChild(new ProcessingInstruction("target", "data"),1);
|
|
383 |
1
| assertTrue(doc.getChild(0) instanceof Comment);
|
|
384 |
1
| assertTrue(doc.getChild(1) instanceof ProcessingInstruction);
|
|
385 |
1
| assertTrue(doc.getChild(2) instanceof Element);
|
|
386 |
1
| assertTrue(doc.getChild(3) instanceof Comment);
|
|
387 |
| |
|
388 |
1
| doc.insertChild(new ProcessingInstruction("epilog", "data"),3);
|
|
389 |
1
| assertTrue(doc.getChild(0) instanceof Comment);
|
|
390 |
1
| assertTrue(doc.getChild(1) instanceof ProcessingInstruction);
|
|
391 |
1
| assertTrue(doc.getChild(2) instanceof Element);
|
|
392 |
1
| assertTrue(doc.getChild(3) instanceof ProcessingInstruction);
|
|
393 |
1
| assertTrue(doc.getChild(4) instanceof Comment);
|
|
394 |
| |
|
395 |
| |
|
396 |
1
| try {
|
|
397 |
1
| Element nullRoot = null;
|
|
398 |
1
| new Document(nullRoot);
|
|
399 |
0
| fail("allowed null root!");
|
|
400 |
| } |
|
401 |
| catch (NullPointerException success) { |
|
402 |
| } |
|
403 |
| |
|
404 |
1
| try {
|
|
405 |
1
| Document nullDoc = null;
|
|
406 |
1
| new Document(nullDoc);
|
|
407 |
0
| fail("allowed null doc!");
|
|
408 |
| } |
|
409 |
| catch (NullPointerException success) { |
|
410 |
| |
|
411 |
| } |
|
412 |
| |
|
413 |
| } |
|
414 |
| |
|
415 |
| |
|
416 |
1
| public void testCopyConstructor() {
|
|
417 |
| |
|
418 |
1
| doc.insertChild(new Comment("text"), 0);
|
|
419 |
1
| doc.insertChild(new ProcessingInstruction("text", "data"), 1);
|
|
420 |
1
| doc.insertChild(new DocType("text"), 2);
|
|
421 |
1
| root.appendChild("some data");
|
|
422 |
1
| doc.appendChild(new Comment("after"));
|
|
423 |
1
| doc.appendChild(new ProcessingInstruction("text", "after"));
|
|
424 |
| |
|
425 |
1
| Document doc2 = new Document(doc);
|
|
426 |
1
| assertEquals(doc, doc2);
|
|
427 |
| |
|
428 |
| } |
|
429 |
| |
|
430 |
| |
|
431 |
1
| public void testCopyConstructorBaseURI() {
|
|
432 |
| |
|
433 |
1
| doc.setBaseURI("http://www.example.com/");
|
|
434 |
| |
|
435 |
1
| Document doc2 = new Document(doc);
|
|
436 |
1
| assertEquals(doc.getBaseURI(), doc2.getBaseURI());
|
|
437 |
1
| assertEquals("http://www.example.com/", doc2.getBaseURI());
|
|
438 |
1
| assertEquals(
|
|
439 |
| doc.getRootElement().getBaseURI(), |
|
440 |
| doc2.getRootElement().getBaseURI() |
|
441 |
| ); |
|
442 |
1
| assertEquals(
|
|
443 |
| "http://www.example.com/", |
|
444 |
| doc2.getRootElement().getBaseURI() |
|
445 |
| ); |
|
446 |
| |
|
447 |
| } |
|
448 |
| |
|
449 |
| |
|
450 |
1
| public void testCopy() {
|
|
451 |
| |
|
452 |
1
| doc.insertChild(new Comment("text"), 0);
|
|
453 |
1
| doc.insertChild(new ProcessingInstruction("text", "data"), 1);
|
|
454 |
1
| doc.insertChild(new DocType("text"), 2);
|
|
455 |
1
| root.appendChild("some data");
|
|
456 |
1
| doc.appendChild(new Comment("after"));
|
|
457 |
1
| doc.appendChild(new ProcessingInstruction("text", "after"));
|
|
458 |
| |
|
459 |
1
| Document doc2 = (Document) doc.copy();
|
|
460 |
1
| assertEquals(doc, doc2);
|
|
461 |
| |
|
462 |
| } |
|
463 |
| |
|
464 |
| |
|
465 |
1
| public void testAppend() {
|
|
466 |
| |
|
467 |
1
| Element root = new Element("root");
|
|
468 |
1
| Document doc = new Document(root);
|
|
469 |
| |
|
470 |
1
| try {
|
|
471 |
1
| doc.appendChild(new Text("test"));
|
|
472 |
0
| fail("appended string");
|
|
473 |
| } |
|
474 |
| catch (IllegalAddException success) { |
|
475 |
1
| assertNotNull(success.getMessage());
|
|
476 |
| } |
|
477 |
| |
|
478 |
1
| try {
|
|
479 |
1
| doc.appendChild(new Text(" "));
|
|
480 |
0
| fail("appended white space");
|
|
481 |
| } |
|
482 |
| catch (IllegalAddException success) { |
|
483 |
1
| assertNotNull(success.getMessage());
|
|
484 |
| } |
|
485 |
| |
|
486 |
1
| try {
|
|
487 |
1
| doc.appendChild(new Text("test"));
|
|
488 |
0
| fail("appended Text");
|
|
489 |
| } |
|
490 |
| catch (IllegalAddException success) { |
|
491 |
1
| assertNotNull(success.getMessage());
|
|
492 |
| } |
|
493 |
| |
|
494 |
1
| try {
|
|
495 |
1
| doc.appendChild(new Comment("test"));
|
|
496 |
1
| doc.appendChild(new Element("test"));
|
|
497 |
0
| fail("appended element");
|
|
498 |
| } |
|
499 |
| catch (IllegalAddException success) { |
|
500 |
1
| assertNotNull(success.getMessage());
|
|
501 |
| } |
|
502 |
| |
|
503 |
1
| try {
|
|
504 |
1
| doc.insertChild(new Element("test"), 0);
|
|
505 |
0
| fail("inserted element");
|
|
506 |
| } |
|
507 |
| catch (IllegalAddException success) { |
|
508 |
1
| assertNotNull(success.getMessage());
|
|
509 |
| } |
|
510 |
| |
|
511 |
| } |
|
512 |
| |
|
513 |
| |
|
514 |
1
| public void testRemoval() {
|
|
515 |
| |
|
516 |
1
| Element root = new Element("root");
|
|
517 |
1
| Document doc = new Document(root);
|
|
518 |
| |
|
519 |
1
| try {
|
|
520 |
1
| root.detach();
|
|
521 |
0
| fail("detached root element");
|
|
522 |
| } |
|
523 |
| catch (WellformednessException success) { |
|
524 |
1
| assertNotNull(success.getMessage());
|
|
525 |
| } |
|
526 |
| |
|
527 |
1
| try {
|
|
528 |
1
| doc.removeChild(root);
|
|
529 |
0
| fail("removed root element");
|
|
530 |
| } |
|
531 |
| catch (WellformednessException success) { |
|
532 |
1
| assertNotNull(success.getMessage());
|
|
533 |
| } |
|
534 |
| |
|
535 |
1
| try {
|
|
536 |
1
| doc.removeChild(0);
|
|
537 |
0
| fail("removed root element");
|
|
538 |
| } |
|
539 |
| catch (WellformednessException success) { |
|
540 |
1
| assertNotNull(success.getMessage());
|
|
541 |
| } |
|
542 |
| |
|
543 |
1
| doc.appendChild(new Comment("test"));
|
|
544 |
1
| doc.removeChild(1);
|
|
545 |
1
| assertEquals(1, doc.getChildCount());
|
|
546 |
| |
|
547 |
1
| Comment test = new Comment("test");
|
|
548 |
1
| doc.appendChild(test);
|
|
549 |
1
| doc.removeChild(test);
|
|
550 |
1
| assertEquals(1, doc.getChildCount());
|
|
551 |
| |
|
552 |
1
| try {
|
|
553 |
1
| Comment something = new Comment("sd");
|
|
554 |
1
| doc.removeChild(something);
|
|
555 |
0
| fail("Removed nonchild");
|
|
556 |
| } |
|
557 |
| catch (NoSuchChildException success) { |
|
558 |
1
| assertNotNull(success.getMessage());
|
|
559 |
| } |
|
560 |
| |
|
561 |
1
| try {
|
|
562 |
1
| doc.removeChild(20);
|
|
563 |
0
| fail("removed overly sized element");
|
|
564 |
| } |
|
565 |
| catch (IndexOutOfBoundsException success) { |
|
566 |
1
| assertNotNull(success.getMessage());
|
|
567 |
| } |
|
568 |
| |
|
569 |
| } |
|
570 |
| |
|
571 |
| |
|
572 |
1
| public void testToXML() throws ParsingException, IOException {
|
|
573 |
| |
|
574 |
1
| Builder builder = new Builder();
|
|
575 |
1
| File f = new File("data");
|
|
576 |
1
| f = new File(f, "test.xml");
|
|
577 |
1
| Document input = builder.build(f);
|
|
578 |
1
| String s = input.toXML();
|
|
579 |
1
| Document output = builder.build(s, f.toURL().toExternalForm());
|
|
580 |
1
| assertEquals(input, output);
|
|
581 |
| |
|
582 |
| } |
|
583 |
| |
|
584 |
| |
|
585 |
| } |