1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.wikimodel.xml; |
21 |
|
|
22 |
|
import java.io.Reader; |
23 |
|
import java.io.StringReader; |
24 |
|
import java.io.StringWriter; |
25 |
|
|
26 |
|
import javax.xml.transform.Result; |
27 |
|
import javax.xml.transform.Source; |
28 |
|
import javax.xml.transform.dom.DOMResult; |
29 |
|
import javax.xml.transform.dom.DOMSource; |
30 |
|
import javax.xml.transform.stream.StreamResult; |
31 |
|
|
32 |
|
import org.w3c.dom.Document; |
33 |
|
import org.xwiki.rendering.wikimodel.IWikiParser; |
34 |
|
import org.xwiki.rendering.wikimodel.confluence.ConfluenceExtendedWikiParser; |
35 |
|
import org.xwiki.rendering.wikimodel.xml.sax.WemReader; |
36 |
|
|
37 |
|
import junit.framework.TestCase; |
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 6 |
Complexity Density: 0.24 |
|
43 |
|
public class WemToSaxTest extends TestCase |
44 |
|
{ |
45 |
|
|
46 |
|
@param |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
1 |
public WemToSaxTest(String name)... |
49 |
|
{ |
50 |
1 |
super(name); |
51 |
|
} |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
5 |
protected IWikiParser newWikiParser()... |
54 |
|
{ |
55 |
5 |
return new ConfluenceExtendedWikiParser(); |
56 |
|
|
57 |
|
|
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
60 |
5 |
public Document parseDocument(Reader reader, IWikiParser parser)... |
61 |
|
throws Exception |
62 |
|
{ |
63 |
5 |
try { |
64 |
5 |
Document document = XmlUtil.newDocument(); |
65 |
5 |
DOMResult result = new DOMResult(document); |
66 |
5 |
WemReader xmlReader = new WemReader(parser); |
67 |
5 |
XmlUtil.write(reader, xmlReader, result); |
68 |
5 |
return document; |
69 |
|
} finally { |
70 |
5 |
reader.close(); |
71 |
|
} |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
74 |
5 |
public Document parseDocument(String str, IWikiParser parser)... |
75 |
|
throws Exception |
76 |
|
{ |
77 |
5 |
StringReader reader = new StringReader(str); |
78 |
5 |
return parseDocument(reader, parser); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
81 |
1 |
public void test() throws Exception... |
82 |
|
{ |
83 |
1 |
test("abc", "<w:p><w:format>abc</w:format></w:p>"); |
84 |
1 |
test( |
85 |
|
"h1.abc", |
86 |
|
"" |
87 |
|
+ "<w:section w:absLevel=\"2\" w:docLevel=\"1\" w:headerLevel=\"1\">" |
88 |
|
+ "<w:header w:level=\"1\">" |
89 |
|
+ "<w:format>abc</w:format>" |
90 |
|
+ "</w:header>" |
91 |
|
+ "<w:content w:absLevel=\"2\" w:docLevel=\"1\" w:headerLevel=\"1\"/>" |
92 |
|
+ "</w:section>"); |
93 |
1 |
test( |
94 |
|
"h1.abc\npara", |
95 |
|
"" |
96 |
|
+ "<w:section w:absLevel=\"2\" w:docLevel=\"1\" w:headerLevel=\"1\">" |
97 |
|
+ "<w:header w:level=\"1\">" |
98 |
|
+ "<w:format>abc</w:format>" |
99 |
|
+ "</w:header>" |
100 |
|
+ "<w:content w:absLevel=\"2\" w:docLevel=\"1\" w:headerLevel=\"1\">" |
101 |
|
+ "<w:p><w:format>para</w:format></w:p>" |
102 |
|
+ "</w:content>" |
103 |
|
+ "</w:section>"); |
104 |
1 |
test("* item one", "" |
105 |
|
+ "<w:ul>" |
106 |
|
+ "<w:li><w:format>item one</w:format></w:li>" |
107 |
|
+ "</w:ul>"); |
108 |
1 |
test("* item one\n* item two", "" |
109 |
|
+ "<w:ul>" |
110 |
|
+ "<w:li><w:format>item one</w:format></w:li>" |
111 |
|
+ "<w:li><w:format>item two</w:format></w:li>" |
112 |
|
+ "</w:ul>"); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
115 |
5 |
private void test(String wiki, String xml) throws Exception... |
116 |
|
{ |
117 |
5 |
IWikiParser parser = newWikiParser(); |
118 |
5 |
Document doc = parseDocument(wiki, parser); |
119 |
5 |
StringWriter writer = new StringWriter(); |
120 |
5 |
Source input = new DOMSource(doc.getDocumentElement()); |
121 |
5 |
Result output = new StreamResult(writer); |
122 |
5 |
XmlUtil.write(input, output, false); |
123 |
5 |
String result = writer.toString(); |
124 |
5 |
String fullXml = "" |
125 |
|
+ |
126 |
|
"<w:document xmlns:w=\"http://www.wikimodel.org/ns/wem#\" xmlns:u=\"http://www.wikimodel.org/ns/user-defined-params#\">" |
127 |
|
+ "<w:section w:absLevel=\"1\" w:docLevel=\"1\" w:headerLevel=\"0\">" |
128 |
|
+ "<w:content w:absLevel=\"1\" w:docLevel=\"1\" w:headerLevel=\"0\">" |
129 |
|
+ xml |
130 |
|
+ "</w:content>" |
131 |
|
+ "</w:section>" |
132 |
|
+ "</w:document>"; |
133 |
5 |
assertEquals(fullXml, result); |
134 |
|
} |
135 |
|
} |