KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > util > XmlUtilsTest


1 package info.jtrac.util;
2
3 import info.jtrac.util.XmlUtils;
4 import junit.framework.TestCase;
5 import org.dom4j.Document;
6
7 public class XmlUtilsTest extends TestCase {
8     
9     public void testXmlStringParse() {
10         String JavaDoc s = "<test/>";
11         Document d = XmlUtils.parse(s);
12         assertTrue(d.getRootElement().getName().equals("test"));
13     }
14     
15     public void testBadXmlParseFails() {
16         String JavaDoc s = "foo";
17         try {
18             Document d = XmlUtils.parse(s);
19             fail("How did we parse invalid XML?");
20         } catch (Exception JavaDoc e) {
21             // expected
22
}
23     }
24     
25     public void testGetAsPrettyXml() {
26         String JavaDoc s = "<root><node1><node2>data</node2></node1></root>";
27         String JavaDoc result = XmlUtils.getAsPrettyXml(s);
28         assertTrue(result.equals("<root>\n <node1>\n <node2>data</node2>\n </node1>\n</root>"));
29     }
30     
31 }
32
Popular Tags