1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.pdf.impl

File XHTML2FOTest.java

 

Code metrics

0
14
1
1
120
81
1
0.07
14
1
1

Classes

Class Line # Actions
XHTML2FOTest 56 14 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Integration tests to verify that the {@code html2fo.xsl} XSL stylesheet works.
48    *
49    * @version $Id: d89c3192075d8b920955a1f4f14fa9f587e7f4f9 $
50    */
51    @ComponentList({
52    DefaultXMLReaderFactory.class,
53    XWikiXMLReaderFactory.class,
54    LocalEntityResolver.class
55    })
 
56    public class XHTML2FOTest
57    {
58    @Rule
59    public MockitoOldcoreRule oldcore = new MockitoOldcoreRule();
60   
61    /**
62    * Verifies that we can have some style using the "font" attribute.
63    */
 
64  1 toggle @Test
65    public void transformWithFontStyle() throws Exception
66    {
67    // Get the xhtml2fo.xsl stylesheet
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    }