1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.xml; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Test; |
24 |
|
|
25 |
|
|
26 |
|
@link |
27 |
|
|
28 |
|
@version |
29 |
|
@since |
30 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (69) |
Complexity: 21 |
Complexity Density: 0.44 |
|
31 |
|
public class XMLUtilsTest |
32 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
33 |
1 |
@Test... |
34 |
|
public void testEscapeXMLComment() |
35 |
|
{ |
36 |
1 |
Assert.assertEquals("-\\- ", XMLUtils.escapeXMLComment("-- ")); |
37 |
1 |
Assert.assertEquals("-\\", XMLUtils.escapeXMLComment("-")); |
38 |
1 |
Assert.assertEquals("-\\-\\-\\", XMLUtils.escapeXMLComment("---")); |
39 |
1 |
Assert.assertEquals("- ", XMLUtils.escapeXMLComment("- ")); |
40 |
|
} |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
42 |
1 |
@Test... |
43 |
|
public void testUnescapeXMLComment() |
44 |
|
{ |
45 |
1 |
Assert.assertEquals("", XMLUtils.unescapeXMLComment("\\")); |
46 |
1 |
Assert.assertEquals("\\", XMLUtils.unescapeXMLComment("\\\\")); |
47 |
1 |
Assert.assertEquals("--", XMLUtils.unescapeXMLComment("\\-\\-")); |
48 |
1 |
Assert.assertEquals("--", XMLUtils.unescapeXMLComment("\\-\\-\\")); |
49 |
|
} |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
51 |
1 |
@Test... |
52 |
|
public void testEscape() |
53 |
|
{ |
54 |
1 |
String escapedText = XMLUtils.escape("a < a' && a' < a\" => a < a\""); |
55 |
|
|
56 |
1 |
Assert.assertFalse("Failed to escape <", escapedText.contains("<")); |
57 |
1 |
Assert.assertFalse("Failed to escape >", escapedText.contains(">")); |
58 |
1 |
Assert.assertFalse("Failed to escape '", escapedText.contains("'")); |
59 |
1 |
Assert.assertFalse("Failed to escape \"", escapedText.contains("\"")); |
60 |
1 |
Assert.assertFalse("Failed to escape &", escapedText.contains("&&")); |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
63 |
1 |
@Test... |
64 |
|
public void testEscapeApos() |
65 |
|
{ |
66 |
1 |
Assert.assertFalse("' wrongly escaped to non-HTML '", XMLUtils.escape("'").equals("'")); |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
69 |
1 |
@Test... |
70 |
|
public void testEscapeEmptyString() |
71 |
|
{ |
72 |
1 |
Assert.assertEquals("\"\" should be \"\"", "", XMLUtils.escape("")); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
75 |
1 |
@Test... |
76 |
|
public void testEscapeWithNull() |
77 |
|
{ |
78 |
1 |
Assert.assertNull("null should be null", XMLUtils.escape(null)); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
81 |
1 |
@Test... |
82 |
|
public void testEscapeNonAscii() |
83 |
|
{ |
84 |
1 |
Assert.assertTrue("Non-ASCII characters were escaped", XMLUtils.escape("\u0123").equals("\u0123")); |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
87 |
1 |
@Test... |
88 |
|
public void testEscapeAttributeValue() |
89 |
|
{ |
90 |
|
|
91 |
1 |
String escapedText = XMLUtils.escapeAttributeValue("a < a' && a' < a\" => a < a\""); |
92 |
|
|
93 |
1 |
Assert.assertFalse("Failed to escape <", escapedText.contains("<")); |
94 |
1 |
Assert.assertFalse("Failed to escape >", escapedText.contains(">")); |
95 |
1 |
Assert.assertFalse("Failed to escape '", escapedText.contains("'")); |
96 |
1 |
Assert.assertFalse("Failed to escape \"", escapedText.contains("\"")); |
97 |
1 |
Assert.assertFalse("Failed to escape &", escapedText.contains("&&")); |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
100 |
1 |
@Test... |
101 |
|
public void testEscapeAttributeValueApos() |
102 |
|
{ |
103 |
1 |
Assert.assertFalse("' wrongly escaped to non-HTML '", XMLUtils.escapeAttributeValue("'") |
104 |
|
.equals("'")); |
105 |
|
} |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
107 |
1 |
@Test... |
108 |
|
public void testEscapeFAttributeValueEmptyString() |
109 |
|
{ |
110 |
1 |
Assert.assertEquals("\"\" should be \"\"", "", XMLUtils.escapeAttributeValue("")); |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
113 |
1 |
@Test... |
114 |
|
public void testEscapeFAttributeValueWithNull() |
115 |
|
{ |
116 |
1 |
Assert.assertNull("null should be null", XMLUtils.escapeAttributeValue(null)); |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
public void testEscapeAttributeValueNonAscii() |
121 |
|
{ |
122 |
1 |
Assert.assertTrue("Non-ASCII characters were escaped", XMLUtils.escapeAttributeValue("\u0123") |
123 |
|
.equals("\u0123")); |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
126 |
1 |
@Test... |
127 |
|
public void testEscapeElementContent() |
128 |
|
{ |
129 |
|
|
130 |
1 |
String escapedText = XMLUtils.escapeElementContent("a < a' && a' < a\" => a < a\""); |
131 |
|
|
132 |
1 |
Assert.assertFalse("Failed to escape <", escapedText.contains("<")); |
133 |
1 |
Assert.assertFalse("Failed to escape >", escapedText.contains(">")); |
134 |
1 |
Assert.assertTrue("Wrongfully escaped '", escapedText.contains("'")); |
135 |
1 |
Assert.assertTrue("Wrongfully escaped \"", escapedText.contains("\"")); |
136 |
1 |
Assert.assertFalse("Failed to escape &", escapedText.contains("&&")); |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
139 |
1 |
@Test... |
140 |
|
public void testEscapeElementContentEmptyString() |
141 |
|
{ |
142 |
1 |
Assert.assertEquals("\"\" should be \"\"", "", XMLUtils.escapeElementContent("")); |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
145 |
1 |
@Test... |
146 |
|
public void testEscapeElementContentWithNull() |
147 |
|
{ |
148 |
1 |
Assert.assertNull("null should be null", XMLUtils.escapeElementContent(null)); |
149 |
|
} |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
151 |
1 |
@Test... |
152 |
|
public void testEscapeElementContentNonAscii() |
153 |
|
{ |
154 |
1 |
Assert.assertTrue("Non-ASCII characters were escaped", XMLUtils.escapeElementContent("\u0123") |
155 |
|
.equals("\u0123")); |
156 |
|
} |
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
158 |
1 |
@Test... |
159 |
|
public void testUnescape() |
160 |
|
{ |
161 |
1 |
Assert.assertEquals("Failed to unescaped named entities", "&'\"<>", |
162 |
|
XMLUtils.unescape("&'"<>")); |
163 |
1 |
Assert.assertEquals("Failed to unescaped decimal entities", "&'\"<>", |
164 |
|
XMLUtils.unescape("&'"<>")); |
165 |
1 |
Assert.assertEquals("Failed to unescaped decimal entities with leading zeros", "&'\"<>", |
166 |
|
XMLUtils.unescape("&'"<>")); |
167 |
1 |
Assert.assertEquals("Failed to unescaped hexadecimal entities", "&'\"<<>>", |
168 |
|
XMLUtils.unescape("&'"<<>>")); |
169 |
1 |
Assert.assertEquals("Failed to unescaped hexadecimal entities with leading zeros", "&'\"<<>>", |
170 |
|
XMLUtils.unescape("&'"<<>>")); |
171 |
|
} |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
173 |
1 |
@Test... |
174 |
|
public void testUnescapeEmptyString() |
175 |
|
{ |
176 |
1 |
Assert.assertEquals("\"\" should be \"\"", "", XMLUtils.unescape("")); |
177 |
|
} |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
179 |
1 |
@Test... |
180 |
|
public void testUnescapeWithNull() |
181 |
|
{ |
182 |
1 |
Assert.assertNull("null should be null", XMLUtils.unescape(null)); |
183 |
|
} |
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
185 |
1 |
@Test... |
186 |
|
public void testUnescapeOtherEscapes() |
187 |
|
{ |
188 |
1 |
Assert.assertEquals("Extra named entities were unescaped", "°", XMLUtils.unescape("°")); |
189 |
1 |
Assert.assertEquals("Extra decimal entities were unescaped", "A", XMLUtils.unescape("A")); |
190 |
1 |
Assert.assertEquals("Extra hexadecimal entities were unescaped", "", XMLUtils.unescape("")); |
191 |
|
} |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
193 |
1 |
@Test... |
194 |
|
public void testGetDomDocument() |
195 |
|
{ |
196 |
|
|
197 |
1 |
Assert.assertNotNull(XMLUtils.createDOMDocument()); |
198 |
|
} |
199 |
|
} |