|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| package nu.xom.tests; |
|
22 |
| |
|
23 |
| import junit.framework.ComparisonFailure; |
|
24 |
| import nu.xom.Attribute; |
|
25 |
| import nu.xom.Comment; |
|
26 |
| import nu.xom.Element; |
|
27 |
| import nu.xom.Namespace; |
|
28 |
| import nu.xom.Node; |
|
29 |
| import nu.xom.Text; |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| public class XOMTestCaseTest extends XOMTestCase { |
|
42 |
| |
|
43 |
| |
|
44 |
12
| public XOMTestCaseTest(String name) {
|
|
45 |
12
| super(name);
|
|
46 |
| } |
|
47 |
| |
|
48 |
| |
|
49 |
1
| public void testNullCheck() {
|
|
50 |
| |
|
51 |
1
| Text t = new Text("");
|
|
52 |
1
| try {
|
|
53 |
1
| assertEquals(t, null);
|
|
54 |
0
| fail("Allowed comparison with null");
|
|
55 |
| } |
|
56 |
| catch (ComparisonFailure ex) { |
|
57 |
1
| assertNotNull(ex.getMessage());
|
|
58 |
| } |
|
59 |
| |
|
60 |
1
| try {
|
|
61 |
1
| assertEquals(null, t);
|
|
62 |
0
| fail("Allowed comparison with null");
|
|
63 |
| } |
|
64 |
| catch (ComparisonFailure ex) { |
|
65 |
1
| assertNotNull(ex.getMessage());
|
|
66 |
| } |
|
67 |
| |
|
68 |
| } |
|
69 |
| |
|
70 |
| |
|
71 |
1
| public void testNamespaceEqualsItself() {
|
|
72 |
1
| Namespace ns = new Namespace("pre", "http://www.example.org", null);
|
|
73 |
1
| assertEquals(ns, ns);
|
|
74 |
| } |
|
75 |
| |
|
76 |
| |
|
77 |
1
| public void testCompareMismatchedTypes() {
|
|
78 |
| |
|
79 |
1
| Node n1 = new Text("");
|
|
80 |
1
| Node n2 = new Attribute("name", "value");
|
|
81 |
| |
|
82 |
1
| try {
|
|
83 |
1
| assertEquals(n1, n2);
|
|
84 |
0
| fail("Text equals Attribute?!");
|
|
85 |
| } |
|
86 |
| catch (ComparisonFailure ex) { |
|
87 |
1
| assertNotNull(ex.getMessage());
|
|
88 |
| } |
|
89 |
| |
|
90 |
1
| try {
|
|
91 |
1
| assertEquals(n2, n1);
|
|
92 |
0
| fail("Text equals Attribute?!");
|
|
93 |
| } |
|
94 |
| catch (ComparisonFailure ex) { |
|
95 |
1
| assertNotNull(ex.getMessage());
|
|
96 |
| } |
|
97 |
| |
|
98 |
| } |
|
99 |
| |
|
100 |
| |
|
101 |
1
| public void testCompareMismatchedNullNodeTypes() {
|
|
102 |
| |
|
103 |
1
| Node n1 = new Text("");
|
|
104 |
1
| Node n2 = null;
|
|
105 |
| |
|
106 |
1
| try {
|
|
107 |
1
| assertEquals(n1, n2);
|
|
108 |
0
| fail("Text equals null?!");
|
|
109 |
| } |
|
110 |
| catch (ComparisonFailure ex) { |
|
111 |
1
| assertNotNull(ex.getMessage());
|
|
112 |
| } |
|
113 |
| |
|
114 |
| } |
|
115 |
| |
|
116 |
| |
|
117 |
1
| public void testCompareAttributesAsNodes() {
|
|
118 |
| |
|
119 |
1
| Node a1 = new Attribute("test", "value");
|
|
120 |
1
| Node a2 = a1.copy();
|
|
121 |
1
| assertEquals(a1, a2);
|
|
122 |
| |
|
123 |
| } |
|
124 |
| |
|
125 |
| |
|
126 |
1
| public void testCombineTextNodes() {
|
|
127 |
| |
|
128 |
1
| Element e1 = new Element("test");
|
|
129 |
1
| e1.appendChild("1");
|
|
130 |
1
| e1.appendChild("2");
|
|
131 |
1
| Element e2 = new Element("test");
|
|
132 |
1
| e2.appendChild("12");
|
|
133 |
1
| assertEquals(e1, e2);
|
|
134 |
1
| assertEquals(2, e1.getChildCount());
|
|
135 |
| |
|
136 |
| } |
|
137 |
| |
|
138 |
| |
|
139 |
1
| public void testTrickyCombineTextNodes() {
|
|
140 |
| |
|
141 |
1
| Element e1 = new Element("test");
|
|
142 |
1
| e1.appendChild("12");
|
|
143 |
1
| e1.appendChild("3");
|
|
144 |
1
| Element e2 = new Element("test");
|
|
145 |
1
| e2.appendChild("1");
|
|
146 |
1
| e2.appendChild("23");
|
|
147 |
1
| assertEquals(e1, e2);
|
|
148 |
1
| assertEquals(2, e1.getChildCount());
|
|
149 |
| |
|
150 |
| } |
|
151 |
| |
|
152 |
| |
|
153 |
1
| public void testCombineThreeTextNodes() {
|
|
154 |
| |
|
155 |
1
| Element e1 = new Element("test");
|
|
156 |
1
| e1.appendChild("1");
|
|
157 |
1
| e1.appendChild("2");
|
|
158 |
1
| e1.appendChild("3");
|
|
159 |
1
| Element e2 = new Element("test");
|
|
160 |
1
| e2.appendChild("123");
|
|
161 |
1
| assertEquals(e1, e2);
|
|
162 |
| |
|
163 |
| } |
|
164 |
| |
|
165 |
| |
|
166 |
1
| public void testCombineThreeTextNodes2() {
|
|
167 |
| |
|
168 |
1
| Element e1 = new Element("test");
|
|
169 |
1
| e1.appendChild("\n");
|
|
170 |
1
| e1.appendChild(new Element("p"));
|
|
171 |
1
| e1.appendChild("1");
|
|
172 |
1
| e1.appendChild("2");
|
|
173 |
1
| e1.appendChild("3");
|
|
174 |
1
| Element e2 = new Element("test");
|
|
175 |
1
| e2.appendChild("\n");
|
|
176 |
1
| e2.appendChild(new Element("p"));
|
|
177 |
1
| e2.appendChild("123");
|
|
178 |
1
| assertEquals(e2, e1);
|
|
179 |
| |
|
180 |
| } |
|
181 |
| |
|
182 |
| |
|
183 |
1
| public void testUnequalElements() {
|
|
184 |
| |
|
185 |
1
| Element e1 = new Element("test");
|
|
186 |
1
| e1.appendChild("1");
|
|
187 |
1
| e1.appendChild(new Element("b"));
|
|
188 |
1
| e1.appendChild("3");
|
|
189 |
1
| Element e2 = new Element("test");
|
|
190 |
1
| e2.appendChild("1");
|
|
191 |
1
| e2.appendChild(new Element("c"));
|
|
192 |
1
| e2.appendChild("3");
|
|
193 |
1
| try {
|
|
194 |
1
| assertEquals(e1, e2);
|
|
195 |
0
| fail("Unequal elements compared equal");
|
|
196 |
| } |
|
197 |
| catch (ComparisonFailure success) { |
|
198 |
1
| assertNotNull(success.getMessage());
|
|
199 |
| } |
|
200 |
| |
|
201 |
| } |
|
202 |
| |
|
203 |
| |
|
204 |
1
| public void testCompareXMLBaseAttributes() {
|
|
205 |
| |
|
206 |
1
| Node a1 = new Attribute("xml:base", Namespace.XML_NAMESPACE, "value.xml");
|
|
207 |
1
| Node a2 = new Attribute("xml:base", Namespace.XML_NAMESPACE, "./value.xml");
|
|
208 |
1
| assertEquals(a1, a2);
|
|
209 |
| |
|
210 |
| } |
|
211 |
| |
|
212 |
| |
|
213 |
1
| public void testCompareChildren() {
|
|
214 |
| |
|
215 |
1
| Element e1 = new Element("e");
|
|
216 |
1
| Element e2 = new Element("e");
|
|
217 |
1
| e1.appendChild(new Comment("a"));
|
|
218 |
1
| e2.appendChild(new Comment("b"));
|
|
219 |
1
| try {
|
|
220 |
1
| assertEquals("BOO!", e1, e2);
|
|
221 |
0
| fail("didn't check children");
|
|
222 |
| } |
|
223 |
| catch (ComparisonFailure ex) { |
|
224 |
1
| assertTrue(ex.getMessage().indexOf("BOO!") >= 0 );
|
|
225 |
| } |
|
226 |
| |
|
227 |
| } |
|
228 |
| |
|
229 |
| |
|
230 |
| } |