2
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
4
* This software is open source.
5
* See the bottom of this file for the licence.
10
import junit.textui.TestRunner;
12
import org.dom4j.AbstractTestCase;
15
* Tests the {@link ExternalEntityDecl}functionality. Tests each of the
16
* property access methods and the serialization mechanisms. Correct parsing is
17
* tested by {@link DocTypeTest}.
22
* @author Bryan Thompson
23
* @author Maarten Coene
24
* @version $Revision: 1.3 $
26
* @todo The dom4j documentation needs to describe what representation SHOULD be
27
* generated by {@link ExternalEntityDecl#toString()}.
28
* @todo Test support for NOTATION and NDATA when used as part of an external
29
* entity declaration. dom4j does not appear to support NOTATION and NDATA
32
public class ExternalEntityDeclTest extends AbstractTestCase {
33
public static void main(String[] args) {
34
TestRunner.run(ExternalEntityDeclTest.class);
38
// -------------------------------------------------------------------------
39
public void testToString() {
40
ExternalEntityDecl decl1 = new ExternalEntityDecl("name", null,
42
ExternalEntityDecl decl2 = new ExternalEntityDecl("%name", null,
45
assertEquals("<!ENTITY name SYSTEM \"systemID\" >", decl1.toString());
46
assertEquals("<!ENTITY % name SYSTEM \"systemID\" >", decl2.toString());
50
* Tests external entity declaration using only the SYSTEM identifier.
52
public void testSystemId() {
53
String expectedName = "anEntity";
55
String expectedPublicID = null;
57
String expectedSystemID = "http://www.myorg.org/foo";
59
String expectedText = "<!ENTITY anEntity "
60
+ "SYSTEM \"http://www.myorg.org/foo\" >";
62
ExternalEntityDecl actual = new ExternalEntityDecl(expectedName,
63
expectedPublicID, expectedSystemID);
65
assertEquals("name is correct", expectedName, actual.getName());
67
assertEquals("publicID is correct", expectedPublicID, actual
70
assertEquals("systemID is correct", expectedSystemID, actual
73
assertEquals("toString() is correct", expectedText, actual.toString());
77
* Tests external entity declaration using both SYSTEM and PUBLIC
80
public void testPublicIdSystemId() {
81
String expectedName = "anEntity";
83
String expectedPublicID = "-//dom4j//DTD sample";
85
String expectedSystemID = "http://www.myorg.org/foo";
87
String expectedText = "<!ENTITY anEntity "
88
+ "PUBLIC \"-//dom4j//DTD sample\" "
89
+ "\"http://www.myorg.org/foo\" >";
91
ExternalEntityDecl actual = new ExternalEntityDecl(expectedName,
92
expectedPublicID, expectedSystemID);
94
assertEquals("name is correct", expectedName, actual.getName());
96
assertEquals("publicID is correct", expectedPublicID, actual
99
assertEquals("systemID is correct", expectedSystemID, actual
102
assertEquals("toString() is correct", expectedText, actual.toString());
107
* Redistribution and use of this software and associated documentation
108
* ("Software"), with or without modification, are permitted provided that the
109
* following conditions are met:
111
* 1. Redistributions of source code must retain copyright statements and
112
* notices. Redistributions must also contain a copy of this document.
114
* 2. Redistributions in binary form must reproduce the above copyright notice,
115
* this list of conditions and the following disclaimer in the documentation
116
* and/or other materials provided with the distribution.
118
* 3. The name "DOM4J" must not be used to endorse or promote products derived
119
* from this Software without prior written permission of MetaStuff, Ltd. For
120
* written permission, please contact dom4j-info@metastuff.com.
122
* 4. Products derived from this Software may not be called "DOM4J" nor may
123
* "DOM4J" appear in their names without prior written permission of MetaStuff,
124
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
126
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
128
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
129
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
130
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
131
* ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
132
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
133
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
134
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
135
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
136
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
137
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
138
* POSSIBILITY OF SUCH DAMAGE.
140
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.