1 /* 2 * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. 3 * 4 * This software is open source. 5 * See the bottom of this file for the licence. 6 * 7 * $Id: TestGetQNames.java,v 1.7 2004/06/25 08:03:47 maartenc Exp $ 8 */ 9 10 package org.dom4j; 11 12 import java.net.URL; 13 import java.util.List; 14 15 import junit.framework.Test; 16 import junit.framework.TestSuite; 17 import junit.textui.TestRunner; 18 19 import org.dom4j.io.SAXReader; 20 21 /*** A test harness to test the DocumentFactory.getQNames() method 22 * 23 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 24 * @version $Revision: 1.7 $ 25 */ 26 public class TestGetQNames extends AbstractTestCase { 27 28 DocumentFactory factory = new DocumentFactory(); 29 30 public static void main( String[] args ) { 31 TestRunner.run( suite() ); 32 } 33 34 public static Test suite() { 35 return new TestSuite( TestGetQNames.class ); 36 } 37 38 public TestGetQNames(String name) { 39 super(name); 40 } 41 42 // Test case(s) 43 //------------------------------------------------------------------------- 44 public void testQNames() throws Exception { 45 List qnames = factory.getQNames(); 46 47 assertTrue( "Found 15 QNames", qnames.size() == 15 ); 48 } 49 50 /*** Test the element rename functionality which was lacking as spotted by 51 * Rob Lebowitz 52 */ 53 public void testRename() throws Exception { 54 Document doc = DocumentHelper.createDocument(); 55 Element root = doc.addElement( "foo" ); 56 57 assertEquals( "named correctly", "foo", root.getName() ); 58 59 root.setName( "bar" ); 60 61 assertEquals( "named correctly", "bar", root.getName() ); 62 63 QName xyz = root.getQName( "xyz" ); 64 65 root.setQName( xyz ); 66 67 assertEquals( "QNamed correctly", xyz, root.getQName() ); 68 } 69 70 // Implementation methods 71 //------------------------------------------------------------------------- 72 protected void setUp() throws Exception { 73 SAXReader reader = new SAXReader(); 74 reader.setDocumentFactory( factory ); 75 URL url = getClass().getResource("/xml/test/soap2.xml"); 76 document = reader.read(url); 77 } 78 } 79 80 81 82 83 /* 84 * Redistribution and use of this software and associated documentation 85 * ("Software"), with or without modification, are permitted provided 86 * that the following conditions are met: 87 * 88 * 1. Redistributions of source code must retain copyright 89 * statements and notices. Redistributions must also contain a 90 * copy of this document. 91 * 92 * 2. Redistributions in binary form must reproduce the 93 * above copyright notice, this list of conditions and the 94 * following disclaimer in the documentation and/or other 95 * materials provided with the distribution. 96 * 97 * 3. The name "DOM4J" must not be used to endorse or promote 98 * products derived from this Software without prior written 99 * permission of MetaStuff, Ltd. For written permission, 100 * please contact dom4j-info@metastuff.com. 101 * 102 * 4. Products derived from this Software may not be called "DOM4J" 103 * nor may "DOM4J" appear in their names without prior written 104 * permission of MetaStuff, Ltd. DOM4J is a registered 105 * trademark of MetaStuff, Ltd. 106 * 107 * 5. Due credit should be given to the DOM4J Project - 108 * http://www.dom4j.org 109 * 110 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 111 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 112 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 113 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 114 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 115 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 116 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 117 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 118 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 119 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 120 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 121 * OF THE POSSIBILITY OF SUCH DAMAGE. 122 * 123 * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved. 124 * 125 * $Id: TestGetQNames.java,v 1.7 2004/06/25 08:03:47 maartenc Exp $ 126 */