1 22 package org.jboss.test.util.test; 23 24 import org.jboss.test.JBossTestCase; 25 import org.jboss.util.xml.DOMUtils; 26 import org.jboss.util.xml.DOMWriter; 27 import org.w3c.dom.Element ; 28 29 36 public class DOMWriterUnitTestCase extends JBossTestCase 37 { 38 public DOMWriterUnitTestCase(String name) 39 { 40 super(name); 41 } 42 43 46 public void testPrint() throws Exception 47 { 48 String envStr = 49 "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + 50 "<env:Header/>" + 51 "<env:Body>" + 52 "<ns1:sendMimeImageGIF xmlns:ns1='http://org.jboss.ws/attachment'>" + 53 "<message>Some text message</message>" + 54 "</ns1:sendMimeImageGIF>" + 55 "</env:Body>" + 56 "</env:Envelope>"; 57 58 String expStr = envStr; 59 60 Element env = DOMUtils.parse(envStr); 61 62 String wasStr = DOMWriter.printNode(env, false); 63 assertEquals(expStr, wasStr); 64 } 65 66 69 public void testPrettyPrint() throws Exception 70 { 71 String envStr = 72 "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + 73 "<env:Header/>" + 74 "<env:Body>" + 75 "<ns1:sendMimeImageGIF xmlns:ns1='http://org.jboss.ws/attachment'>" + 76 "<message>Some text message</message>" + 77 "</ns1:sendMimeImageGIF>" + 78 "</env:Body>" + 79 "</env:Envelope>"; 80 81 String expStr = 82 "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>\n" + 83 " <env:Header/>\n" + 84 " <env:Body>\n" + 85 " <ns1:sendMimeImageGIF xmlns:ns1='http://org.jboss.ws/attachment'>\n" + 86 " <message>Some text message</message>\n" + 87 " </ns1:sendMimeImageGIF>\n" + 88 " </env:Body>\n" + 89 "</env:Envelope>"; 90 91 Element env = DOMUtils.parse(envStr); 92 93 String wasStr = DOMWriter.printNode(env, true); 94 assertEquals(expStr, wasStr); 95 } 96 97 100 public void testPrettyComment() throws Exception 101 { 102 String envStr = 103 "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + 104 "<env:Header/>" + 105 "<env:Body>" + 106 "<ns1:sendMimeImageGIF xmlns:ns1='http://org.jboss.ws/attachment'>" + 107 "<!-- This is some comment -->" + 108 "<message>Some text message</message>" + 109 "</ns1:sendMimeImageGIF>" + 110 "</env:Body>" + 111 "</env:Envelope>"; 112 113 String expStr = 114 "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>\n" + 115 " <env:Header/>\n" + 116 " <env:Body>\n" + 117 " <ns1:sendMimeImageGIF xmlns:ns1='http://org.jboss.ws/attachment'>\n" + 118 " <!-- This is some comment -->\n" + 119 " <message>Some text message</message>\n" + 120 " </ns1:sendMimeImageGIF>\n" + 121 " </env:Body>\n" + 122 "</env:Envelope>"; 123 124 Element env = DOMUtils.parse(envStr); 125 126 String wasStr = DOMWriter.printNode(env, true); 127 assertEquals(expStr, wasStr); 128 } 129 } 130 | Popular Tags |