1 /*
2 * Copyright 2001-2005 (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
8 package org.dom4j;
9
10 import junit.textui.TestRunner;
11
12 import java.util.List;
13
14 import org.dom4j.dtd.ElementDecl;
15 import org.dom4j.io.SAXReader;
16
17 /***
18 * Tests the DocType functionality
19 *
20 * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
21 * @version $Revision: 1.4 $
22 */
23 public class DocTypeTest extends AbstractTestCase {
24 /*** Input XML file to read */
25 protected static final String INPUT_XML_FILE = "/xml/dtd/internal.xml";
26
27 public static void main(String[] args) {
28 TestRunner.run(DocTypeTest.class);
29 }
30
31 // Test case(s)
32 // -------------------------------------------------------------------------
33 public void testDocType() throws Exception {
34 SAXReader reader = new SAXReader();
35 reader.setIncludeInternalDTDDeclarations(true);
36
37 Document document = getDocument(INPUT_XML_FILE, reader);
38
39 DocumentType docType = document.getDocType();
40 assertTrue("Has DOCTYPE", docType != null);
41
42 List declarations = docType.getInternalDeclarations();
43 assertTrue("DOCTYPE has declarations", (declarations != null)
44 && !declarations.isEmpty());
45
46 ElementDecl decl = (ElementDecl) declarations.get(0);
47
48 assertEquals("name is correct", "greeting", decl.getName());
49 assertEquals("model is correct", "(#PCDATA)", decl.getModel());
50
51 String expected = "<!ELEMENT " + decl.getName() + " " + decl.getModel()
52 + ">";
53 assertEquals("toString() is correct", expected, decl.toString());
54 }
55 }
56
57 /*
58 * Redistribution and use of this software and associated documentation
59 * ("Software"), with or without modification, are permitted provided that the
60 * following conditions are met:
61 *
62 * 1. Redistributions of source code must retain copyright statements and
63 * notices. Redistributions must also contain a copy of this document.
64 *
65 * 2. Redistributions in binary form must reproduce the above copyright notice,
66 * this list of conditions and the following disclaimer in the documentation
67 * and/or other materials provided with the distribution.
68 *
69 * 3. The name "DOM4J" must not be used to endorse or promote products derived
70 * from this Software without prior written permission of MetaStuff, Ltd. For
71 * written permission, please contact dom4j-info@metastuff.com.
72 *
73 * 4. Products derived from this Software may not be called "DOM4J" nor may
74 * "DOM4J" appear in their names without prior written permission of MetaStuff,
75 * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
76 *
77 * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
78 *
79 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
80 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
83 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
84 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
85 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
86 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
87 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
88 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
89 * POSSIBILITY OF SUCH DAMAGE.
90 *
91 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
92 */