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 ExternalEntityDecl}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 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
30 * at this time.
31 */
32 public class ExternalEntityDeclTest extends AbstractTestCase {
33 public static void main(String[] args) {
34 TestRunner.run(ExternalEntityDeclTest.class);
35 }
36
37
38
39 public void testToString() {
40 ExternalEntityDecl decl1 = new ExternalEntityDecl("name", null,
41 "systemID");
42 ExternalEntityDecl decl2 = new ExternalEntityDecl("%name", null,
43 "systemID");
44
45 assertEquals("<!ENTITY name SYSTEM \"systemID\" >", decl1.toString());
46 assertEquals("<!ENTITY % name SYSTEM \"systemID\" >", decl2.toString());
47 }
48
49 /***
50 * Tests external entity declaration using only the SYSTEM identifier.
51 */
52 public void testSystemId() {
53 String expectedName = "anEntity";
54
55 String expectedPublicID = null;
56
57 String expectedSystemID = "http://www.myorg.org/foo";
58
59 String expectedText = "<!ENTITY anEntity "
60 + "SYSTEM \"http://www.myorg.org/foo\" >";
61
62 ExternalEntityDecl actual = new ExternalEntityDecl(expectedName,
63 expectedPublicID, expectedSystemID);
64
65 assertEquals("name is correct", expectedName, actual.getName());
66
67 assertEquals("publicID is correct", expectedPublicID, actual
68 .getPublicID());
69
70 assertEquals("systemID is correct", expectedSystemID, actual
71 .getSystemID());
72
73 assertEquals("toString() is correct", expectedText, actual.toString());
74 }
75
76 /***
77 * Tests external entity declaration using both SYSTEM and PUBLIC
78 * identifiers.
79 */
80 public void testPublicIdSystemId() {
81 String expectedName = "anEntity";
82
83 String expectedPublicID = "-//dom4j//DTD sample";
84
85 String expectedSystemID = "http://www.myorg.org/foo";
86
87 String expectedText = "<!ENTITY anEntity "
88 + "PUBLIC \"-//dom4j//DTD sample\" "
89 + "\"http://www.myorg.org/foo\" >";
90
91 ExternalEntityDecl actual = new ExternalEntityDecl(expectedName,
92 expectedPublicID, expectedSystemID);
93
94 assertEquals("name is correct", expectedName, actual.getName());
95
96 assertEquals("publicID is correct", expectedPublicID, actual
97 .getPublicID());
98
99 assertEquals("systemID is correct", expectedSystemID, actual
100 .getSystemID());
101
102 assertEquals("toString() is correct", expectedText, actual.toString());
103 }
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141