01: package info.jtrac.util;
02:
03: import info.jtrac.util.XmlUtils;
04: import junit.framework.TestCase;
05: import org.dom4j.Document;
06:
07: public class XmlUtilsTest extends TestCase {
08:
09: public void testXmlStringParse() {
10: String s = "<test/>";
11: Document d = XmlUtils.parse(s);
12: assertTrue(d.getRootElement().getName().equals("test"));
13: }
14:
15: public void testBadXmlParseFails() {
16: String s = "foo";
17: try {
18: Document d = XmlUtils.parse(s);
19: fail("How did we parse invalid XML?");
20: } catch (Exception e) {
21: // expected
22: }
23: }
24:
25: public void testGetAsPrettyXml() {
26: String s = "<root><node1><node2>data</node2></node1></root>";
27: String result = XmlUtils.getAsPrettyXml(s);
28: assertTrue(result
29: .equals("<root>\n <node1>\n <node2>data</node2>\n </node1>\n</root>"));
30: }
31:
32: }
|