1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.store.serialization.xml.internal; |
21 |
|
|
22 |
|
import java.io.ByteArrayInputStream; |
23 |
|
import java.io.ByteArrayOutputStream; |
24 |
|
import java.io.IOException; |
25 |
|
|
26 |
|
import org.apache.commons.io.IOUtils; |
27 |
|
import org.dom4j.Element; |
28 |
|
import org.junit.Assert; |
29 |
|
import org.junit.Test; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@param |
35 |
|
@version |
36 |
|
@since |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.33 |
|
38 |
|
public class AbstractXMLSerializerTest extends AbstractXMLSerializer<Element, Element> |
39 |
|
{ |
40 |
|
private static final String TEST_CONTENT = |
41 |
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
42 |
|
+ "\n" |
43 |
|
+ "<root>\n" |
44 |
|
+ " <doc>\n" |
45 |
|
+ " <name>docName</name>\n" |
46 |
|
+ " <obj>\n" |
47 |
|
+ " <name>objName</name>\n" |
48 |
|
+ " <content>objContent</content>\n" |
49 |
|
+ " </obj>\n" |
50 |
|
+ " <content>docContent</content>\n" |
51 |
|
+ " </doc>\n" |
52 |
|
+ "</root>"; |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
1 |
public Element parse(final Element xmlElement)... |
55 |
|
{ |
56 |
1 |
return xmlElement; |
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
1 |
public void serialize(final Element object, final XMLWriter writeTo) throws IOException... |
60 |
|
{ |
61 |
1 |
writeTo.write(object); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
64 |
1 |
@Test... |
65 |
|
public void testParseSerialize() throws Exception |
66 |
|
{ |
67 |
1 |
final ByteArrayInputStream bais = new ByteArrayInputStream(TEST_CONTENT.getBytes("US-ASCII")); |
68 |
1 |
final Element element = this.parse(bais); |
69 |
1 |
bais.close(); |
70 |
|
|
71 |
1 |
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
72 |
1 |
IOUtils.copy(this.serialize(element), baos); |
73 |
1 |
final String test = new String(baos.toByteArray(), "US-ASCII"); |
74 |
1 |
Assert.assertEquals("Parsing and serializing yields a different output.", TEST_CONTENT, test); |
75 |
|
} |
76 |
|
} |