KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > util > test > DOMWriterUnitTestCase


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

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 JavaDoc;
28
29 /**
30 * Test the DOMWriter
31 *
32 * @author Thomas.Diesler@jboss.org
33 * @author Dimitris.Andreadis@jboss.org
34 * @since 22-Jun-2005
35 */

36 public class DOMWriterUnitTestCase extends JBossTestCase
37 {
38    public DOMWriterUnitTestCase(String JavaDoc name)
39    {
40       super(name);
41    }
42    
43    /**
44     * Test printing
45     */

46    public void testPrint() throws Exception JavaDoc
47    {
48       String JavaDoc 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 JavaDoc expStr = envStr;
59       
60       Element JavaDoc env = DOMUtils.parse(envStr);
61       
62       String JavaDoc wasStr = DOMWriter.printNode(env, false);
63       assertEquals(expStr, wasStr);
64    }
65    
66   /**
67    * Test pretty printing
68    */

69    public void testPrettyPrint() throws Exception JavaDoc
70    {
71       String JavaDoc 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 JavaDoc 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 JavaDoc env = DOMUtils.parse(envStr);
92      
93       String JavaDoc wasStr = DOMWriter.printNode(env, true);
94       assertEquals(expStr, wasStr);
95    }
96   
97    /**
98     * Test pretty comment printing
99     */

100    public void testPrettyComment() throws Exception JavaDoc
101    {
102       String JavaDoc 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 JavaDoc 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 JavaDoc env = DOMUtils.parse(envStr);
125      
126       String JavaDoc wasStr = DOMWriter.printNode(env, true);
127       assertEquals(expStr, wasStr);
128    }
129 }
130
Popular Tags