1
2
3
4
5
6
7
8
9
10 package org.dom4j.dtd;
11
12 import junit.framework.*;
13 import junit.textui.TestRunner;
14
15 /*** Tests the {@link InternalEntityDecl} functionality. Tests each of
16 * the property access methods and the serialization mechanisms.
17 * Correct parsing is tested by {@link TestDocType}.<p>
18 *
19 * @todo The dom4j documentation needs to describe what
20 * representation SHOULD be generated by {@link
21 * InternalEntityDecl#toString()}.
22 *
23 * @author Bryan Thompson
24 * @author Maarten Coene
25 * @version $Revision: 1.4 $
26 */
27
28 public class TestInternalEntityDecl extends TestCase {
29
30
31 public static void main( String[] args ) {
32 TestRunner.run( suite() );
33 }
34
35 public static Test suite() {
36 return new TestSuite( TestInternalEntityDecl.class );
37 }
38
39 public TestInternalEntityDecl(String name) {
40 super(name);
41 }
42
43
44
45 public void testToString() {
46 InternalEntityDecl decl1 = new InternalEntityDecl("name", "value");
47 InternalEntityDecl decl2 = new InternalEntityDecl("%name", "value");
48
49 assertEquals("<!ENTITY name \"value\">", decl1.toString());
50 assertEquals("<!ENTITY % name \"value\">", decl2.toString());
51 }
52
53 /***
54 * Tests parameter entity declaration, such as
55 *
56 * <pre>
57 * <!ENTITY % boolean "( true | false )">
58 * </pre>
59 * Note: There is a required whitespace between the "%" and the
60 * name of the entity. This whitespace is required in the
61 * declaration and is not allowed when writing a reference to the
62 * entity, e.g., "%boolean;" is a legal reference but not "%
63 * boolean;".<p>
64 *
65 * Note: The "%" is part of the parameter entity name as reported
66 * by the SAX API. See
67 *
68 * <a href="http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html#startEntity(java.lang.String)">
69 * LexicalHandler</a>, which states:
70 *
71 * <pre>
72 * General entities are reported with their regular names,
73 * parameter entities have '%' prepended to their names, and the
74 * external DTD subset has the pseudo-entity name "[dtd]".
75 * </pre>
76 */
77 public void test_parameter_entity()
78 {
79
80 String expectedName = "%boolean";
81
82 String expectedValue = "( true | false )";
83
84 String expectedText = "<!ENTITY % boolean \"( true | false )\">";
85
86 InternalEntityDecl actual = new InternalEntityDecl
87 ( expectedName,
88 expectedValue
89 );
90
91 assertEquals
92 ( "name is correct",
93 expectedName,
94 actual.getName()
95 );
96
97 assertEquals
98 ( "value is correct",
99 expectedValue,
100 actual.getValue()
101 );
102
103 assertEquals
104 ( "toString() is correct",
105 expectedText,
106 actual.toString()
107 );
108
109 }
110
111 /***
112 * Tests general entity declaration, such as:
113 *
114 * <pre>
115 * <!ENTITY foo "bar">
116 * </pre>
117 */
118
119 public void test_general_entity()
120 {
121
122 String expectedName = "foo";
123
124 String expectedValue = "bar";
125
126 String expectedText = "<!ENTITY foo \"bar\">";
127
128 InternalEntityDecl actual = new InternalEntityDecl
129 ( expectedName,
130 expectedValue
131 );
132
133 assertEquals
134 ( "name is correct",
135 expectedName,
136 actual.getName()
137 );
138
139 assertEquals
140 ( "value is correct",
141 expectedValue,
142 actual.getValue()
143 );
144
145 assertEquals
146 ( "toString() is correct",
147 expectedText,
148 actual.toString()
149 );
150
151 }
152
153
154
155
156
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204