1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.pdf.impl; |
21 |
|
|
22 |
|
import java.io.InputStream; |
23 |
|
import java.io.StringReader; |
24 |
|
|
25 |
|
import javax.xml.transform.sax.SAXSource; |
26 |
|
|
27 |
|
import org.apache.commons.io.IOUtils; |
28 |
|
import org.custommonkey.xmlunit.Diff; |
29 |
|
import org.custommonkey.xmlunit.XMLUnit; |
30 |
|
import org.junit.Rule; |
31 |
|
import org.junit.Test; |
32 |
|
import org.xml.sax.InputSource; |
33 |
|
import org.xml.sax.XMLReader; |
34 |
|
import org.xwiki.rendering.internal.parser.xhtml.wikimodel.XWikiXMLReaderFactory; |
35 |
|
import org.xwiki.test.annotation.ComponentList; |
36 |
|
import org.xwiki.xml.EntityResolver; |
37 |
|
import org.xwiki.xml.XMLReaderFactory; |
38 |
|
import org.xwiki.xml.XMLUtils; |
39 |
|
import org.xwiki.xml.internal.DefaultXMLReaderFactory; |
40 |
|
import org.xwiki.xml.internal.LocalEntityResolver; |
41 |
|
|
42 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
43 |
|
|
44 |
|
import static org.junit.Assert.*; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@version |
50 |
|
|
51 |
|
@ComponentList({ |
52 |
|
DefaultXMLReaderFactory.class, |
53 |
|
XWikiXMLReaderFactory.class, |
54 |
|
LocalEntityResolver.class |
55 |
|
}) |
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
|
56 |
|
public class XHTML2FOTest |
57 |
|
{ |
58 |
|
@Rule |
59 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
64 |
1 |
@Test... |
65 |
|
public void transformWithFontStyle() throws Exception |
66 |
|
{ |
67 |
|
|
68 |
1 |
InputStream xslt = getClass().getClassLoader().getResourceAsStream("xhtml2fo.xsl"); |
69 |
1 |
assertNotNull(xslt); |
70 |
|
|
71 |
1 |
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
72 |
|
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " |
73 |
|
+ "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" |
74 |
|
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" |
75 |
|
+ "<head>\n" |
76 |
|
+ " <title>\n" |
77 |
|
+ " Main.test2 - test2\n" |
78 |
|
+ " </title>\n" |
79 |
|
+ " <meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\" />\n" |
80 |
|
+ " <meta content=\"en\" name=\"language\" />\n" |
81 |
|
+ "</head>\n" |
82 |
|
+ "<body class=\"exportbody\" id=\"body\" pdfcover=\"0\" pdftoc=\"0\" " |
83 |
|
+ "style=\"display: block; margin: 8pt; \">\n" |
84 |
|
+ " <div class=\"pdfheader\" style=\"display: block; \">\n" |
85 |
|
+ " Main.test2 - test2\n" |
86 |
|
+ " \n" |
87 |
|
+ " </div>\n" |
88 |
|
+ " <div class=\"pdffooter\" style=\"display: block; \">\n" |
89 |
|
+ " Page <span class=\"page-number\">\n" |
90 |
|
+ " </span> of <span class=\"page-total\">\n" |
91 |
|
+ " </span> - last modified by Administrator on 2016/01/25 14:07\n" |
92 |
|
+ " \n" |
93 |
|
+ "</div>\n" |
94 |
|
+ "<div id=\"xwikimaincontainer\" style=\"display: block; \">\n" |
95 |
|
+ " <div id=\"xwikimaincontainerinner\" style=\"display: block; \">\n" |
96 |
|
+ " <div id=\"xwikicontent\" style=\"display: block; \">\n" |
97 |
|
+ " <p style=\"display: block; margin: 1em 0; color: red; \">\n" |
98 |
|
+ " <span style=\"font: 7px 14px Courier; \">Test</span>\n" |
99 |
|
+ " </p>\n" |
100 |
|
+ " </div>\n" |
101 |
|
+ " </div>\n" |
102 |
|
+ "</div>\n" |
103 |
|
+ "</body>\n" |
104 |
|
+ "</html>\n"; |
105 |
|
|
106 |
1 |
XMLReaderFactory xmlReaderFactory = this.oldcore.getMocker().getInstance(XMLReaderFactory.class); |
107 |
1 |
XMLReader xmlReader = xmlReaderFactory.createXMLReader(); |
108 |
1 |
EntityResolver entityResolver = this.oldcore.getMocker().getInstance(EntityResolver.class); |
109 |
1 |
xmlReader.setEntityResolver(entityResolver); |
110 |
1 |
SAXSource xmlSource = new SAXSource(xmlReader, new InputSource(new StringReader(xml))); |
111 |
1 |
SAXSource xsltSource = new SAXSource(xmlReader, new InputSource(xslt)); |
112 |
|
|
113 |
1 |
String transformedXML = XMLUtils.transform(xmlSource, xsltSource); |
114 |
1 |
String expectedXML = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("xhtml2fo.expected")); |
115 |
|
|
116 |
1 |
XMLUnit.setIgnoreWhitespace(true); |
117 |
1 |
Diff diff = new Diff(expectedXML, transformedXML); |
118 |
1 |
assertTrue("XML is not similar [" + diff.toString() + "]", diff.identical()); |
119 |
|
} |
120 |
|
} |