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 ExternalEntityDecl} 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 * ExternalEntityDecl#toString()}.
22 *
23 * @todo Test support for NOTATION and NDATA when used as part of an
24 * external entity declaration. dom4j does not appear to support
25 * NOTATION and NDATA at this time.
26 *
27 * @author Bryan Thompson
28 * @author Maarten Coene
29 * @version $Revision: 1.4 $
30 */
31
32 public class TestExternalEntityDecl extends TestCase {
33
34
35 public static void main( String[] args ) {
36 TestRunner.run( suite() );
37 }
38
39 public static Test suite() {
40 return new TestSuite( TestExternalEntityDecl.class );
41 }
42
43 public TestExternalEntityDecl(String name) {
44 super(name);
45 }
46
47
48
49 public void testToString() {
50 ExternalEntityDecl decl1 = new ExternalEntityDecl("name", null, "systemID");
51 ExternalEntityDecl decl2 = new ExternalEntityDecl("%name", null, "systemID");
52
53 assertEquals("<!ENTITY name SYSTEM \"systemID\" >", decl1.toString());
54 assertEquals("<!ENTITY % name SYSTEM \"systemID\" >", decl2.toString());
55 }
56
57 /***
58 * Tests external entity declaration using only the SYSTEM
59 * identifier.
60 */
61 public void test_systemId()
62 {
63
64 String expectedName = "anEntity";
65
66 String expectedPublicID = null;
67
68 String expectedSystemID = "http://www.myorg.org/foo";
69
70 String expectedText = "<!ENTITY anEntity SYSTEM \"http://www.myorg.org/foo\" >" ;
71
72 ExternalEntityDecl actual = new ExternalEntityDecl
73 ( expectedName,
74 expectedPublicID,
75 expectedSystemID
76 );
77
78 assertEquals
79 ( "name is correct",
80 expectedName,
81 actual.getName()
82 );
83
84 assertEquals
85 ( "publicID is correct",
86 expectedPublicID,
87 actual.getPublicID()
88 );
89
90 assertEquals
91 ( "systemID is correct",
92 expectedSystemID,
93 actual.getSystemID()
94 );
95
96 assertEquals
97 ( "toString() is correct",
98 expectedText,
99 actual.toString()
100 );
101
102 }
103
104 /***
105 * Tests external entity declaration using both SYSTEM and PUBLIC
106 * identifiers.
107 */
108
109 public void test_publicId_systemId()
110 {
111
112 String expectedName = "anEntity";
113
114 String expectedPublicID = "-//dom4j//DTD sample";
115
116 String expectedSystemID = "http://www.myorg.org/foo";
117
118 String expectedText = "<!ENTITY anEntity PUBLIC \"-//dom4j//DTD sample\" \"http://www.myorg.org/foo\" >" ;
119
120 ExternalEntityDecl actual = new ExternalEntityDecl
121 ( expectedName,
122 expectedPublicID,
123 expectedSystemID
124 );
125
126 assertEquals
127 ( "name is correct",
128 expectedName,
129 actual.getName()
130 );
131
132 assertEquals
133 ( "publicID is correct",
134 expectedPublicID,
135 actual.getPublicID()
136 );
137
138 assertEquals
139 ( "systemID is correct",
140 expectedSystemID,
141 actual.getSystemID()
142 );
143
144 assertEquals
145 ( "toString() is correct",
146 expectedText,
147 actual.toString()
148 );
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