1
2
3
4
5
6
7
8 package org.dom4j.dtd;
9
10 import junit.textui.TestRunner;
11
12 import org.dom4j.AbstractTestCase;
13
14 /***
15 * Tests the {@link InternalEntityDecl}functionality. Tests each of the
16 * property access methods and the serialization mechanisms. Correct parsing is
17 * tested by {@link DocTypeTest}.
18 *
19 * <p>
20 * </p>
21 *
22 * @author Bryan Thompson
23 * @author Maarten Coene
24 * @version $Revision: 1.3 $
25 *
26 * @todo The dom4j documentation needs to describe what representation SHOULD be
27 * generated by {@link InternalEntityDecl#toString()}.
28 */
29 public class InternalEntityDeclTest extends AbstractTestCase {
30 public static void main(String[] args) {
31 TestRunner.run(InternalEntityDeclTest.class);
32 }
33
34
35
36 public void testToString() {
37 InternalEntityDecl decl1 = new InternalEntityDecl("name", "value");
38 InternalEntityDecl decl2 = new InternalEntityDecl("%name", "value");
39
40 assertEquals("<!ENTITY name \"value\">", decl1.toString());
41 assertEquals("<!ENTITY % name \"value\">", decl2.toString());
42 }
43
44 /***
45 * Tests parameter entity declaration, such as
46 *
47 * <pre>
48 *
49 *
50 * <!ENTITY % boolean "( true | false )">
51 *
52 *
53 * </pre>
54 *
55 * Note: There is a required whitespace between the "%" and the name of the
56 * entity. This whitespace is required in the declaration and is not allowed
57 * when writing a reference to the entity, e.g., "%boolean;" is a legal
58 * reference but not "% boolean;".
59 *
60 * <p>
61 * Note: The "%" is part of the parameter entity name as reported by the SAX
62 * API. See <a href="http://tinyurl.com/6xe9y">LexicalHandler </a>, which
63 * states:
64 *
65 * <pre>
66 *
67 *
68 * General entities are reported with their regular names,
69 * parameter entities have '%' prepended to their names, and the
70 * external DTD subset has the pseudo-entity name "[dtd]".
71 *
72 *
73 * </pre>
74 *
75 * </p>
76 */
77 public void testParameterEntity() {
78 String expectedName = "%boolean";
79
80 String expectedValue = "( true | false )";
81
82 String expectedText = "<!ENTITY % boolean \"( true | false )\">";
83
84 InternalEntityDecl actual = new InternalEntityDecl(expectedName,
85 expectedValue);
86
87 assertEquals("name is correct", expectedName, actual.getName());
88
89 assertEquals("value is correct", expectedValue, actual.getValue());
90
91 assertEquals("toString() is correct", expectedText, actual.toString());
92 }
93
94 /***
95 * Tests general entity declaration, such as:
96 *
97 * <pre>
98 *
99 *
100 * <!ENTITY foo "bar">
101 *
102 *
103 * </pre>
104 */
105 public void testGeneralEntity() {
106 String expectedName = "foo";
107
108 String expectedValue = "bar";
109
110 String expectedText = "<!ENTITY foo \"bar\">";
111
112 InternalEntityDecl actual = new InternalEntityDecl(expectedName,
113 expectedValue);
114
115 assertEquals("name is correct", expectedName, actual.getName());
116
117 assertEquals("value is correct", expectedValue, actual.getValue());
118
119 assertEquals("toString() is correct", expectedText, actual.toString());
120 }
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158