| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
|
| 38 |
|
|
| 39 |
|
@version |
| 40 |
|
@since |
| 41 |
|
@since |
| 42 |
|
@since |
| 43 |
|
|
| |
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 5 |
Complexity Density: 0.33 |
|
| 44 |
|
public abstract class AbstractHTMLFilterTest |
| 45 |
|
{ |
| 46 |
|
protected HTMLFilter filter; |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
private DOMImplementationLS lsImpl; |
| 52 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 53 |
4 |
@Before... |
| 54 |
|
public void configure() throws Exception |
| 55 |
|
{ |
| 56 |
4 |
this.lsImpl = (DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS 3.0"); |
| 57 |
|
} |
| 58 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 59 |
0 |
protected Document filter(String content)... |
| 60 |
|
{ |
| 61 |
0 |
return filter(content, Collections.<String, String>emptyMap()); |
| 62 |
|
} |
| 63 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 64 |
5 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 74 |
1 |
protected Document filterAndAssertOutput(String input, String expectedOuput)... |
| 75 |
|
{ |
| 76 |
1 |
return filterAndAssertOutput(input, Collections.<String, String>emptyMap(), expectedOuput); |
| 77 |
|
} |
| 78 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 79 |
5 |
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 |
|
} |