KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > TestDocType


1 /*
2  * Copyright 2001 (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: TestDocType.java,v 1.2 2003/07/12 12:13:06 per_nyfelt Exp $
8  */

9
10 package test.dom4j;
11
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import junit.textui.TestRunner;
15 import org.dom4j.DocumentType;
16 import org.dom4j.dtd.ElementDecl;
17 import org.dom4j.io.SAXReader;
18 import org.ozoneDB.xml.dom4j.io.O3SAXReader;
19
20 import java.io.FileInputStream JavaDoc;
21 import java.util.List JavaDoc;
22
23 /** Tests the DocType functionality
24   *
25   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
26   * @version $Revision: 1.2 $
27   */

28 public class TestDocType extends AbstractTestCase {
29
30     /** Input XML file to read */
31     protected static String JavaDoc INPUT_XML_FILE = "xml/dtd/internal.xml";
32
33     public static void main( String JavaDoc[] args ) {
34         TestRunner.run( suite() );
35     }
36
37     public static Test suite() {
38         return new TestSuite( TestDocType.class );
39     }
40
41     public TestDocType(String JavaDoc name) {
42         super(name);
43     }
44
45     // Test case(s)
46
//-------------------------------------------------------------------------
47
public void testDocType() throws Exception JavaDoc {
48         DocumentType docType = document.getDocType();
49         assertTrue( "Has DOCTYPE", docType!= null );
50
51         List JavaDoc declarations = docType.getInternalDeclarations();
52         assertTrue( "DOCTYPE has declarations", declarations != null && declarations.size() == 1 );
53
54         ElementDecl decl = (ElementDecl) declarations.get(0);
55
56         assertEquals( "name is correct", "greeting", decl.getName() );
57         assertEquals( "model is correct", "(#PCDATA)", decl.getModel() );
58
59         assertEquals( "getText() is correct", "<!ELEMENT greeting (#PCDATA)>", docType.getText() );
60     }
61
62     // Implementation methods
63
//-------------------------------------------------------------------------
64
protected void setUp() throws Exception JavaDoc {
65         SAXReader reader = new O3SAXReader(db());
66         reader.setIncludeInternalDTDDeclarations(true);
67         document = reader.read( new FileInputStream JavaDoc(INPUT_XML_FILE) );
68     }
69 }
70
71
72
73
74 /*
75  * Redistribution and use of this software and associated documentation
76  * ("Software"), with or without modification, are permitted provided
77  * that the following conditions are met:
78  *
79  * 1. Redistributions of source code must retain copyright
80  * statements and notices. Redistributions must also contain a
81  * copy of this document.
82  *
83  * 2. Redistributions in binary form must reproduce the
84  * above copyright notice, this list of conditions and the
85  * following disclaimer in the documentation and/or other
86  * materials provided with the distribution.
87  *
88  * 3. The name "DOM4J" must not be used to endorse or promote
89  * products derived from this Software without prior written
90  * permission of MetaStuff, Ltd. For written permission,
91  * please contact dom4j-info@metastuff.com.
92  *
93  * 4. Products derived from this Software may not be called "DOM4J"
94  * nor may "DOM4J" appear in their names without prior written
95  * permission of MetaStuff, Ltd. DOM4J is a registered
96  * trademark of MetaStuff, Ltd.
97  *
98  * 5. Due credit should be given to the DOM4J Project
99  * (http://dom4j.org/).
100  *
101  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
102  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
103  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
104  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
105  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
106  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
107  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
108  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
109  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
110  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
111  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
112  * OF THE POSSIBILITY OF SUCH DAMAGE.
113  *
114  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
115  *
116  * $Id: TestDocType.java,v 1.2 2003/07/12 12:13:06 per_nyfelt Exp $
117  */

118
Popular Tags