1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.officeimporter.internal.filter

File AbstractHTMLFilterTest.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

0
15
5
1
88
49
5
0.33
3
5
1

Classes

Class Line # Actions
AbstractHTMLFilterTest 44 15 0% 5 2
0.990%
 

Contributing tests

This file is covered by 4 tests. .

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 org.xwiki.officeimporter.internal.filter;
21   
22    import java.io.ByteArrayInputStream;
23    import java.util.Collections;
24    import java.util.Map;
25   
26    import org.apache.commons.lang.StringUtils;
27    import org.junit.Assert;
28    import org.junit.Before;
29    import org.w3c.dom.Document;
30    import org.w3c.dom.bootstrap.DOMImplementationRegistry;
31    import org.w3c.dom.ls.DOMImplementationLS;
32    import org.w3c.dom.ls.LSInput;
33    import org.xwiki.xml.XMLUtils;
34    import org.xwiki.xml.html.filter.HTMLFilter;
35   
36    /**
37    * Base class for HTML filter tests.
38    *
39    * @version $Id: 6d75c6db57fb808a55914dde6cae33e1a5ff55c7 $
40    * @since 7.4.6
41    * @since 8.2.2
42    * @since 8.3
43    */
 
44    public abstract class AbstractHTMLFilterTest
45    {
46    protected HTMLFilter filter;
47   
48    /**
49    * Helper object for manipulating DOM Level 3 Load and Save APIs.
50    */
51    private DOMImplementationLS lsImpl;
52   
 
53  4 toggle @Before
54    public void configure() throws Exception
55    {
56  4 this.lsImpl = (DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS 3.0");
57    }
58   
 
59  0 toggle protected Document filter(String content)
60    {
61  0 return filter(content, Collections.<String, String>emptyMap());
62    }
63   
 
64  5 toggle protected Document filter(String content, Map<String, String> cleaningParameters)
65    {
66  5 LSInput input = this.lsImpl.createLSInput();
67  5 String actualContent = "<root>" + content + "</root>";
68  5 input.setByteStream(new ByteArrayInputStream(actualContent.getBytes()));
69  5 Document document = XMLUtils.parse(input);
70  5 this.filter.filter(document, cleaningParameters);
71  5 return document;
72    }
73   
 
74  1 toggle protected Document filterAndAssertOutput(String input, String expectedOuput)
75    {
76  1 return filterAndAssertOutput(input, Collections.<String, String>emptyMap(), expectedOuput);
77    }
78   
 
79  5 toggle protected Document filterAndAssertOutput(String input, Map<String, String> cleaningParameters, String expectedOuput)
80    {
81  5 Document document = filter(input, cleaningParameters);
82  5 String output = XMLUtils.serialize(document, false);
83  5 output = StringUtils.removeStart(output, "<root>");
84  5 output = StringUtils.removeEnd(output, "</root>");
85  5 Assert.assertEquals(expectedOuput, output);
86  5 return document;
87    }
88    }